Skip to content

Commit

Permalink
add a gh action to check formatting of e2e test scripts (#119)
Browse files Browse the repository at this point in the history
* add a gh action to check formatting of e2e test scripts

* fix node

* disable build

* fix build

* working?

* use npm

* fixes

* prettier

* fix npm run build

---------

Co-authored-by: Sergej <[email protected]>
  • Loading branch information
cuteolaf and Szegoo authored May 10, 2024
1 parent e52b9ee commit c8b8f7a
Show file tree
Hide file tree
Showing 17 changed files with 590 additions and 501 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
node_modules/
28 changes: 28 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"env": {
"node": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "script"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-undef": "off"
}
}
30 changes: 30 additions & 0 deletions .github/workflows/lint-e2e_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lint e2e_tests

on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
lint:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
working-directory: ./e2e_tests
steps:
- name: Checkout
uses: actions/[email protected]
- run: npm i
- run: npm run format
- run: npm run lint
- run: npm run build
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
node_modules/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"singleQuote": true,
"tabWidth": 2,
"semi": true,
"useTabs": false,
"trailingComma": "es5",
"arrowParens": "always"
}
109 changes: 55 additions & 54 deletions e2e_tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,75 @@
import { ApiPromise, Keyring } from "@polkadot/api";
import { SubmittableExtrinsic, SignerOptions } from "@polkadot/api/types";
import { KeyringPair } from "@polkadot/keyring/types";
import { ApiPromise, Keyring } from '@polkadot/api';
import { SignerOptions, SubmittableExtrinsic } from '@polkadot/api/types';
import { KeyringPair } from '@polkadot/keyring/types';

const RELAY_ASSET_ID = 1;

async function submitExtrinsic(
signer: KeyringPair,
call: SubmittableExtrinsic<"promise">,
options: Partial<SignerOptions>
signer: KeyringPair,
call: SubmittableExtrinsic<'promise'>,
options: Partial<SignerOptions>
): Promise<void> {
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 reject();
}
});
});
return new Promise((resolve, reject) => {
const unsub = 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.then();
return resolve();
} else if (result.isError) {
console.log('Transaction error');
unsub.then();
return reject();
}
});
});
}

