difftreelog
Move feedAlices to globalSetup.ts
in: master
4 files changed
tests/globalSetup.tsdiffbeforeafterboth--- a/tests/globalSetup.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import {Pallets, usingPlaygrounds} from './src/util/playgrounds/index';
-
-export async function mochaGlobalSetup() {
- await usingPlaygrounds(async (helper, privateKey) => {
- // Set up App Promotion admin
- const missingPallets = helper.fetchMissingPalletNames([Pallets.AppPromotion]);
- if (missingPallets.length === 0) {
- const superuser = await privateKey('//Alice');
- const palletAddress = helper.arrange.calculatePalleteAddress('appstake');
- const palletAdmin = await privateKey('//PromotionAdmin');
- const api = helper.getApi();
- await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
- const nominal = helper.balance.getOneTokenNominal();
- await helper.balance.transferToSubstrate(superuser, palletAdmin.address, 1000n * nominal);
- await helper.balance.transferToSubstrate(superuser, palletAddress, 1000n * nominal);
- }
- });
-}
tests/package.jsondiffbeforeafterboth21 },21 },22 "mocha": {22 "mocha": {23 "timeout": 9999999,23 "timeout": 9999999,24 "require": ["ts-node/register", "./globalSetup.ts"]24 "require": ["ts-node/register", "./src/util/playgrounds/globalSetup.ts"]25 },25 },26 "scripts": {26 "scripts": {27 "lint": "eslint --ext .ts,.js src/",27 "lint": "eslint --ext .ts,.js src/",28 "fix": "eslint --ext .ts,.js src/ --fix",28 "fix": "eslint --ext .ts,.js src/ --fix",29 "feedAlices": "ts-node ./src/util/playgrounds/feedAlices.ts",302931 "test": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",30 "test": "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'",31 "testSequential": "mocha --timeout 9999999 -r ts-node/register './src/**/*.seqtest.ts'",33 "testStructure": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",32 "testStructure": "mocha --parallel --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",34 "testEth": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",33 "testEth": "mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",35 "testEthNesting": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",34 "testEthNesting": "mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",36 "testEthFractionalizer": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",35 "testEthFractionalizer": "mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",37 "testEthMarketplace": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",36 "testEthMarketplace": "mocha --parallel --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",38 "testEvent": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",37 "testEvent": "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",38 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**test.ts",403941 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",40 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",tests/src/util/playgrounds/feedAlices.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/feedAlices.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-import * as path from 'path';
-import {promises as fs} from 'fs';
-import {usingPlaygrounds} from '.';
-
-async function getFiles(rootPath: string): Promise<string[]> {
- const files = await fs.readdir(rootPath, {withFileTypes: true});
- const filenames: string[] = [];
- for (const entry of files) {
- const res = path.resolve(rootPath, entry.name);
- if (entry.isDirectory()) {
- filenames.push(...await getFiles(res));
- } else {
- filenames.push(res);
- }
- }
- return filenames;
-}
-
-const fundFilenames = async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const oneToken = helper.balance.getOneTokenNominal();
- const alice = await privateKey('//Alice');
- const nonce = await helper.chain.getNonce(alice.address);
- const filenames = await getFiles(path.resolve(__dirname, '../..'));
-
- // batching is actually undesired, it takes away the time while all the transactions actually succeed
- const batchSize = 300;
- let balanceGrantedCounter = 0;
- for (let b = 0; b < filenames.length; b += batchSize) {
- const tx = [];
- let batchBalanceGrantedCounter = 0;
- for (let i = 0; batchBalanceGrantedCounter < batchSize && b + i < filenames.length; i++) {
- const f = filenames[b + i];
- if (!f.endsWith('.test.ts') || f.includes('.outdated')) continue;
- const account = await privateKey({filename: f, ignoreFundsPresence: true});
- const aliceBalance = await helper.balance.getSubstrate(account.address);
-
- if (aliceBalance < 100_000n * oneToken) {
- tx.push(helper.executeExtrinsic(
- alice,
- 'api.tx.balances.transfer',
- [account.address, 1_000_000n * oneToken],
- true,
- {nonce: nonce + balanceGrantedCounter++},
- ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));
- batchBalanceGrantedCounter++;
- }
- }
-
- if(tx.length > 0) {
- console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);
- const result = await Promise.all(tx);
- if (result && result.lastIndexOf(false) > -1) throw new Error('The transactions actually probably succeeded, should check the balances.');
- }
- }
-
- if (balanceGrantedCounter == 0) console.log('No account needs additional funding.');
- });
-};
-
-const fundFilenamesWithRetries = async (retriesLeft: number): Promise<boolean> => {
- if (retriesLeft <= 0) return Promise.resolve(false);
- return fundFilenames()
- .then(() => Promise.resolve(true))
- .catch(e => {
- console.error(e);
- console.error(`Some transactions might have failed. ${retriesLeft > 1 ? 'Retrying...' : 'Something is wrong.'}\n`);
- return fundFilenamesWithRetries(--retriesLeft);
- });
-};
-
-fundFilenamesWithRetries(3).then((result) => process.exit(result ? 0 : 1)).catch(e => {
- console.error(e);
- process.exit(1);
-});
tests/src/util/playgrounds/globalSetup.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/util/playgrounds/globalSetup.ts
@@ -0,0 +1,102 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+import {usingPlaygrounds, Pallets} from './index';
+import * as path from 'path';
+import {promises as fs} from 'fs';
+
+// This file is used in the mocha package.json section
+export async function mochaGlobalSetup() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ try {
+ // 1. Create donors
+ await fundFilenamesWithRetries(3)
+ .then((result) => {
+ if (!result) process.exit(1);
+ });
+
+ // 2. Set up App Promotion admin
+ const missingPallets = helper.fetchMissingPalletNames([Pallets.AppPromotion]);
+ if (missingPallets.length === 0) {
+ const superuser = await privateKey('//Alice');
+ const palletAddress = helper.arrange.calculatePalleteAddress('appstake');
+ const palletAdmin = await privateKey('//PromotionAdmin');
+ const api = helper.getApi();
+ await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
+ const nominal = helper.balance.getOneTokenNominal();
+ await helper.balance.transferToSubstrate(superuser, palletAdmin.address, 1000n * nominal);
+ await helper.balance.transferToSubstrate(superuser, palletAddress, 1000n * nominal);
+ }
+ } catch (error) {
+ console.error(error);
+ process.exit(1);
+ }
+ });
+}
+
+async function getFiles(rootPath: string): Promise<string[]> {
+ const files = await fs.readdir(rootPath, {withFileTypes: true});
+ const filenames: string[] = [];
+ for (const entry of files) {
+ const res = path.resolve(rootPath, entry.name);
+ if (entry.isDirectory()) {
+ filenames.push(...await getFiles(res));
+ } else {
+ filenames.push(res);
+ }
+ }
+ return filenames;
+}
+
+const fundFilenames = async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const oneToken = helper.balance.getOneTokenNominal();
+ const alice = await privateKey('//Alice');
+ const nonce = await helper.chain.getNonce(alice.address);
+ const filenames = await getFiles(path.resolve(__dirname, '../..'));
+
+ // batching is actually undesired, it takes away the time while all the transactions actually succeed
+ const batchSize = 300;
+ let balanceGrantedCounter = 0;
+ for (let b = 0; b < filenames.length; b += batchSize) {
+ const tx = [];
+ let batchBalanceGrantedCounter = 0;
+ for (let i = 0; batchBalanceGrantedCounter < batchSize && b + i < filenames.length; i++) {
+ const f = filenames[b + i];
+ if (!f.endsWith('.test.ts') || f.includes('.outdated')) continue;
+ const account = await privateKey({filename: f, ignoreFundsPresence: true});
+ const aliceBalance = await helper.balance.getSubstrate(account.address);
+
+ if (aliceBalance < 100_000n * oneToken) {
+ tx.push(helper.executeExtrinsic(
+ alice,
+ 'api.tx.balances.transfer',
+ [account.address, 1_000_000n * oneToken],
+ true,
+ {nonce: nonce + balanceGrantedCounter++},
+ ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));
+ batchBalanceGrantedCounter++;
+ }
+ }
+
+ if(tx.length > 0) {
+ console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);
+ const result = await Promise.all(tx);
+ if (result && result.lastIndexOf(false) > -1) throw new Error('The transactions actually probably succeeded, should check the balances.');
+ }
+ }
+
+ if (balanceGrantedCounter == 0) console.log('No account needs additional funding.');
+ });
+};
+
+const fundFilenamesWithRetries = async (retriesLeft: number): Promise<boolean> => {
+ if (retriesLeft <= 0) return Promise.resolve(false);
+ return fundFilenames()
+ .then(() => Promise.resolve(true))
+ .catch(e => {
+ console.error(e);
+ console.error(`Some transactions might have failed. ${retriesLeft > 1 ? 'Retrying...' : 'Something is wrong.'}\n`);
+ return fundFilenamesWithRetries(--retriesLeft);
+ });
+};