difftreelog
tests(util): fix and adapt feed-alices to asynchronisity
in: master
4 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -29,14 +29,14 @@
"feedAlices": "ts-node ./src/util/playgrounds/feedAlices.ts",
"test": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",
+ "testSequential": "yarn feedAlices && mocha --timeout 9999999 -r ts-node/register './src/**/*.seqtest.ts'",
"testStructure": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
"testEth": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",
"testEthNesting": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",
"testEthFractionalizer": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",
"testEthMarketplace": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",
- "testCollision": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
"testEvent": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",
- "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
+ "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**test.ts",
"testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
"testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",
@@ -48,7 +48,7 @@
"testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
"testChangeCollectionOwner": "mocha --timeout 9999999 -r ts-node/register ./**/change-collection-owner.test.ts",
"testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",
- "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",
+ "testConfirmSponsorship": "mocha --timeout 9999999 --parallel -r ts-node/register ./**/confirmSponsorship.test.ts",
"testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
"testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
@@ -78,12 +78,6 @@
"testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
"testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",
"testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
- "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
- "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",
- "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
- "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
- "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
- "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
@@ -97,6 +91,13 @@
"testEthFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/fungible.test.ts",
"testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",
"testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",
+
+ "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
+ "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",
+ "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
+ "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
+ "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
+ "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
"load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
"loadTransfer": "ts-node src/transfer.nload.ts",
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -142,14 +142,14 @@
return account.address;
}
- async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {
+ async createAccountWithBalance(donor: IKeyringPair, amount=100n) {
const account = this.createAccount();
await this.transferBalanceFromSubstrate(donor, account, amount);
return account;
}
- async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {
+ async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=100n, inTokens=true) {
return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));
}
tests/src/util/playgrounds/feedAlices.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import {promises as fs} from 'fs';6import {usingPlaygrounds} from '.';78async function getFiles(rootPath: string): Promise<string[]> {9 const files = await fs.readdir(rootPath, {withFileTypes: true});10 const filenames: string[] = [];11 for (const entry of files) {12 const res = path.resolve(rootPath, entry.name);13 if (entry.isDirectory()) {14 filenames.push(...await getFiles(res));15 } else {16 filenames.push(res);17 }18 }19 return filenames;20}2122const fundFilenames = async () => {23 await usingPlaygrounds(async (helper, privateKey) => {24 const oneToken = helper.balance.getOneTokenNominal();25 const alice = await privateKey('//Alice');26 const nonce = await helper.chain.getNonce(alice.address);27 const filenames = await getFiles(path.resolve(__dirname, '../..'));2829 console.log(`Main Alice address: ${alice.address}, with balance:`, await helper.balance.getSubstrate(alice.address));3031 const batchSize = 20;32 let balanceGrantedCounter = 0;33 for (let b = 0; b < filenames.length; b += batchSize) {34 const tx = [];35 let batchBalanceGrantedCounter = 0;36 for (const f of filenames.slice(b, b + batchSize)) {37 if (!f.endsWith('.test.ts')) continue;38 const account = await privateKey({filename: f});39 const aliceBalance = await helper.balance.getSubstrate(account.address);4041 if (aliceBalance < 5000n * oneToken) {42 tx.push(helper.executeExtrinsic(43 alice, 44 'api.tx.balances.transfer',45 [account.address, 10000n * oneToken],46 true,47 {nonce: nonce + balanceGrantedCounter++},48 ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));49 batchBalanceGrantedCounter++;50 }51 }5253 if(tx.length > 0) {54 console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);55 const result = await Promise.all(tx);56 if (result && result.lastIndexOf(false) > -1) throw new Error('The transactions actually probably succeeded, should check the balances.');57 }58 }5960 if (balanceGrantedCounter == 0) console.log('No account needs additional funding.');61 });62};6364const fundFilenamesWithRetries = async (retriesLeft: number): Promise<boolean> => {65 if (retriesLeft <= 0) return Promise.resolve(false);66 return fundFilenames()67 .then(() => Promise.resolve(true))68 .catch(() => {69 console.error(`Some transactions have failed. ${retriesLeft>=1'Retrying...''Something is wrong.'}`);70 return fundFilenamesWithRetries(--retriesLeft);71 });72};7374fundFilenamesWithRetries(2).then((result) => process.exit(result ? 0 : 1)).catch(e => {75 console.error(e);76 process.exit(1);77});tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -22,8 +22,7 @@
return `//Alice+${getTestHash(filename)}`;
};
-// todo:playgrounds normalize to seed and filename
-export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {
+export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {
const silentConsole = new SilentConsole();
silentConsole.enable();
@@ -32,14 +31,14 @@
try {
await helper.connect(url);
const ss58Format = helper.chain.getChainProperties().ss58Format;
- const privateKey = async (seed: string | {filename: string}) => {
+ const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {
if (typeof seed === 'string') {
return helper.util.fromSeed(seed, ss58Format);
}
else {
const actualSeed = getTestSeed(seed.filename);
let account = helper.util.fromSeed(actualSeed, ss58Format);
- if (await helper.balance.getSubstrate(account.address) == 0n) {
+ if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) == 0n) {
console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);
account = helper.util.fromSeed('//Alice', ss58Format);
}