git.delta.rocks / unique-network / refs/commits / d1851d8ede93

difftreelog

tests(util): fix and adapt feed-alices to asynchronisity

Fahrrader2022-10-07parent: #add44eb.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
before · tests/package.json
1{2  "name": "unique-tests",3  "version": "1.0.0",4  "description": "Unique Chain Tests",5  "main": "",6  "devDependencies": {7    "@polkadot/ts": "0.4.22",8    "@polkadot/typegen": "9.2.2",9    "@types/chai": "^4.3.1",10    "@types/chai-as-promised": "^7.1.5",11    "@types/chai-like": "^1.1.1",12    "@types/mocha": "^9.1.1",13    "@types/node": "^17.0.35",14    "@typescript-eslint/eslint-plugin": "^5.26.0",15    "@typescript-eslint/parser": "^5.26.0",16    "chai": "^4.3.6",17    "eslint": "^8.16.0",18    "mocha": "^10.0.0",19    "ts-node": "^10.8.0",20    "typescript": "^4.7.2"21  },22  "mocha": {23    "timeout": 9999999,24    "require": "ts-node/register"25  },26  "scripts": {27    "lint": "eslint --ext .ts,.js src/",28    "fix": "eslint --ext .ts,.js src/ --fix",29    "feedAlices": "ts-node ./src/util/playgrounds/feedAlices.ts",3031    "test": "yarn feedAlices && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",32    "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    "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    "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",39    "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",4041    "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",43    "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",44    "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",45    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",46    "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",47    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.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",50    "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",51    "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.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",54    "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",55    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",56    "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",57    "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",58    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",59    "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",60    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",61    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",62    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",63    "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",64    "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",65    "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",66    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",67    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",68    "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",69    "testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",70    "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",71    "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",72    "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",73    "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",74    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",75    "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",76    "testNextSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/nextSponsoring.test.ts",77    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.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",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",88    "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",89    "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",90    "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",91    "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",92    "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",93    "testEthNFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/nonFungible.test.ts",94    "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",95    "testEthRFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/reFungible.test.ts ./**/eth/reFungibleToken.test.ts",96    "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",97    "testEthFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/fungible.test.ts",98    "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",99    "testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",100101    "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",102    "loadTransfer": "ts-node src/transfer.nload.ts",103    104    "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",105    "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",106    "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",107    "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"108  },109  "author": "",110  "license": "SEE LICENSE IN ../LICENSE",111  "homepage": "",112  "dependencies": {113    "@polkadot/api": "9.2.2",114    "@polkadot/api-contract": "9.2.2",115    "@polkadot/util-crypto": "10.1.7",116    "bignumber.js": "^9.0.2",117    "chai-as-promised": "^7.1.1",118    "chai-like": "^1.1.1",119    "find-process": "^1.4.7",120    "solc": "0.8.14-fixed",121    "web3": "^1.7.3"122  },123  "standard": {124    "globals": [125      "it",126      "assert",127      "beforeEach",128      "afterEach",129      "describe",130      "contract",131      "artifacts"132    ]133  },134  "resolutions": {135    "simple-get": "^4.0.1"136  }137}
modifiedtests/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));
   }
   
modifiedtests/src/util/playgrounds/feedAlices.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/feedAlices.ts
+++ b/tests/src/util/playgrounds/feedAlices.ts
@@ -26,23 +26,23 @@
     const nonce = await helper.chain.getNonce(alice.address);
     const filenames = await getFiles(path.resolve(__dirname, '../..'));
 
-    console.log(`Main Alice address: ${alice.address}, with balance:`, await helper.balance.getSubstrate(alice.address));
-
-    const batchSize = 20;
+    // 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 (const f of filenames.slice(b, b + batchSize)) {
-        if (!f.endsWith('.test.ts')) continue;
-        const account = await privateKey({filename: f});
+      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 < 5000n * oneToken) {
+        if (aliceBalance < 7500n * oneToken) {
           tx.push(helper.executeExtrinsic(
             alice, 
             'api.tx.balances.transfer',
-            [account.address, 10000n * oneToken],
+            [account.address, 15000n * oneToken],
             true,
             {nonce: nonce + balanceGrantedCounter++},
           ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));
@@ -65,13 +65,14 @@
   if (retriesLeft <= 0) return Promise.resolve(false);
   return fundFilenames()
     .then(() => Promise.resolve(true))
-    .catch(() => {
-      console.error(`Some transactions have failed. ${retriesLeft >= 1 ? 'Retrying...' : 'Something is wrong.'}`);
+    .catch(e => {
+      console.error(e);
+      console.error(`Some transactions might have failed. ${retriesLeft > 1 ? 'Retrying...' : 'Something is wrong.'}\n`);
       return fundFilenamesWithRetries(--retriesLeft);
     });
 };
 
-fundFilenamesWithRetries(2).then((result) => process.exit(result ? 0 : 1)).catch(e => {
+fundFilenamesWithRetries(3).then((result) => process.exit(result ? 0 : 1)).catch(e => {
   console.error(e);
   process.exit(1);
 });
modifiedtests/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);
         }