difftreelog
tests(util): fix and adapt feed-alices to asynchronisity
in: master
4 files changed
tests/package.jsondiffbeforeafterboth29 "feedAlices": "ts-node ./src/util/playgrounds/feedAlices.ts",29 "feedAlices": "ts-node ./src/util/playgrounds/feedAlices.ts",303031 "test": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",31 "test": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",32 "testSequential": "yarn feedAlices && mocha --timeout 9999999 -r ts-node/register './src/**/*.seqtest.ts'",32 "testStructure": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",33 "testStructure": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",33 "testEth": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",34 "testEth": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",34 "testEthNesting": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",35 "testEthNesting": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",35 "testEthFractionalizer": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",36 "testEthFractionalizer": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",36 "testEthMarketplace": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",37 "testEthMarketplace": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",37 "testCollision": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",38 "testEvent": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",38 "testEvent": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",39 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",39 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**test.ts",404041 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",41 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",42 "testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",42 "testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",48 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",48 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",49 "testChangeCollectionOwner": "mocha --timeout 9999999 -r ts-node/register ./**/change-collection-owner.test.ts",49 "testChangeCollectionOwner": "mocha --timeout 9999999 -r ts-node/register ./**/change-collection-owner.test.ts",50 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",50 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",51 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",51 "testConfirmSponsorship": "mocha --timeout 9999999 --parallel -r ts-node/register ./**/confirmSponsorship.test.ts",52 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",52 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",53 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",53 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",54 "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",54 "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",78 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",78 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",79 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",79 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",80 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",80 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",81 "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",82 "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",83 "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",84 "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",85 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",86 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",87 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",81 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",88 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",82 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",89 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",83 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",98 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",92 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",99 "testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",93 "testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",94 95 "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",96 "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",97 "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",98 "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",99 "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",100 "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",100101101 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",102 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",102 "loadTransfer": "ts-node src/transfer.nload.ts",103 "loadTransfer": "ts-node src/transfer.nload.ts",tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth142 return account.address;142 return account.address;143 }143 }144144145 async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {145 async createAccountWithBalance(donor: IKeyringPair, amount=100n) {146 const account = this.createAccount();146 const account = this.createAccount();147 await this.transferBalanceFromSubstrate(donor, account, amount);147 await this.transferBalanceFromSubstrate(donor, account, amount);148 148 149 return account;149 return account;150 }150 }151151152 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {152 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=100n, inTokens=true) {153 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));153 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));154 }154 }155 155 tests/src/util/playgrounds/feedAlices.tsdiffbeforeafterboth26 const nonce = await helper.chain.getNonce(alice.address);26 const nonce = await helper.chain.getNonce(alice.address);27 const filenames = await getFiles(path.resolve(__dirname, '../..'));27 const filenames = await getFiles(path.resolve(__dirname, '../..'));282829 console.log(`Main Alice address: ${alice.address}, with balance:`, await helper.balance.getSubstrate(alice.address));29 // batching is actually undesired, it takes away the time while all the transactions actually succeed3031 const batchSize = 20;30 const batchSize = 300;32 let balanceGrantedCounter = 0;31 let balanceGrantedCounter = 0;33 for (let b = 0; b < filenames.length; b += batchSize) {32 for (let b = 0; b < filenames.length; b += batchSize) {34 const tx = [];33 const tx = [];35 let batchBalanceGrantedCounter = 0;34 let batchBalanceGrantedCounter = 0;36 for (const f of filenames.slice(b, b + batchSize)) {35 for (let i = 0; batchBalanceGrantedCounter < batchSize && b + i < filenames.length; i++) {36 const f = filenames[b + i];37 if (!f.endsWith('.test.ts')) continue;37 if (!f.endsWith('.test.ts') || f.includes('.outdated')) continue;38 const account = await privateKey({filename: f});38 const account = await privateKey({filename: f, ignoreFundsPresence: true});39 const aliceBalance = await helper.balance.getSubstrate(account.address);39 const aliceBalance = await helper.balance.getSubstrate(account.address);404041 if (aliceBalance < 5000n * oneToken) {41 if (aliceBalance < 7500n * oneToken) {42 tx.push(helper.executeExtrinsic(42 tx.push(helper.executeExtrinsic(43 alice, 43 alice, 44 'api.tx.balances.transfer',44 'api.tx.balances.transfer',45 [account.address, 10000n * oneToken],45 [account.address, 15000n * oneToken],46 true,46 true,47 {nonce: nonce + balanceGrantedCounter++},47 {nonce: nonce + balanceGrantedCounter++},48 ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));48 ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));49 batchBalanceGrantedCounter++;49 batchBalanceGrantedCounter++;50 }50 }51 }51 }525253 if(tx.length > 0) {53 if(tx.length > 0) {54 console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);54 console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);65 if (retriesLeft <= 0) return Promise.resolve(false);65 if (retriesLeft <= 0) return Promise.resolve(false);66 return fundFilenames()66 return fundFilenames()67 .then(() => Promise.resolve(true))67 .then(() => Promise.resolve(true))68 .catch(() => {68 .catch(e => {69 console.error(e);69 console.error(`Some transactions have failed. ${retriesLeft >= 1 ? 'Retrying...' : 'Something is wrong.'}`);70 console.error(`Some transactions might have failed. ${retriesLeft > 1 ? 'Retrying...' : 'Something is wrong.'}\n`);70 return fundFilenamesWithRetries(--retriesLeft);71 return fundFilenamesWithRetries(--retriesLeft);71 });72 });72};73};737474fundFilenamesWithRetries(2).then((result) => process.exit(result ? 0 : 1)).catch(e => {75fundFilenamesWithRetries(3).then((result) => process.exit(result ? 0 : 1)).catch(e => {75 console.error(e);76 console.error(e);76 process.exit(1);77 process.exit(1);77});78});tests/src/util/playgrounds/index.tsdiffbeforeafterboth22 return `//Alice+${getTestHash(filename)}`;22 return `//Alice+${getTestHash(filename)}`;23};23};242425// todo:playgrounds normalize to seed and filename26export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {25export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {27 const silentConsole = new SilentConsole();26 const silentConsole = new SilentConsole();28 silentConsole.enable();27 silentConsole.enable();292832 try {31 try {33 await helper.connect(url);32 await helper.connect(url);34 const ss58Format = helper.chain.getChainProperties().ss58Format;33 const ss58Format = helper.chain.getChainProperties().ss58Format;35 const privateKey = async (seed: string | {filename: string}) => {34 const privateKey = async (seed: string | {filename: string, ignoreFundsPresence?: boolean}) => {36 if (typeof seed === 'string') {35 if (typeof seed === 'string') {37 return helper.util.fromSeed(seed, ss58Format);36 return helper.util.fromSeed(seed, ss58Format);38 }37 }39 else {38 else {40 const actualSeed = getTestSeed(seed.filename);39 const actualSeed = getTestSeed(seed.filename);41 let account = helper.util.fromSeed(actualSeed, ss58Format);40 let account = helper.util.fromSeed(actualSeed, ss58Format);42 if (await helper.balance.getSubstrate(account.address) == 0n) {41 if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) == 0n) {43 console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);42 console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);44 account = helper.util.fromSeed('//Alice', ss58Format);43 account = helper.util.fromSeed('//Alice', ss58Format);45 }44 }