Skip to content

Commit

Permalink
Test e2e runtime upgrade (#909)
Browse files Browse the repository at this point in the history
* Unify ports for all tests suites/each job runs in its own machine; modify e2e workflow to run upgrade-chain test

* Upgrade test chain infra

* Integrate zombie tests and chopsticks tests in one workflow each; rm chopsticks-configs/laos as not needed anymore

* Add WS provider to describeWithExistingNode as we need to advance blocks in chopsticks

* npm fmt

* Fix CI typo

* Update setups and use chopsticks for upgrade chain test

* test upgrade chain finds wasm

* fmt

* Fix CI

* Ugrade chain test

* Remove custom IPs for XCM suite
  • Loading branch information
tsenovilla authored Dec 12, 2024
1 parent 12e981c commit 6c7708e
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 47 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
working-directory: ./e2e-tests


tests:
zombie-tests:
needs: [build, lint]
runs-on:
group: laos
Expand Down Expand Up @@ -112,17 +112,22 @@ jobs:
npm install
working-directory: ./e2e-tests

- name: Npm build
run: |
npm run build
working-directory: ./e2e-tests

- name: Run evm tests
run: |
npm run build && npm run test-evm
npm run test-evm
working-directory: ./e2e-tests

- name: Run deploy tests
- name: Run contract deploy test
run: |
npm run test-deploy
working-directory: ./e2e-tests

xcm-tests:
chopsticks-tests:
needs: [build, lint]
runs-on:
group: laos
Expand Down Expand Up @@ -154,7 +159,7 @@ jobs:
run: |
npx @acala-network/chopsticks xcm \
-r polkadot \
-p chopsticks-configs/laos.yml \
-p laos \
-p chopsticks-configs/asset_hub.yml &
echo "Chopsticks started"
working-directory: ./e2e-tests
Expand All @@ -163,7 +168,18 @@ jobs:
run: |
timeout 36 sh -c 'until nc -z $0 $1; do echo -n .; sleep 1; done' localhost 8000
- name: Npm build
run: |
npm run build
working-directory: ./e2e-tests

- name: Run upgrade chain test
run: |
npm run test-upgrade-chain
working-directory: ./e2e-tests

- name: Run xcm tests
run: |
npm run build && npm run test-xcm
npm run test-xcm
working-directory: ./e2e-tests

17 changes: 0 additions & 17 deletions e2e-tests/chopsticks-configs/laos.yml

This file was deleted.

7 changes: 4 additions & 3 deletions e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"fmt-check": "prettier ./ --check",
"fmt": "prettier ./ --write",
"build": "./compile_contracts.sh",
"test-evm": "mocha -r ts-node/register -r tsconfig-paths/register -t 900000 'tests/evm/*.ts' --exclude 'tests/evm/test-deploy-contract.ts'",
"test-deploy": "hardhat test --network zombienet tests/evm/test-deploy-contract.ts",
"test-xcm": "mocha -r ts-node/register -r tsconfig-paths/register -t 900000 'tests/xcm/*.ts'"
"test-evm": "mocha -r ts-node/register -r tsconfig-paths/register -t 900000 'tests/evm/*.ts'",
"test-deploy": "hardhat test --network zombienet tests/deploy/*.ts",
"test-xcm": "mocha -r ts-node/register -r tsconfig-paths/register -t 900000 'tests/xcm/*.ts'",
"test-upgrade-chain": "mocha -r ts-node/register -r tsconfig-paths/register -t 900000 'tests/upgrade-chain/*.ts'"
},
"author": "",
"license": "ISC",
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions e2e-tests/tests/upgrade-chain/test-upgrade-chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect } from "chai";
import path from "path";
import { existsSync, readFileSync } from "fs";
import { step } from "mocha-steps";
import { describeWithExistingNode } from "@utils/setups";
import { CHOPSTICKS_LAOS_NODE_IP, RUNTIME_SPEC_VERSION, TARGET_PATH } from "@utils/constants";
import { sendTxAndWaitForFinalization } from "@utils/transactions";

