Skip to content

Commit

Permalink
added logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Jan 12, 2024
1 parent 7f41851 commit 729e799
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 15 deletions.
1 change: 0 additions & 1 deletion e2e-tests/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const balanceTracker = async (
if (!balance) {
for (const assetId of assetIds) {
accountInfo = await api.query.poolAssets.account(assetId, address);
console.log(accountInfo.value.toHuman());
if (accountInfo.isNone) {
balances.initial.push([assetId, 0]);
} else {
Expand Down
43 changes: 32 additions & 11 deletions e2e-tests/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { delay } from '../scripts/util';
import { constructApiPromise } from '../src';
import { balanceTracker, IBalance } from './balance';
import { KUSAMA_ASSET_HUB_WS_URL, MOONRIVER_WS_URL, ROCOCO_ALICE_WS_URL, TRAPPIST_WS_URL } from './consts';
import { startProgressBar, startTestLogger, terminateProgressBar, testResultLogger, updateProgressBar } from './logger';
import { assetTests, foreignAssetsTests, IndividualTest, liquidPoolsTests, localTests, tests } from './tests';
import { verification } from './verification';

Expand All @@ -16,7 +17,6 @@ const executor = async (testCase: string) => {
let destWsUrl = '';

let testData: IndividualTest[] = [];
console.log(testCase);

await cryptoWaitReady();

Expand Down Expand Up @@ -53,7 +53,6 @@ const executor = async (testCase: string) => {
n = assetTests;
break;
}
console.log(n);

let originChainId = '';
let destChainId = '';
Expand All @@ -62,6 +61,13 @@ const executor = async (testCase: string) => {
let assetIds: string[] = [];
let amounts: string[] = [];
let opts: object = {};
let counter: number = 0;

startTestLogger(testCase);

const progressBar = startProgressBar(testData, testCase);

const results: [string, string, string, boolean][] = [];

for (const t of testData) {
originChainId = t.args[0];
Expand All @@ -73,40 +79,49 @@ const executor = async (testCase: string) => {
opts = JSON.parse(t.args[6], (key: string, value: string) => {
return key === 'paysWithFeeOrigin' ? JSON.stringify(value) : value;
}) as object;
let chainName: string = '';

switch (originChainId) {
case '0':
originWsUrl = ROCOCO_ALICE_WS_URL;
chainName = 'Rococo';
break;
case '1000':
originWsUrl = KUSAMA_ASSET_HUB_WS_URL;
chainName = 'Kusama Asset Hub';
break;
case '1836':
originWsUrl = TRAPPIST_WS_URL;
chainName = 'Trappist';
break;
case '4000':
originWsUrl = MOONRIVER_WS_URL;
chainName = 'Moonriver';
break;
}

if (originChainId == destChainId) {
destWsUrl = originWsUrl;
} else {
switch (destChainId) {
case '0':
destWsUrl = ROCOCO_ALICE_WS_URL;
chainName = 'Rococo';
break;
case '1000':
destWsUrl = KUSAMA_ASSET_HUB_WS_URL;
chainName = 'Kusama Asset Hub';
break;
case '1836':
destWsUrl = TRAPPIST_WS_URL;
chainName = 'Trappist';
break;
case '4000':
destWsUrl = MOONRIVER_WS_URL;
chainName = 'Moonriver';
break;
}
}

const { api, specName, safeXcmVersion } = await constructApiPromise(originWsUrl);

await api.isReady;
Expand Down Expand Up @@ -139,19 +154,25 @@ const executor = async (testCase: string) => {

const correctlyReceived = verification(assetIds, amounts, destFinalBalance);

for (let i = 0; i < assetIds.length; i++) {
if (correctlyReceived[i][1]) {
console.log('all good');
} else {
console.log('badd');
}
}

await delay(12000);

await originApi.disconnect();
await destinationApi.disconnect();

counter += 1;

updateProgressBar(counter, progressBar);

for (let i = 0; i < assetIds.length; i++) {
results.push([t.test, assetIds[i], chainName, correctlyReceived[i][1]]);
}
}

for (let i = 0; i < results.length; i++) {
testResultLogger(results[i][0], results[i][1], results[i][2], results[i][3]);
}

terminateProgressBar(progressBar, testCase);
};

executor(process.argv[2])
Expand Down
73 changes: 73 additions & 0 deletions e2e-tests/logger.ts
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
import colors from 'ansi-colors';
import chalk from 'chalk';
import * as cliProgress from 'cli-progress';
import { IndividualTest } from 'tests';

const defineTest = (testCase: string): string => {
let test: string = '';

switch (testCase) {
case '--foreign-assets':
test = 'Foreign Assets Transfers';
break;
case '--liquidity-assets':
test = 'Liqudity Tokens Transfers';
break;
case '--local':
test = 'Native Token Transfers';
break;
case '--assets':
test = 'Local Assets Transfers';
break;
}
return test;
};

export const startTestLogger = (testCase: string) => {
const test = defineTest(testCase);

console.log(chalk.yellow(`Initializing tests for ${test}\n`));
};

export const startProgressBar = (testData: IndividualTest[], testCase: string): cliProgress.SingleBar => {
const test = defineTest(testCase);

const coverage: number = testData.length;

const progressBar = new cliProgress.SingleBar({
format:
`\n${test} Test Suite Progress |` + colors.cyan('{bar}') + '| {percentage}% || {value}/{total} tests covered \n',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
});

progressBar.start(coverage, 0);

return progressBar;
};

export const updateProgressBar = (counter: number, progressBar: cliProgress.SingleBar) => {
process.stdout.moveCursor(0, -2);

process.stdout.clearLine(0);

progressBar.increment(counter);
};

export const terminateProgressBar = (progressBar: cliProgress.SingleBar, testCase: string) => {
const test = defineTest(testCase);
console.log(chalk.yellow(`Test Suite for ${test} completed.\n`));

progressBar.stop();
console.log('\n');
};

export const testResultLogger = (testName: string, assetId: string, chainName: string, passed: boolean) => {
const tokenId = assetId === '' ? 'native asset' : `asset ${assetId}`;
if (passed) {
console.log(chalk.green(`Test ${testName} passed for ${chainName}'s ${tokenId} \u2705\n`));
} else {
console.log(chalk.red(`Test ${testName} failed for ${chainName}'s ${tokenId} \u274E\n`));
}
};
2 changes: 0 additions & 2 deletions e2e-tests/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export const verification = (assetIds: string[], amounts: string[], destBalance:
const destInitialBalance: [string, number][] = destBalance.initial;
const destFinalBalance: [string, number][] = destBalance.final;
const correctlyReceived: [string, boolean][] = [];
console.log(destInitialBalance);
console.log(destFinalBalance);

let check = true;
for (let i = 0; i < assetIds.length; i++) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
"packageManager": "[email protected]",
"devDependencies": {
"@substrate/dev": "^0.7.1",
"@types/cli-progress": "^3",
"chalk": "4.1.2",
"cli-progress": "^3.12.0",
"typedoc": "^0.25.4",
"typedoc-plugin-missing-exports": "^1.0.0",
"typedoc-theme-hierarchy": "^4.0.0"
"typedoc-theme-hierarchy": "^4.0.0",
"ansi-colors": "^4.1.3"
},
"dependencies": {
"@polkadot/api": "^10.11.2",
Expand Down
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,10 @@ __metadata:
"@polkadot/api": "npm:^10.11.2"
"@substrate/asset-transfer-api-registry": "npm:^0.2.11"
"@substrate/dev": "npm:^0.7.1"
"@types/cli-progress": "npm:^3"
ansi-colors: "npm:^4.1.3"
chalk: "npm:4.1.2"
cli-progress: "npm:^3.12.0"
typedoc: "npm:^0.25.4"
typedoc-plugin-missing-exports: "npm:^1.0.0"
typedoc-theme-hierarchy: "npm:^4.0.0"
Expand Down Expand Up @@ -1467,6 +1470,15 @@ __metadata:
languageName: node
linkType: hard

"@types/cli-progress@npm:^3":
version: 3.11.5
resolution: "@types/cli-progress@npm:3.11.5"
dependencies:
"@types/node": "npm:*"
checksum: cb19187637b0a9b92219eab8d3d42250f1773328c24cb265d1bc677e3017f512e95e834e4846bcf0964efc232a13f86f7ef01843be804daa5433cc655c375bb3
languageName: node
linkType: hard

"@types/graceful-fs@npm:^4.1.3":
version: 4.1.6
resolution: "@types/graceful-fs@npm:4.1.6"
Expand Down Expand Up @@ -1751,6 +1763,13 @@ __metadata:
languageName: node
linkType: hard

"ansi-colors@npm:^4.1.3":
version: 4.1.3
resolution: "ansi-colors@npm:4.1.3"
checksum: 43d6e2fc7b1c6e4dc373de708ee76311ec2e0433e7e8bd3194e7ff123ea6a747428fc61afdcf5969da5be3a5f0fd054602bec56fc0ebe249ce2fcde6e649e3c2
languageName: node
linkType: hard

"ansi-escapes@npm:^4.2.1":
version: 4.3.2
resolution: "ansi-escapes@npm:4.3.2"
Expand Down Expand Up @@ -2155,6 +2174,15 @@ __metadata:
languageName: node
linkType: hard

"cli-progress@npm:^3.12.0":
version: 3.12.0
resolution: "cli-progress@npm:3.12.0"
dependencies:
string-width: "npm:^4.2.3"
checksum: a6a549919a7461f5e798b18a4a19f83154bab145d3ec73d7f3463a8db8e311388c545ace1105557760a058cc4999b7f28c9d8d24d9783ee2912befb32544d4b8
languageName: node
linkType: hard

"cliui@npm:^8.0.1":
version: 8.0.1
resolution: "cliui@npm:8.0.1"
Expand Down

0 comments on commit 729e799

Please sign in to comment.