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 [/ | ] to receive it" + bob ##> "/fr 1 ./tests/tmp" + bob <## "saving file 1 from alice to ./tests/tmp/test.txt" + concurrentlyN_ + [ do + bob <## "started receiving file 1 (test.txt) from alice" + bob <## "completed receiving file 1 (test.txt) from alice", + do + alice <## "started sending file 1 (test.txt) to bob" + alice <## "completed sending file 1 (test.txt) to bob" + ] + src <- B.readFile "./tests/fixtures/test.txt" + dest <- B.readFile "./tests/tmp/test.txt" + dest `shouldBe` src + testFileSndCancel :: IO () testFileSndCancel = testChat2 aliceProfile bobProfile $ diff --git a/tests/fixtures/test.txt b/tests/fixtures/test.txt new file mode 100644 index 000000000..d2aeeec3f --- /dev/null +++ b/tests/fixtures/test.txt @@ -0,0 +1 @@ +hello there \ No newline at end of file