Skip to content

Commit

Permalink
fix CI and typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Dec 22, 2023
1 parent 128401d commit 55dc0d1
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ jobs:
chopsticks_zeitgeist_upgrade:
name: Zeitgeist Chopsticks Post-Upgrade Tests
runs-on: ubuntu-20.04
needs: ["build_parachain"]
# run after "chopsticks_battery_station_upgrade" job, because the moonwall test has port conflicts
needs: ["build_parachain", "chopsticks_battery_station_upgrade"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@
{
"name": "BatteryStationPara",
"type": "polkadotJs",
"endpoints": ["ws://127.0.0.1:8100"]
"endpoints": ["ws://127.0.0.1:8000"]
},
{
"name": "BasiliskPara",
"type": "polkadotJs",
"endpoints": ["ws://127.0.0.1:8101"]
"endpoints": ["ws://127.0.0.1:8001"]
},
{
"name": "RococoRelay",
"type": "polkadotJs",
"endpoints": ["ws://127.0.0.1:8102"]
"endpoints": ["ws://127.0.0.1:8002"]
}
]
}
Expand Down
1 change: 1 addition & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@acala-network/chopsticks": "0.9.3",
"@moonwall/cli": "^4.4.4",
"@moonwall/util": "^4.4.4",
"debug": "4.3.4",
"@polkadot/api": "^10.10.1",
"@polkadot/types": "^10.10.1",
"@types/node": "^20.9.0",
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions integration-tests/specs/zeitgeist-parachain-2092.json

Large diffs are not rendered by default.

70 changes: 31 additions & 39 deletions integration-tests/tests/common-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import { expect, ChopsticksContext } from "@moonwall/cli";
import { generateKeyringPair } from "@moonwall/util";
import { ApiPromise, Keyring } from "@polkadot/api";
import { AccountInfo, AccountData } from "@polkadot/types/interfaces";
import WebSocket from "ws";
import { Debugger } from "debug";

const MAX_BALANCE_TRANSFER_TRIES = 5;

