From e9180ed0dc5478a84820ad8385f2029df1cdefc9 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 25 Sep 2021 10:09:49 +0100 Subject: [PATCH] fix small file transfer, closes #104 (#105) --- src/Simplex/Chat/Store.hs | 7 ++++++- tests/ChatTests.hs | 24 ++++++++++++++++++++++++ tests/fixtures/test.txt | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/test.txt diff --git a/src/Simplex/Chat/Store.hs b/src/Simplex/Chat/Store.hs index d63c31df0..ccac1f746 100644 --- a/src/Simplex/Chat/Store.hs +++ b/src/Simplex/Chat/Store.hs @@ -1321,7 +1321,12 @@ createRcvFileChunk st RcvFileTransfer {fileId, fileInvitation = FileInvitation { getLastChunkNo db = do ns <- DB.query db "SELECT chunk_number FROM rcv_file_chunks WHERE file_id = ? ORDER BY chunk_number DESC LIMIT 1" (Only fileId) pure $ case map fromOnly ns of - [] -> if chunkNo == 1 then RcvChunkOk else RcvChunkError + [] + | chunkNo == 1 -> + if chunkSize >= fileSize + then RcvChunkFinal + else RcvChunkOk + | otherwise -> RcvChunkError n : _ | chunkNo == n -> RcvChunkDuplicate | chunkNo == n + 1 -> diff --git a/tests/ChatTests.hs b/tests/ChatTests.hs index 195b7227b..ad1c521ad 100644 --- a/tests/ChatTests.hs +++ b/tests/ChatTests.hs @@ -42,6 +42,7 @@ chatTests = do it "update user profiles and notify contacts" testUpdateProfile describe "sending and receiving files" $ do it "send and receive file" testFileTransfer + it "send and receive a small file" testSmallFileTransfer it "sender cancelled file transfer" testFileSndCancel it "recipient cancelled file transfer" testFileRcvCancel it "send and receive file to group" testGroupFileTransfer @@ -420,6 +421,29 @@ testFileTransfer = dest <- B.readFile "./tests/tmp/test.jpg" dest `shouldBe` src +testSmallFileTransfer :: IO () +testSmallFileTransfer = + testChat2 aliceProfile bobProfile $ + \alice bob -> do + connectUsers alice bob + alice #> "/f @bob ./tests/fixtures/test.txt" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file test.txt (11 bytes / 11 bytes)" + bob <## "use /fr 1 [