Skip to content

Commit

Permalink
prepare last transfer of 1B
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcotech committed Jul 31, 2024
1 parent ffb9095 commit c5ac884
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
18 changes: 17 additions & 1 deletion contracts/bank.fc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {


Expand All @@ -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 ();
}

Expand Down
14 changes: 10 additions & 4 deletions tests/Bank.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe('[Bank]', () => {
smart contract balance goes
above the 1B limit
*/
/* transfers.push({
transfers.push({
sender: user1 as unknown as SandboxContract<TreasuryContract>,
coins: BigInt('1000000000'),
}); */
value: BigInt('1000000000'),
});
});

it('[Bank] user1 transfers to smart contract', async () => {
Expand All @@ -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<TreasuryContract>).getSender(),
Expand All @@ -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);
}
}
});
});

0 comments on commit c5ac884

Please sign in to comment.