From 72581c02e381a6867b4294a068269b49c89aaee9 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 19 Apr 2024 20:52:57 +0200 Subject: [PATCH] non-native transfer --- .../0003-non-native-fee-payment-test.toml | 25 ++++++++ .../0003-non-native-fee-payment-test.zndsl | 10 +++ zombienet_tests/0003-non-native-transfer.js | 61 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 zombienet_tests/0003-non-native-fee-payment-test.toml create mode 100644 zombienet_tests/0003-non-native-fee-payment-test.zndsl create mode 100644 zombienet_tests/0003-non-native-transfer.js diff --git a/zombienet_tests/0003-non-native-fee-payment-test.toml b/zombienet_tests/0003-non-native-fee-payment-test.toml new file mode 100644 index 00000000..c74fbef6 --- /dev/null +++ b/zombienet_tests/0003-non-native-fee-payment-test.toml @@ -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" ] + + diff --git a/zombienet_tests/0003-non-native-fee-payment-test.zndsl b/zombienet_tests/0003-non-native-fee-payment-test.zndsl new file mode 100644 index 00000000..c327635d --- /dev/null +++ b/zombienet_tests/0003-non-native-fee-payment-test.zndsl @@ -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 diff --git a/zombienet_tests/0003-non-native-transfer.js b/zombienet_tests/0003-non-native-transfer.js new file mode 100644 index 00000000..b07ed2ab --- /dev/null +++ b/zombienet_tests/0003-non-native-transfer.js @@ -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', + assetId: 'Option' + }, + 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', 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 };