Expand Down Expand Up @@ -34,7 +36,7 @@ export async function canSendBalanceTransfer(
let tries = 0;
const amount = BigInt("1000000000");
const balanceBefore = (
await paraApi.query.system.account(randomAccount.address)
(await paraApi.query.system.account(randomAccount.address)) as AccountInfo
).data.free.toBigInt();

/// It might happen that by accident we hit a session change
Expand Down Expand Up @@ -66,13 +68,15 @@ export async function canSendBalanceTransfer(
await context.createBlock({ providerName: providerName, count: 1 });

const balanceAfter = (
await paraApi.query.system.account(randomAccount.address)
(await paraApi.query.system.account(randomAccount.address)) as AccountInfo
).data.free.toBigInt();
expect(balanceAfter > balanceBefore, "Balance did not increase").toBeTruthy();
}

export async function canSendXcmTransfer(
context: ChopsticksContext,
log: Debugger,
senderProviderName: string,
senderParaApi: ApiPromise,
receiverParaApi: ApiPromise,
receiverParaId: number,
Expand All @@ -83,10 +87,13 @@ export async function canSendXcmTransfer(
const bob = keyring.addFromUri("//Bob", { name: "Bob default" });

const senderBalanceBefore = (
await senderParaApi.query.system.account(alice.address)
(await senderParaApi.query.system.account(alice.address)) as AccountInfo
).data.free.toBigInt();
const receiverBalanceBefore = (
await receiverParaApi.query.tokens.accounts(bob.address, tokensIndex)
(await receiverParaApi.query.tokens.accounts(
bob.address,
tokensIndex
)) as AccountData
).free.toBigInt();

const ztg = { Ztg: null };
Expand All @@ -107,31 +114,25 @@ export async function canSendXcmTransfer(
};
const destWeightLimit = { Unlimited: null };

// Create a promise that resolves when the transaction is finalized
const finalizedPromise = new Promise((resolve, reject) => {
const xcmTransfer = senderParaApi.tx.xTokens.transfer(
ztg,
amount,
destination,
destWeightLimit
);
xcmTransfer.signAndSend(alice, { nonce: -1 }, ({ status }) => {
log(`Current status is ${status.toString()}`);
if (status.isFinalized) {
log(`Transaction finalized at blockHash ${status.asFinalized}`);
resolve(xcmTransfer);
} else if (status.isError) {
reject(new Error(`Transaction failed with status ${status}`));
}
});
const xcmTransfer = senderParaApi.tx.xTokens.transfer(
ztg,
amount,
destination,
destWeightLimit
);

await xcmTransfer.signAndSend(alice, { nonce: -1 });

await context.createBlock({
providerName: senderProviderName,
count: 1,
allowFailures: false,
});

// Wait for the transaction to be finalized
const xcmTransfer = await finalizedPromise;
const { partialFee, weight } = await xcmTransfer.paymentInfo(alice.address);
const transferFee: bigint = partialFee.toBigInt();
const senderBalanceAfter = (
await senderParaApi.query.system.account(alice.address)
(await senderParaApi.query.system.account(alice.address)) as AccountInfo
).data.free.toBigInt();
expect(
senderBalanceBefore - senderBalanceAfter,
Expand All @@ -142,10 +143,6 @@ export async function canSendXcmTransfer(
// Reported Bug here https://github.com/Moonsong-Labs/moonwall/issues/343

// use a workaround for creating a block
const blocksToRun = 2;
const currentHeight = (
await receiverParaApi.rpc.chain.getBlock()
).block.header.number.toNumber();
const newBlockPromise = new Promise((resolve, reject) => {
// ws://127.0.0.1:8001 represents the receiver chain endpoint
const ws = new WebSocket("ws://127.0.0.1:8001");
Expand All @@ -155,7 +152,7 @@ export async function canSendXcmTransfer(
jsonrpc: "2.0",
id: 1,
method: "dev_newBlock",
params: [{ count: blocksToRun }],
params: [{ count: 1 }],
};

ws.send(JSON.stringify(message));
Expand All @@ -173,17 +170,12 @@ export async function canSendXcmTransfer(
});
});

const blockHash = await newBlockPromise;
const newHeight = (
await receiverParaApi.rpc.chain.getBlock()
).block.header.number.toNumber();
// TODO why +1 here?
expect(newHeight - currentHeight, "Block difference is not correct!").toBe(
blocksToRun + 1
);

await newBlockPromise;
const receiverBalanceAfter: bigint = (
await receiverParaApi.query.tokens.accounts(bob.address, tokensIndex)
(await receiverParaApi.query.tokens.accounts(
bob.address,
tokensIndex
)) as AccountData
).free.toBigInt();
expect(
receiverBalanceAfter > receiverBalanceBefore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
canSendBalanceTransfer,
canSendXcmTransfer,
} from "tests/common-tests";
import { RuntimeVersion } from "@polkadot/types/interfaces";

const ZEITGEIST_TOKENS_INDEX = 12;
const BASILISK_PARA_ID = 2090;
Expand All @@ -33,32 +34,38 @@ describeSuite({
relayApi = context.polkadotJs("RococoRelay");
basiliskParaApi = context.polkadotJs("BasiliskPara");

const paraZeitgeistNetwork =
batteryStationParaApi.consts.system.version.specName.toString();
const paraZeitgeistNetwork = (
batteryStationParaApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(paraZeitgeistNetwork, "Para API incorrect").to.contain(
"zeitgeist"
);

const relayNetwork = relayApi.consts.system.version.specName.toString();
const relayNetwork = (
relayApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(relayNetwork, "Relay API incorrect").to.contain("rococo");

const paraBasiliskNetwork =
basiliskParaApi.consts.system.version.specName.toString();
const paraBasiliskNetwork = (
basiliskParaApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(paraBasiliskNetwork, "Para API incorrect").to.contain("basilisk");

const rtBefore =
batteryStationParaApi.consts.system.version.specVersion.toNumber();
const rtBefore = (
batteryStationParaApi.consts.system.version as RuntimeVersion
).specVersion.toNumber();
log(`About to upgrade to runtime at:`);
log(MoonwallContext.getContext().rtUpgradePath);

await context.upgradeRuntime(context);
await context.upgradeRuntime();

const rtafter =
batteryStationParaApi.consts.system.version.specVersion.toNumber();
const rtafter = (
batteryStationParaApi.consts.system.version as RuntimeVersion
).specVersion.toNumber();
log(
`RT upgrade has increased specVersion from ${rtBefore} to ${rtafter}`
);
});
}, 60000);

it({
id: "T1",
Expand Down Expand Up @@ -95,7 +102,9 @@ describeSuite({
title: "Can send ZBS to Basilisk",
test: async () => {
await canSendXcmTransfer(
context,
log,
"BatteryStationPara",
batteryStationParaApi,
basiliskParaApi,
BASILISK_PARA_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
canSendBalanceTransfer,
canSendXcmTransfer,
} from "tests/common-tests";
import { RuntimeVersion } from "@polkadot/types/interfaces";

const ZEITGEIST_TOKENS_INDEX = 12;
const HYDRADX_PARA_ID = 2034;
Expand All @@ -33,32 +34,38 @@ describeSuite({
relayApi = context.polkadotJs("PolkadotRelay");
hydradxParaApi = context.polkadotJs("HydraDXPara");

const paraZeitgeistNetwork =
zeitgeistParaApi.consts.system.version.specName.toString();
const paraZeitgeistNetwork = (
zeitgeistParaApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(paraZeitgeistNetwork, "Para API incorrect").to.contain(
"zeitgeist"
);

const relayNetwork = relayApi.consts.system.version.specName.toString();
const relayNetwork = (
relayApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(relayNetwork, "Relay API incorrect").to.contain("polkadot");

const paraHydraDXNetwork =
hydradxParaApi.consts.system.version.specName.toString();
const paraHydraDXNetwork = (
hydradxParaApi.consts.system.version as RuntimeVersion
).specName.toString();
expect(paraHydraDXNetwork, "Para API incorrect").to.contain("hydradx");

const rtBefore =
zeitgeistParaApi.consts.system.version.specVersion.toNumber();
const rtBefore = (
zeitgeistParaApi.consts.system.version as RuntimeVersion
).specVersion.toNumber();
log(`About to upgrade to runtime at:`);
log(MoonwallContext.getContext().rtUpgradePath);

await context.upgradeRuntime(context);
await context.upgradeRuntime();

const rtafter =
zeitgeistParaApi.consts.system.version.specVersion.toNumber();
const rtafter = (
zeitgeistParaApi.consts.system.version as RuntimeVersion
).specVersion.toNumber();
log(
`RT upgrade has increased specVersion from ${rtBefore} to ${rtafter}`
);
});
}, 60000);

it({
id: "T1",
Expand Down Expand Up @@ -88,7 +95,9 @@ describeSuite({
title: "Can send ZTG to HydraDX",
test: async () => {
await canSendXcmTransfer(
context,
log,
"ZeitgeistPara",
zeitgeistParaApi,
hydradxParaApi,
HYDRADX_PARA_ID,
Expand Down

0 comments on commit 55dc0d1

Please sign in to comment.