describeWithExistingNode(
"Runtime upgrade",
function () {
step("Runtime spec increases", async function () {
const runtimePath = path.join(
TARGET_PATH,
"release/wbuild/laos-runtime/laos_runtime.compact.compressed.wasm"
);

if (!existsSync(runtimePath)) {
throw new Error(`Unable to find LAOS wasm at ${runtimePath}`);
}

const wasmFile = readFileSync(runtimePath).toString("hex");

const liveSpecVersion = this.chains.laos.consts.system.version.specVersion.toNumber();

// The runtime version in LAOS is at most the latest in the repo
expect(
liveSpecVersion <= RUNTIME_SPEC_VERSION,
"live runtime version is greater than developed version"
).to.be.true;

// Upgrade only if the live spec version isn't the latest in the repo
if (liveSpecVersion !== RUNTIME_SPEC_VERSION) {
const tx = this.chains.laos.tx.sudo.sudo(this.chains.laos.tx.system.setCode(`0x${wasmFile}`));

await sendTxAndWaitForFinalization(this.chains.laos, tx, this.ethereumPairs.alith);

// Advance a block so the upgrade takes place
await this.wsProvider.send("dev_newBlock", [{ count: 1 }]);

const liveSpecVersion = this.chains.laos.consts.system.version.specVersion.toNumber();

expect(liveSpecVersion === RUNTIME_SPEC_VERSION, "Runtime version wasn't upgraded").to.be.true;
}
});
},
// Override LAOS node ip as this test is run with chopsticks
CHOPSTICKS_LAOS_NODE_IP
);
10 changes: 7 additions & 3 deletions e2e-tests/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BN from "bn.js";
import path from "path";
import { AbiItem } from "web3-utils";
import AssetMetadataExtender from "../build/contracts/AssetMetadataExtender.sol/AssetMetadataExtender.json";
import EvolutionCollection from "../build/contracts/EvolutionCollection.sol/EvolutionCollection.json";
Expand All @@ -12,11 +13,11 @@ export const RUNTIME_SPEC_VERSION = 2400;
export const RUNTIME_IMPL_VERSION = 0;

// Nodes endpoints
export const LAOS_NODE_IP = "127.0.0.1:9999";
export const ZOMBIE_LAOS_NODE_IP = "127.0.0.1:9999";

// XCM nodes endpoints
export const XCM_LAOS_NODE_IP = "127.0.0.1:8000";
export const XCM_ASSET_HUB_NODE_IP = "127.0.0.1:8001";
export const CHOPSTICKS_LAOS_NODE_IP = "127.0.0.1:8000";
export const CHOPSTICKS_ASSET_HUB_NODE_IP = "127.0.0.1:8001";

// Ethereum chain constants
export const CHAIN_ID = 667;
Expand Down Expand Up @@ -71,3 +72,6 @@ export const STAKING_ABI = ParachainStaking.abi as AbiItem[];
// Other
export const MAX_U96 = new BN("79228162514264337593543950336"); // 2^96 - 1
export const REVERT_BYTECODE = "0x60006000fd";

// Paths
export const TARGET_PATH = path.resolve(__dirname, "../../target");
31 changes: 14 additions & 17 deletions e2e-tests/utils/setups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import Web3 from "web3";
import { sovereignAccountOf, siblingParachainLocation, relayChainLocation } from "@utils/xcm";
import { CustomSuiteContext, XcmSuiteContext } from "@utils/types";
import {
LAOS_NODE_IP,
ZOMBIE_LAOS_NODE_IP,
CHOPSTICKS_LAOS_NODE_IP,
CHOPSTICKS_ASSET_HUB_NODE_IP,
ALITH_PRIVATE_KEY,
BALTATHAR_PRIVATE_KEY,
FAITH_PRIVATE_KEY,
LAOS_PARA_ID,
ASSET_HUB_PARA_ID,
XCM_LAOS_NODE_IP,
XCM_ASSET_HUB_NODE_IP,
POLKADOT_PREFIX,
} from "@utils/constants";

