Skip to content

Commit

Permalink
non-native transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 19, 2024
1 parent c5c48a0 commit 72581c0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
25 changes: 25 additions & 0 deletions zombienet_tests/0003-non-native-fee-payment-test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[settings]
timeout = 1000

[relaychain]
chain = "rococo-local"
command = "polkadot"

[[relaychain.nodes]]
name = "alice"
validator = true

[[relaychain.nodes]]
name = "bob"
validator = true

[[parachains]]
id = 2000
addToGenesis = false

[parachains.collator]
name = "regionx-collator01"
command = "regionx-node"
args = [ "-lruntime=debug,parachain=trace" ]


10 changes: 10 additions & 0 deletions zombienet_tests/0003-non-native-fee-payment-test.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description: Native currency fee payment
Network: ./0003-non-native-fee-payment-test.toml
Creds: config

alice: is up
bob: is up

alice: parachain 2000 is registered within 225 seconds

regionx-collator01: js-script ./0003-non-native-transfer.js return is 0 within 400 seconds
61 changes: 61 additions & 0 deletions zombienet_tests/0003-non-native-transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const BOB = "5HpG9w8EBLe5XCrbczpwq5TSXvedjrBGCwqxK1iQ7qUsSWFc";
const ASSET_ID = 42;

async function run(nodeName, networkInfo, _jsArgs) {
const { wsUri, userDefinedTypes } = networkInfo.nodesByName[nodeName];
const api = await zombie.connect(wsUri, {
...userDefinedTypes,
signedExtensions: {
ChargeAssetTxPayment: {
extrinsic: {
tip: 'Compact<Balance>',
assetId: 'Option<u32>'
},
payload: {}
}
}});

await zombie.util.cryptoWaitReady();

// account to submit tx
const keyring = new zombie.Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");

const createCall = api.tx.assets.forceCreate(ASSET_ID, alice.address, true, 50);
const mintCall = api.tx.assets.mint(ASSET_ID, alice.address, 10n**6n);

const sudo = api.tx.sudo.sudo(createCall);
await submitExtrinsic(alice, sudo, {});
await submitExtrinsic(alice, mintCall, {});

const transferCall = api.tx.balances.transferKeepAlive(BOB, 10n**6n);
const feePaymentAsset = api.registry.createType('Option<u32>', ASSET_ID);
await submitExtrinsic(alice, transferCall, {assetId: feePaymentAsset});

return 0;
}

async function submitExtrinsic(signer, call, options) {
return new Promise(async (resolve, reject) => {
const unsub = await call.signAndSend(signer, options, (result) => {
console.log(`Current status is ${result.status}`);
if (result.status.isInBlock) {
console.log(
`Transaction included at blockHash ${result.status.asInBlock}`
);
} else if (result.status.isFinalized) {
console.log(
`Transaction finalized at blockHash ${result.status.asFinalized}`
);
unsub();
return resolve();
} else if (result.isError) {
console.log(`Transaction error`);
unsub();
return resolve();
}
});
});
}

module.exports = { run };

0 comments on commit 72581c0

Please sign in to comment.