Skip to content

Commit

Permalink
Add test for SC transferring ESDT to non-existing account
Browse files Browse the repository at this point in the history
  • Loading branch information
lcswillems committed Dec 14, 2024
1 parent 2228482 commit 76738bc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Binary file modified xsuite/contracts/output-reproducible/world/world.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions xsuite/contracts/world/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ pub trait World {
self.n().set(n);
}

#[payable("*")]
#[endpoint]
fn transfer_received(&self, to: ManagedAddress) {
let token = self.call_value().egld_or_single_esdt();
self.send().direct(&to, &token.token_identifier, token.token_nonce, &token.amount);
}

#[endpoint]
fn get_back_transfers(&self) -> (BigUint, MultiEsdtPayment<Self::Api>) {
let BackTransfers { total_egld_amount, esdt_payments } = self.blockchain().get_back_transfers();
Expand Down
22 changes: 22 additions & 0 deletions xsuite/src/world/fsworld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,28 @@ test.concurrent("FSWallet.callContract - change the state", async () => {
});
});

test.concurrent(
"FSWallet.callContract - transfer ESDT to non-existent account",
async () => {
using world = await FSWorld.start();
const { wallet, contract } = await createAccounts(world);
const nonExistentWallet = world.newWallet(createAddressLike("wallet"));
await wallet.callContract({
callee: contract,
funcName: "transfer_received",
funcArgs: [nonExistentWallet],
esdts: [{ id: fftId, amount: 10n ** 17n }],
gasLimit: 10_000_000,
});
assertAccount(await wallet.getAccount(), {
hasKvs: { esdts: [{ id: fftId, amount: 9n * 10n ** 17n }] },
});
assertAccount(await nonExistentWallet.getAccount(), {
hasKvs: { esdts: [{ id: fftId, amount: 10n ** 17n }] },
});
},
);

test.concurrent(
"FSWallet.callContract - succeeding async call v2",
async () => {
Expand Down
23 changes: 23 additions & 0 deletions xsuite/src/world/lsworld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,29 @@ test.concurrent("LSWallet.callContract - change the state", async () => {
});
});

// TODO-MvX: To run once Mandos is fixed
test.todo(
"LSWallet.callContract - transfer ESDT to non-existent account",
async () => {
using world = await LSWorld.start();
const { wallet, contract } = await createAccounts(world);
const nonExistentWallet = world.newWallet(createAddressLike("wallet"));
await wallet.callContract({
callee: contract,
funcName: "transfer_received",
funcArgs: [nonExistentWallet],
esdts: [{ id: fftId, amount: 10n ** 17n }],
gasLimit: 10_000_000,
});
assertAccount(await wallet.getAccount(), {
hasKvs: { esdts: [{ id: fftId, amount: 9n * 10n ** 17n }] },
});
assertAccount(await nonExistentWallet.getAccount(), {
hasKvs: { esdts: [{ id: fftId, amount: 10n ** 17n }] },
});
},
);

test.concurrent("LSWallet.callContract - failure", async () => {
using world = await LSWorld.start();
const { wallet, contract } = await createAccounts(world);
Expand Down

0 comments on commit 76738bc

Please sign in to comment.