Expand All @@ -21,12 +21,13 @@ import {
*
* @param {string} title - The title of the test
* @param {() => void} cb - The test itself
* @param {string} [providerLaosNodeUrl] - An optional URL to connect with the LAOS node
* @param {string} [providerLaosNodeIP] - An optional IP to connect with the LAOS node. By default, it's connected to
* zombienet.
*/
export function describeWithExistingNode(title: string, cb: () => void, providerLaosNodeUrl?: string) {
export function describeWithExistingNode(title: string, cb: () => void, providerLaosNodeIP?: string) {
describe(title, function (this: CustomSuiteContext) {
before(async function () {
this.web3 = new Web3(providerLaosNodeUrl || "http://" + LAOS_NODE_IP);
this.web3 = new Web3(providerLaosNodeIP ? `http://${providerLaosNodeIP}` : `http://${ZOMBIE_LAOS_NODE_IP}`);

let keyring = new Keyring({ type: "sr25519" });
this.substratePairs = {
Expand All @@ -50,10 +51,13 @@ export function describeWithExistingNode(title: string, cb: () => void, provider
this.web3.eth.accounts.wallet.add(BALTATHAR_PRIVATE_KEY);
this.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);

let provider = new WsProvider(providerLaosNodeUrl || "ws://" + LAOS_NODE_IP);
let provider = new WsProvider(
providerLaosNodeIP ? `ws://${providerLaosNodeIP}` : `ws://${ZOMBIE_LAOS_NODE_IP}`
);
const apiLaos = await new ApiPromise({ provider }).isReady;

this.chains = { laos: apiLaos };
this.wsProvider = provider;
});

cb();
Expand All @@ -70,15 +74,8 @@ export function describeWithExistingNode(title: string, cb: () => void, provider
*
* @param {string} title - The title of the test
* @param {() => void} cb - The test itself
* @param {string} [providerLaosNodeUrl] - An optional URL to connect with the LAOS node
* @param {string} [providerAssetHubNodeUrl] - An optional URL to connect with the Asset Hub node
*/
export function describeWithExistingNodeXcm(
title: string,
cb: () => void,
providerLaosNodeUrl?: string,
providerAssetHubNodeUrl?: string
) {
export function describeWithExistingNodeXcm(title: string, cb: () => void) {
describe(title, function (this: XcmSuiteContext) {
before(async function () {
// In Xcm tests we use chopsticks and fork Paseo, which uses prefixed addresses.
Expand All @@ -100,10 +97,10 @@ export function describeWithExistingNodeXcm(
faith: keyring.addFromUri(FAITH_PRIVATE_KEY),
};

const laosProvider = new WsProvider(providerLaosNodeUrl || "ws://" + XCM_LAOS_NODE_IP);
const laosProvider = new WsProvider(`ws://${CHOPSTICKS_LAOS_NODE_IP}`);
const apiLaos = await new ApiPromise({ provider: laosProvider }).isReady;

const assetHubProvider = new WsProvider(providerAssetHubNodeUrl || "ws://" + XCM_ASSET_HUB_NODE_IP);
const assetHubProvider = new WsProvider(`ws://${CHOPSTICKS_ASSET_HUB_NODE_IP}`);
const apiAssetHub = await ApiPromise.create({ provider: assetHubProvider });

this.chains = { laos: apiLaos, assetHub: apiAssetHub };
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Suite } from "mocha";
import { MultiAddress, AccountId } from "@polkadot/types/interfaces";
import { XcmVersionedLocation, StagingXcmV3MultiLocation } from "@polkadot/types/lookup";
import { KeyringPair } from "@polkadot/keyring/types";
import { ApiPromise } from "@polkadot/api";
import { ApiPromise, WsProvider } from "@polkadot/api";
import Web3 from "web3";

type assetHubItems = {
Expand Down Expand Up @@ -60,6 +60,7 @@ export interface CustomSuiteContext extends Suite {
substratePairs: substratePairs;
ethereumPairs: ethereumPairs;
laosItems: laosItems;
wsProvider: WsProvider;
}

export interface XcmSuiteContext extends Suite {
Expand Down

0 comments on commit 6c7708e

Please sign in to comment.