From eba9c9ca010d6422c3f71f5b4f586374a83e6292 Mon Sep 17 00:00:00 2001 From: vicente Date: Thu, 26 Feb 2026 20:38:37 -0300 Subject: [PATCH 1/2] fix receiver should use reserve and carry_all_balance --- .../ccip/test/receiver/contract.tolk | 27 ++++++++++--------- contracts/tests/ccip/Receiver.spec.ts | 21 +++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/contracts/contracts/ccip/test/receiver/contract.tolk b/contracts/contracts/ccip/test/receiver/contract.tolk index ce01b29a3..cab87ed53 100644 --- a/contracts/contracts/ccip/test/receiver/contract.tolk +++ b/contracts/contracts/ccip/test/receiver/contract.tolk @@ -26,18 +26,7 @@ fun onInternalMessage(in: InMessage) { match (msg) { Receiver_CCIPReceive => { var st = lazy Storage.load(); - msg.validateAndConfirm({ - router: st.authorizedCaller, - minValue: ton("0.01"), - inMsg: { - senderAddress: in.senderAddress, - valueCoins: in.valueCoins, - }, - confirmationMsg: { - sendMode: SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE, - } - }); - + match (st.behavior) { TestReceiverBehavior.Accept => { processAccept(msg, in.senderAddress) @@ -49,6 +38,20 @@ fun onInternalMessage(in: InMessage) { processConsumeAllGas() } } + + reserveToncoinsOnBalance(0, RESERVE_MODE_INCREASE_BY_ORIGINAL_BALANCE); + msg.validateAndConfirm({ + router: st.authorizedCaller, + minValue: ton("0.01"), + inMsg: { + senderAddress: in.senderAddress, + valueCoins: in.valueCoins, + }, + confirmationMsg: { + sendMode: SEND_MODE_CARRY_ALL_BALANCE, + } + }); + } TestReceiver_UpdateAuthorizedCaller => { onUpdateAuthorizedCaller(msg, in.senderAddress) diff --git a/contracts/tests/ccip/Receiver.spec.ts b/contracts/tests/ccip/Receiver.spec.ts index 02c3b9d34..f15d9d47c 100644 --- a/contracts/tests/ccip/Receiver.spec.ts +++ b/contracts/tests/ccip/Receiver.spec.ts @@ -258,4 +258,25 @@ describe('Receiver', () => { exitCode: -14, }) }) + + it('should keep original balance after succesfully receiving', async () => { + const contract = await blockchain.getContract(receiver.address) + const initialBalance = contract.balance + + const result = await receiver.sendCCIPReceive( + deployer.getSender(), + toNano('1'), + ccipReceiveSampleMessage, + ) + expect(result.transactions).toHaveTransaction({ + from: deployer.address, + to: receiver.address, + success: true, + deploy: false, + body: tr.builder.message.in.ccipReceive.encode(ccipReceiveSampleMessage).asCell(), + }) + + const finalBalance = (await blockchain.getContract(receiver.address)).balance + expect(finalBalance).toEqual(initialBalance) + }) }) From 9d65dc0d20c5f22322247532f4f19a4f70b833ff Mon Sep 17 00:00:00 2001 From: vicentevieytes <73846744+vicentevieytes@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:32:30 -0500 Subject: [PATCH 2/2] Update contracts/tests/ccip/Receiver.spec.ts Co-authored-by: Patricio --- contracts/tests/ccip/Receiver.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contracts/tests/ccip/Receiver.spec.ts b/contracts/tests/ccip/Receiver.spec.ts index f15d9d47c..e87f8606f 100644 --- a/contracts/tests/ccip/Receiver.spec.ts +++ b/contracts/tests/ccip/Receiver.spec.ts @@ -276,7 +276,22 @@ describe('Receiver', () => { body: tr.builder.message.in.ccipReceive.encode(ccipReceiveSampleMessage).asCell(), }) + const tx = result.transactions.find( + (tx) => + tx.inMessage && + tx.inMessage.info.src && + tx.inMessage.info.src instanceof Address && + tx.inMessage.info.src.equals(deployer.address) && + tx.inMessage.info.dest && + tx.inMessage.info.dest instanceof Address && + tx.inMessage.info.dest.equals(receiver.address), + ) + if (!tx || tx.description.type != 'generic') { + throw new Error('Expected an internal message') + } + const storageFees = tx.description.storagePhase?.storageFeesCollected || toNano('0') + const finalBalance = (await blockchain.getContract(receiver.address)).balance - expect(finalBalance).toEqual(initialBalance) + expect(finalBalance).toEqual(initialBalance - storageFees) }) })