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 [