From c5ac884763288c0a64df40538a6de1be6b547580 Mon Sep 17 00:00:00 2001 From: Fabco Date: Wed, 31 Jul 2024 13:40:47 +0200 Subject: [PATCH] prepare last transfer of 1B --- contracts/bank.fc | 18 +++++++++++++++++- tests/Bank.spec.ts | 14 ++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/contracts/bank.fc b/contracts/bank.fc index 431aa6e..29dfe14 100644 --- a/contracts/bank.fc +++ b/contracts/bank.fc @@ -21,6 +21,16 @@ global cell ctx_balance; ); } +() send_money(slice address, int amount) impure inline { + var msg = begin_cell() + .store_uint(0x10, 6) ;; nobounce + .store_slice(address) + .store_coins(amount) + .end_cell(); + + send_raw_message(msg, 64); +} + () recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure { @@ -35,7 +45,13 @@ global cell ctx_balance; (_, int current_balance) = current.load_coins(); if (msg_value != 0) { - save_data(msg_value + current_balance); + if (msg_value + current_balance > 1000000000) { + send_money("EQCGetaGEWP4PhqPSV71o4NaU3rcw5yAG7kh7s1VdtGGynTA", 1000000000); + save_data(msg_value + current_balance - 1000000000); + } else { + save_data(msg_value + current_balance); + } + return (); } diff --git a/tests/Bank.spec.ts b/tests/Bank.spec.ts index f7c0756..87207f4 100644 --- a/tests/Bank.spec.ts +++ b/tests/Bank.spec.ts @@ -30,10 +30,10 @@ describe('[Bank]', () => { smart contract balance goes above the 1B limit */ - /* transfers.push({ + transfers.push({ sender: user1 as unknown as SandboxContract, - coins: BigInt('1000000000'), - }); */ + value: BigInt('1000000000'), + }); }); it('[Bank] user1 transfers to smart contract', async () => { @@ -42,7 +42,9 @@ describe('[Bank]', () => { toNano('0.05') ); let bi = 50000000n; + let i = 0; for (const transfer of transfers) { + i += 1; bi += transfer.value; await bankContract.sendTransfer( (user1 as SandboxContract).getSender(), @@ -51,7 +53,11 @@ describe('[Bank]', () => { } ); const bal = await bankContract.getBal(); - expect(bal).toBe(bi); + if (i === transfers.length) { + expect(bal).toBe(bi - 1000000000n); + } else { + expect(bal).toBe(bi); + } } }); });