async function setupRelayAsset(
api: ApiPromise,
signer: KeyringPair,
initialBalance: bigint = 0n
) {
const assetMetadata = {
decimals: 12,
name: "ROC",
symbol: "ROC",
existentialDeposit: 10n ** 3n,
location: null,
additional: null,
};
async function setupRelayAsset(api: ApiPromise, signer: KeyringPair, initialBalance = 0n) {
const assetMetadata = {
decimals: 12,
name: 'ROC',
symbol: 'ROC',
existentialDeposit: 10n ** 3n,
location: null,
additional: null,
};

const assetSetupCalls = [
api.tx.assetRegistry.registerAsset(assetMetadata, RELAY_ASSET_ID),
api.tx.assetRate.create(RELAY_ASSET_ID, 1_000_000_000_000_000_000n), // 1 on 1
];
const assetSetupCalls = [
api.tx.assetRegistry.registerAsset(assetMetadata, RELAY_ASSET_ID),
api.tx.assetRate.create(RELAY_ASSET_ID, 1_000_000_000_000_000_000n), // 1 on 1
];

if (initialBalance > BigInt(0)) {
assetSetupCalls.push(
api.tx.tokens.setBalance(signer.address, RELAY_ASSET_ID, initialBalance, 0)
);
}
if (initialBalance > BigInt(0)) {
assetSetupCalls.push(
api.tx.tokens.setBalance(signer.address, RELAY_ASSET_ID, initialBalance, 0)
);
}

const batchCall = api.tx.utility.batch(assetSetupCalls);
const sudoCall = api.tx.sudo.sudo(batchCall);
const batchCall = api.tx.utility.batch(assetSetupCalls);
const sudoCall = api.tx.sudo.sudo(batchCall);

await submitExtrinsic(signer, sudoCall, {});
await submitExtrinsic(signer, sudoCall, {});
}

// Transfer the relay chain asset to the parachain specified by paraId.
// Receiver address is same as the sender's.
async function transferRelayAssetToPara(amount: bigint, paraId: number, relayApi: ApiPromise, signer: KeyringPair) {
async function transferRelayAssetToPara(
amount: bigint,
paraId: number,
relayApi: ApiPromise,
signer: KeyringPair
) {
const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(signer.address);

// If system parachain we use teleportation, otherwise we do a reserve transfer.
const transferKind = paraId < 2000 ? 'limitedTeleportAssets' : 'limitedReserveTransferAssets';

const feeAssetItem = 0;
const weightLimit = "Unlimited";
const weightLimit = 'Unlimited';
const reserveTransfer = relayApi.tx.xcmPallet[transferKind](
{ V3: { parents: 0, interior: { X1: { Parachain: paraId } } } }, //dest
{
Expand All @@ -77,7 +78,7 @@ async function transferRelayAssetToPara(amount: bigint, paraId: number, relayApi
interior: {
X1: {
AccountId32: {
chain: "Any",
chain: 'Any',
id: receiverKeypair.pairs[0].publicKey,
},
},
Expand All @@ -88,7 +89,7 @@ async function transferRelayAssetToPara(amount: bigint, paraId: number, relayApi
V3: [
{
id: {
Concrete: { parents: 0, interior: "Here" },
Concrete: { parents: 0, interior: 'Here' },
},
fun: {
Fungible: amount,
Expand All @@ -97,13 +98,13 @@ async function transferRelayAssetToPara(amount: bigint, paraId: number, relayApi
],
}, //asset
feeAssetItem,
weightLimit,
weightLimit
);
await submitExtrinsic(signer, reserveTransfer, {});
}

async function sleep(milliseconds: number) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}

export { submitExtrinsic, setupRelayAsset, transferRelayAssetToPara, sleep, RELAY_ASSET_ID }
export { RELAY_ASSET_ID, setupRelayAsset, sleep, submitExtrinsic, transferRelayAssetToPara };
2 changes: 1 addition & 1 deletion e2e_tests/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ const CONFIG = {
contribution_timeout: 5,
};

export {UNIT, INITIAL_PRICE, CORE_COUNT, TIMESLICE_PERIOD, IDEAL_CORES_SOLD, CONFIG};
export { CONFIG, CORE_COUNT, IDEAL_CORES_SOLD, INITIAL_PRICE, TIMESLICE_PERIOD, UNIT };
68 changes: 34 additions & 34 deletions e2e_tests/fee-payment/custom.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { submitExtrinsic, setupRelayAsset, RELAY_ASSET_ID } from "../common";
import { ApiPromise, Keyring, WsProvider } from '@polkadot/api';
import { RELAY_ASSET_ID, setupRelayAsset, submitExtrinsic } from '../common';

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri: regionXUri } = networkInfo.nodesByName[nodeName];
const { wsUri: rococoUri } = networkInfo.nodesByName["rococo-validator01"];

const rococoApi = await ApiPromise.create({ provider: new WsProvider(rococoUri) });
const regionXApi = await ApiPromise.create({
provider: new WsProvider(regionXUri),
signedExtensions: {
ChargeAssetTxPayment: {
extrinsic: {
tip: "Compact<Balance>",
assetId: "Option<AssetId>",
},
payload: {},
},
},
});

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

const setXcmVersion = rococoApi.tx.xcmPallet.forceDefaultXcmVersion([3]);
await submitExtrinsic(alice, rococoApi.tx.sudo.sudo(setXcmVersion), {});

await setupRelayAsset(regionXApi, alice, 10n**12n);

const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(alice.address);

// Try to pay for fees with relay chain asset.
const remarkCall = regionXApi.tx.system.remark("0x44");
await submitExtrinsic(alice, remarkCall, { assetId: RELAY_ASSET_ID });
const { wsUri: regionXUri } = networkInfo.nodesByName[nodeName];
const { wsUri: rococoUri } = networkInfo.nodesByName['rococo-validator01'];

const rococoApi = await ApiPromise.create({ provider: new WsProvider(rococoUri) });
const regionXApi = await ApiPromise.create({
provider: new WsProvider(regionXUri),
signedExtensions: {
ChargeAssetTxPayment: {
extrinsic: {
tip: 'Compact<Balance>',
assetId: 'Option<AssetId>',
},
payload: {},
},
},
});

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

const setXcmVersion = rococoApi.tx.xcmPallet.forceDefaultXcmVersion([3]);
await submitExtrinsic(alice, rococoApi.tx.sudo.sudo(setXcmVersion), {});

await setupRelayAsset(regionXApi, alice, 10n ** 12n);

const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(alice.address);

// Try to pay for fees with relay chain asset.
const remarkCall = regionXApi.tx.system.remark('0x44');
await submitExtrinsic(alice, remarkCall, { assetId: RELAY_ASSET_ID });
}

export { run };
22 changes: 11 additions & 11 deletions e2e_tests/fee-payment/native.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api";
import { submitExtrinsic } from "../common";
import { ApiPromise, Keyring, WsProvider } from '@polkadot/api';
import { submitExtrinsic } from '../common';

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri } = networkInfo.nodesByName[nodeName];
const api = await ApiPromise.create({ provider: new WsProvider(wsUri) });
const { wsUri } = networkInfo.nodesByName[nodeName];
const api = await ApiPromise.create({ provider: new WsProvider(wsUri) });

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

const call = api.tx.balances.transferKeepAlive(bob.address, 10n ** 6n);
const sudo = api.tx.sudo.sudo(call);
await submitExtrinsic(alice, sudo, {});
const call = api.tx.balances.transferKeepAlive(bob.address, 10n ** 6n);
const sudo = api.tx.sudo.sudo(call);
await submitExtrinsic(alice, sudo, {});
}

export { run };
Loading

0 comments on commit c8b8f7a

Please sign in to comment.