From b2725443881abec5cf82b2bcb1e5cc3674d25130 Mon Sep 17 00:00:00 2001 From: Chralt98 Date: Wed, 20 Dec 2023 09:57:07 +0100 Subject: [PATCH] add xcm test to post rt upgrade suite --- .github/workflows/integration-tests.yml | 55 ++-------- integration-tests/moonwall.config.json | 103 +++++++++--------- .../test-chopsticks-xcm-transfer.ts | 78 ------------- .../test-chopsticks-runtime-upgrade.ts | 92 +++++++++++++--- 4 files changed, 134 insertions(+), 194 deletions(-) delete mode 100644 integration-tests/tests/chopsticks-xcm/test-chopsticks-xcm-transfer.ts diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 151e7c9ad..cb394de51 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -103,7 +103,7 @@ jobs: ./integration-tests/scripts/deploy-zombienet.sh --test zombienet_zeitgeist_upgrade: - name: Zombienet Runtime Upgrade Zeitgeist + name: Zeitgeist Zombienet Post-Upgrade Tests runs-on: ubuntu-20.04 needs: ["build_parachain"] steps: @@ -132,14 +132,14 @@ jobs: - name: Create local folders run: | - mkdir -p target/release/wbuild/battery-station-runtime/ + mkdir -p target/release/wbuild/zeitgeist-runtime/ mkdir -p integration-tests/tmp - name: Download runtime uses: actions/download-artifact@v3.0.2 with: name: runtimes - path: target/release/wbuild/battery-station-runtime/ + path: target/release/wbuild/zeitgeist-runtime/ - name: Download binary uses: actions/download-artifact@v3.0.2 @@ -159,7 +159,7 @@ jobs: pnpm exec moonwall test zombienet_zeitgeist_upgrade chopsticks_battery_station_upgrade: - name: Chopsticks Runtime Upgrade Battery Station + name: Battery Station Chopsticks Post-Upgrade Tests runs-on: ubuntu-20.04 needs: ["build_parachain"] steps: @@ -202,7 +202,7 @@ jobs: run: ls -R working-directory: target/ - - name: Test battery station runtime upgrade using Chopsticks + - name: Battery Station post-upgrade tests using Chopsticks run: | cd integration-tests pnpm exec moonwall test chopsticks_battery_station_upgrade @@ -210,7 +210,7 @@ jobs: cat tmp/node_logs/*.log chopsticks_zeitgeist_upgrade: - name: Chopsticks Runtime Upgrade Zeitgeist + name: Zeitgeist Chopsticks Post-Upgrade Tests runs-on: ubuntu-20.04 needs: ["build_parachain"] steps: @@ -253,50 +253,9 @@ jobs: run: ls -R working-directory: target/ - - name: Test zeitgeist runtime upgrade using Chopsticks + - name: Zeitgeist post-upgrade tests using Chopsticks run: | cd integration-tests pnpm exec moonwall test chopsticks_zeitgeist_upgrade ls -R tmp/node_logs/ cat tmp/node_logs/*.log - - chopsticks_zeitgeist_hydradx_xcm_tests: - name: Chopsticks Zeitgeist HydraDX XCM Tests - runs-on: ubuntu-20.04 - needs: ["build_parachain"] - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Install build tools - run: ./scripts/init.sh - - - uses: pnpm/action-setup@v2 - with: - version: 8 - - uses: actions/setup-node@v3 - with: - node-version: 20.x - cache: "pnpm" - cache-dependency-path: "./integration-tests/pnpm-lock.yaml" - - - name: Install pnpm packages - run: | - cd integration-tests - pnpm install - - - name: Cache Dependencies - uses: Swatinem/rust-cache@v1 - - - name: Create local folders - run: | - mkdir -p integration-tests/tmp - mkdir -p integration-tests/tmp/node_logs - - - name: Test zeitgeist xcm tests using Chopsticks - run: | - cd integration-tests - pnpm exec moonwall test chopsticks_zeitgeist_hydra_xcm_tests - ls -R tmp/node_logs/ - cat tmp/node_logs/*.log - diff --git a/integration-tests/moonwall.config.json b/integration-tests/moonwall.config.json index 151e13a53..7970f07fe 100644 --- a/integration-tests/moonwall.config.json +++ b/integration-tests/moonwall.config.json @@ -44,21 +44,41 @@ "type": "chopsticks", "rtUpgradePath": "../target/release/wbuild/zeitgeist-runtime/zeitgeist_runtime.compact.compressed.wasm", "launchSpec": [ - { - "name": "db", - "type": "parachain", - "configPath": "./configs/zeitgeist.yml" - } + { + "name": "PolkadotDB", + "type": "relaychain", + "configPath": "polkadot" + }, + { + "name": "HydraDXDB", + "type": "parachain", + "configPath": "./configs/hydradx.yml" + }, + { + "name": "ZeitgeistDB", + "type": "parachain", + "configPath": "./configs/zeitgeist.yml" + } ] }, "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"], "buildBlockMode": "manual", "connections": [ - { - "name": "DB", + { + "name": "PolkadotRelay", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:8002"] + }, + { + "name": "HydraDXPara", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:8000"] + }, + { + "name": "ZeitgeistPara", "type": "polkadotJs", - "endpoints": ["ws://127.0.0.1:8000"] - } + "endpoints": ["ws://127.0.0.1:8001"] + } ] }, { @@ -68,63 +88,40 @@ "type": "chopsticks", "rtUpgradePath": "../target/release/wbuild/battery-station-runtime/battery_station_runtime.compact.compressed.wasm", "launchSpec": [ - { - "name": "db", - "type": "parachain", - "configPath": "./configs/battery-station.yml" - } - ] - }, - "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"], - "buildBlockMode": "manual", - "connections": [ - { - "name": "DB", - "type": "polkadotJs", - "endpoints": ["ws://127.0.0.1:8000"] - } - ] - }, - { - "name": "chopsticks_zeitgeist_hydra_xcm_tests", - "testFileDir": ["tests/chopsticks-xcm"], - "foundation": { - "type": "chopsticks", - "launchSpec": [ - { - "name": "PolkadotDB", - "type": "relaychain", - "configPath": "polkadot" - }, - { - "name": "HydraDXDB", - "type": "parachain", - "configPath": "./configs/hydradx.yml" - }, - { - "name": "ZeitgeistDB", - "type": "parachain", - "configPath": "./configs/zeitgeist.yml" - } + { + "name": "ZeitgeistDB", + "type": "parachain", + "configPath": "./configs/battery-station.yml" + }, + { + "name": "HydraDXDB", + "type": "parachain", + "configPath": "./configs/hydradx.yml" + }, + { + "name": "PolkadotDB", + "type": "relaychain", + "configPath": "polkadot" + } ] }, "envVars": ["LOG_LEVEL=debug", "VERBOSE_LOG"], "buildBlockMode": "manual", "connections": [ { - "name": "PolkadotRelay", + "name": "ZeitgeistPara", "type": "polkadotJs", - "endpoints": ["ws://127.0.0.1:8002"] + "endpoints": ["ws://127.0.0.1:8000"] }, { "name": "HydraDXPara", "type": "polkadotJs", - "endpoints": ["ws://127.0.0.1:8000"] + "endpoints": ["ws://127.0.0.1:8001"] }, { - "name": "ZeitgeistPara", - "type": "polkadotJs", - "endpoints": ["ws://127.0.0.1:8001"] + "name": "PolkadotRelay", + "type": "polkadotJs", + "endpoints": ["ws://127.0.0.1:8002"] } ] } diff --git a/integration-tests/tests/chopsticks-xcm/test-chopsticks-xcm-transfer.ts b/integration-tests/tests/chopsticks-xcm/test-chopsticks-xcm-transfer.ts deleted file mode 100644 index 51654691e..000000000 --- a/integration-tests/tests/chopsticks-xcm/test-chopsticks-xcm-transfer.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { KeyringPair } from "@moonwall/util"; -import { ApiPromise, Keyring } from "@polkadot/api"; - -describeSuite({ - id: "CZXCM", - title: "Chopsticks Zeitgeist XCM Tests", - foundationMethods: "chopsticks", - testCases: function ({ it, context, log }) { - let relayApi: ApiPromise; - let zeitgeistParaApi: ApiPromise; - let hydradxParaApi: ApiPromise; - let alice: KeyringPair; - - beforeAll(async () => { - const keyring = new Keyring({ type: "sr25519" }); - alice = keyring.addFromUri("//Alice", { name: "Alice default" }); - relayApi = context.polkadotJs("PolkadotRelay"); - zeitgeistParaApi = context.polkadotJs("ZeitgeistPara"); - hydradxParaApi = context.polkadotJs("HydraDXPara"); - - const relayNetwork = relayApi.consts.system.version.specName.toString(); - expect(relayNetwork, "Relay API incorrect").to.contain("polkadot"); - - const paraZeitgeistNetwork = zeitgeistParaApi.consts.system.version.specName.toString(); - expect(paraZeitgeistNetwork, "Para API incorrect").to.contain("zeitgeist"); - - const paraHydraDXNetwork = hydradxParaApi.consts.system.version.specName.toString(); - expect(paraHydraDXNetwork, "Para API incorrect").to.contain("hydradx"); - }); - - it({ - id: "T1", - timeout: 60000, - title: "Can send ZTG to HydraDX", - test: async () => { - const keyring = new Keyring({ type: "sr25519" }); - const alice = keyring.addFromUri("//Alice", { name: "Alice default" }); - const bob = keyring.addFromUri("//Bob", { name: "Bob default" }); - - const zeitgeistBalanceBefore = (await zeitgeistParaApi.query.system.account(alice.address)).data.free.toBigInt(); - const hydradxBalanceBefore = (await hydradxParaApi.query.tokens.accounts(bob.address, 12)).free.toBigInt(); - - const ztg = { 'Ztg': null }; - const amount = "192913122185847181"; - const bobAccountId = zeitgeistParaApi.createType("AccountId32", bob.address).toHex(); - const destination = { - V3: { - parents: 1, - interior: { X2: [{ Parachain: 2034 }, { AccountId32: { id: bobAccountId, network: null } }] }, - } - }; - const destWeightLimit = { Unlimited: null }; - // Create a promise that resolves when the transaction is finalized - const finalizedPromise = new Promise((resolve, reject) => { - zeitgeistParaApi.tx.xTokens.transfer(ztg, amount, destination, destWeightLimit).signAndSend(alice, ({ status }) => { - if (status.isFinalized) { - log(`Transaction finalized at blockHash ${status.asFinalized}`); - resolve(); - } else if (status.isError) { - reject(new Error(`Transaction failed with status ${status}`)); - } - }); - }); - - // Wait for the transaction to be finalized - await finalizedPromise; - - const zeitgeistBalanceAfter = (await zeitgeistParaApi.query.system.account(alice.address)).data.free.toBigInt(); - expect(zeitgeistBalanceBefore > zeitgeistBalanceAfter).to.be.true; - - await context.createBlock({ providerName: "HydraDXPara", count: 1, logger: log }); - const hydradxBalanceAfter = (await hydradxParaApi.query.tokens.accounts(bob.address, 12)).free.toBigInt(); - expect(hydradxBalanceBefore < hydradxBalanceAfter).to.be.true; - }, - }); - }, -}); \ No newline at end of file diff --git a/integration-tests/tests/rt-upgrade-chopsticks/test-chopsticks-runtime-upgrade.ts b/integration-tests/tests/rt-upgrade-chopsticks/test-chopsticks-runtime-upgrade.ts index 1bc6c570f..322897f24 100644 --- a/integration-tests/tests/rt-upgrade-chopsticks/test-chopsticks-runtime-upgrade.ts +++ b/integration-tests/tests/rt-upgrade-chopsticks/test-chopsticks-runtime-upgrade.ts @@ -2,30 +2,44 @@ import { MoonwallContext, beforeAll, describeSuite, expect } from "@moonwall/cli"; import { generateKeyringPair } from "@moonwall/util"; +import { KeyringPair } from "@moonwall/util"; import { ApiPromise, Keyring } from "@polkadot/api"; const MAX_BALANCE_TRANSFER_TRIES = 5; describeSuite({ id: "CAN", - title: "Chopsticks Zeitgeist or Battery Station Upgrade Test", + title: "Chopsticks Zeitgeist or Battery Station Post-Upgrade Tests", foundationMethods: "chopsticks", testCases: function ({ it, context, log }) { - let api: ApiPromise; + let zeitgeistParaApi: ApiPromise; + let relayApi: ApiPromise; + let hydradxParaApi: ApiPromise; + let alice: KeyringPair; beforeAll(async () => { - api = context.polkadotJs(); + const keyring = new Keyring({ type: "sr25519" }); + alice = keyring.addFromUri("//Alice", { name: "Alice default" }); + zeitgeistParaApi = context.polkadotJs("ZeitgeistPara"); + relayApi = context.polkadotJs("PolkadotRelay"); + hydradxParaApi = context.polkadotJs("HydraDXPara"); - const rtBefore = api.consts.system.version.specVersion.toNumber(); + const paraZeitgeistNetwork = zeitgeistParaApi.consts.system.version.specName.toString(); + expect(paraZeitgeistNetwork, "Para API incorrect").to.contain("zeitgeist"); + + const relayNetwork = relayApi.consts.system.version.specName.toString(); + expect(relayNetwork, "Relay API incorrect").to.contain("polkadot"); + + const paraHydraDXNetwork = hydradxParaApi.consts.system.version.specName.toString(); + expect(paraHydraDXNetwork, "Para API incorrect").to.contain("hydradx"); + + const rtBefore = zeitgeistParaApi.consts.system.version.specVersion.toNumber(); log(`About to upgrade to runtime at:`); log(MoonwallContext.getContext().rtUpgradePath); await context.upgradeRuntime(context); - const rtafter = api.consts.system.version.specVersion.toNumber(); + const rtafter = zeitgeistParaApi.consts.system.version.specVersion.toNumber(); log(`RT upgrade has increased specVersion from ${rtBefore} to ${rtafter}`); - - const specName = api.consts.system.version.specName.toString(); - log(`Currently connected to chain: ${specName}`); }); it({ @@ -33,9 +47,9 @@ describeSuite({ timeout: 60000, title: "Can create new blocks", test: async () => { - const currentHeight = (await api.rpc.chain.getBlock()).block.header.number.toNumber(); - await context.createBlock({ count: 2 }); - const newHeight = (await api.rpc.chain.getBlock()).block.header.number.toNumber(); + const currentHeight = (await zeitgeistParaApi.rpc.chain.getBlock()).block.header.number.toNumber(); + await context.createBlock({ providerName: "ZeitgeistPara", count: 2, logger: log }); + const newHeight = (await zeitgeistParaApi.rpc.chain.getBlock()).block.header.number.toNumber(); expect(newHeight - currentHeight).to.be.equal(2); }, }); @@ -50,19 +64,19 @@ describeSuite({ const alice = keyring.addFromUri("//Alice", { name: "Alice default" }); let tries = 0; - const balanceBefore = (await api.query.system.account(randomAccount.address)).data.free.toBigInt(); + const balanceBefore = (await zeitgeistParaApi.query.system.account(randomAccount.address)).data.free.toBigInt(); /// It might happen that by accident we hit a session change /// A block in which a session change occurs cannot hold any tx /// Chopsticks does not have the notion of tx pool either, so we need to retry /// Therefore we just retry at most MAX_BALANCE_TRANSFER_TRIES while (tries < MAX_BALANCE_TRANSFER_TRIES) { - const txHash = await api.tx.balances + const txHash = await zeitgeistParaApi.tx.balances .transfer(randomAccount.address, 1_000_000_000) .signAndSend(alice); const result = await context.createBlock({ count: 1 }); - const block = await api.rpc.chain.getBlock(result.result); + const block = await zeitgeistParaApi.rpc.chain.getBlock(result.result); const includedTxHashes = block.block.extrinsics.map((x) => x.hash.toString()); if (includedTxHashes.includes(txHash.toString())) { break; @@ -70,9 +84,57 @@ describeSuite({ tries++; } - const balanceAfter = (await api.query.system.account(randomAccount.address)).data.free.toBigInt(); + const balanceAfter = (await zeitgeistParaApi.query.system.account(randomAccount.address)).data.free.toBigInt(); expect(balanceBefore < balanceAfter).to.be.true; }, }); + + it({ + id: "T3", + timeout: 60000, + title: "Can send ZTG to HydraDX", + test: async () => { + const keyring = new Keyring({ type: "sr25519" }); + const alice = keyring.addFromUri("//Alice", { name: "Alice default" }); + const bob = keyring.addFromUri("//Bob", { name: "Bob default" }); + + const zeitgeistBalanceBefore = (await zeitgeistParaApi.query.system.account(alice.address)).data.free.toBigInt(); + const hydradxBalanceBefore = (await hydradxParaApi.query.tokens.accounts(bob.address, 12)).free.toBigInt(); + + const ztg = { 'Ztg': null }; + const amount = "192913122185847181"; + const bobAccountId = zeitgeistParaApi.createType("AccountId32", bob.address).toHex(); + const destination = { + V3: { + parents: 1, + interior: { X2: [{ Parachain: 2034 }, { AccountId32: { id: bobAccountId, network: null } }] }, + } + }; + const destWeightLimit = { Unlimited: null }; + // Create a promise that resolves when the transaction is finalized + const finalizedPromise = new Promise((resolve, reject) => { + zeitgeistParaApi.tx.xTokens.transfer(ztg, amount, destination, destWeightLimit).signAndSend(alice, ({ status }) => { + if (status.isFinalized) { + log(`Transaction finalized at blockHash ${status.asFinalized}`); + resolve(); + } else if (status.isError) { + reject(new Error(`Transaction failed with status ${status}`)); + } + }); + }); + + // Wait for the transaction to be finalized + await finalizedPromise; + + const zeitgeistBalanceAfter = (await zeitgeistParaApi.query.system.account(alice.address)).data.free.toBigInt(); + expect(zeitgeistBalanceBefore > zeitgeistBalanceAfter).to.be.true; + + // await context.createBlock({ providerName: "ZeitgeistPara", count: 1, logger: log }); + await context.createBlock({ providerName: "HydraDXPara", count: 1, logger: log }); + // await context.createBlock({ providerName: "PolkadotRelay", count: 1, logger: log }); + const hydradxBalanceAfter = (await hydradxParaApi.query.tokens.accounts(bob.address, 12)).free.toBigInt(); + expect(hydradxBalanceBefore < hydradxBalanceAfter).to.be.true; + }, + }); }, }); \ No newline at end of file