git.delta.rocks / unique-network / refs/commits / 23067ec51dc9

difftreelog

tests: adjust minimum donor fund structure + fix app-promotion.seqtest's 'after' if the pallet is not present

Fahrrader2022-10-13parent: #02e004a.patch.diff
in: master

3 files changed

modifiedtests/src/app-promotion.seqtest.tsdiffbeforeafterboth
before · tests/src/app-promotion.seqtest.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util';19import {expect} from './eth/util';2021let superuser: IKeyringPair;22let donor: IKeyringPair;23let palletAdmin: IKeyringPair;2425describe('App promotion', () => {26  before(async function () {27    await usingPlaygrounds(async (helper, privateKey) => {28      requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);29      superuser = await privateKey('//Alice');30      donor = await privateKey({filename: __filename});31      palletAdmin = await privateKey('//PromotionAdmin');32      const api = helper.getApi();33      await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));34    });35  });3637  after(async () => {38    await usingPlaygrounds(async (helper) => {39      const api = helper.getApi();40      await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));41    });42  });4344  describe('admin adress', () => {45    itSub('can be set by sudo only', async ({helper}) => {46      const api = helper.getApi();47      const [nonAdmin] = await helper.arrange.createAccounts([10n], donor);48      // nonAdmin can not set admin not from himself nor as a sudo49      await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;50      await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;51    });52    53    itSub('can be any valid CrossAccountId', async ({helper}) => {54      // We are not going to set an eth address as a sponsor,55      // but we do want to check, it doesn't break anything;56      const api = helper.getApi();57      const [account] = await helper.arrange.createAccounts([10n], donor);58      const ethAccount = helper.address.substrateToEth(account.address); 59      // Alice sets Ethereum address as a sudo. Then Substrate address back...60      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;61      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;62        63      // ...It doesn't break anything;64      const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});65      await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;66    });67  68    itSub('can be reassigned', async ({helper}) => {69      const api = helper.getApi();70      const [oldAdmin, newAdmin, collectionOwner] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);71      const collection  = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});72        73      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;74      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;75      await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;76        77      await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;78    });79  });80});81
after · tests/src/app-promotion.seqtest.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util';19import {expect} from './eth/util';2021let superuser: IKeyringPair;22let donor: IKeyringPair;23let palletAdmin: IKeyringPair;2425describe('App promotion', () => {26  before(async function () {27    await usingPlaygrounds(async (helper, privateKey) => {28      requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);29      superuser = await privateKey('//Alice');30      donor = await privateKey({filename: __filename});31      palletAdmin = await privateKey('//PromotionAdmin');32      const api = helper.getApi();33      await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));34    });35  });3637  after(async function () {38    await usingPlaygrounds(async (helper) => {39      if (helper.fetchMissingPalletNames([Pallets.AppPromotion]).length != 0) return;40      const api = helper.getApi();41      await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));42    });43  });4445  describe('admin adress', () => {46    itSub('can be set by sudo only', async ({helper}) => {47      const api = helper.getApi();48      const [nonAdmin] = await helper.arrange.createAccounts([10n], donor);49      // nonAdmin can not set admin not from himself nor as a sudo50      await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;51      await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;52    });53    54    itSub('can be any valid CrossAccountId', async ({helper}) => {55      // We are not going to set an eth address as a sponsor,56      // but we do want to check, it doesn't break anything;57      const api = helper.getApi();58      const [account] = await helper.arrange.createAccounts([10n], donor);59      const ethAccount = helper.address.substrateToEth(account.address); 60      // Alice sets Ethereum address as a sudo. Then Substrate address back...61      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;62      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;63        64      // ...It doesn't break anything;65      const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});66      await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;67    });68  69    itSub('can be reassigned', async ({helper}) => {70      const api = helper.getApi();71      const [oldAdmin, newAdmin, collectionOwner] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);72      const collection  = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});73        74      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;75      await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;76      await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;77        78      await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;79    });80  });81});82
modifiedtests/src/util/globalSetup.tsdiffbeforeafterboth
--- a/tests/src/util/globalSetup.ts
+++ b/tests/src/util/globalSetup.ts
@@ -1,7 +1,7 @@
 // Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
 // SPDX-License-Identifier: Apache-2.0
 
-import {usingPlaygrounds, Pallets} from './index';
+import {usingPlaygrounds, Pallets, DONOR_FUNDING, MINIMUM_DONOR_FUND} from './index';
 import * as path from 'path';
 import {promises as fs} from 'fs';
 
@@ -67,11 +67,11 @@
         const account = await privateKey({filename: f, ignoreFundsPresence: true});
         const aliceBalance = await helper.balance.getSubstrate(account.address);
 
-        if (aliceBalance < 100_000n * oneToken) {
+        if (aliceBalance < MINIMUM_DONOR_FUND * oneToken) {
           tx.push(helper.executeExtrinsic(
             alice, 
             'api.tx.balances.transfer',
-            [account.address, 1_000_000n * oneToken],
+            [account.address, DONOR_FUNDING * oneToken],
             true,
             {nonce: nonce + balanceGrantedCounter++},
           ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));
modifiedtests/src/util/index.tsdiffbeforeafterboth
--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -38,7 +38,7 @@
       else {
         const actualSeed = getTestSeed(seed.filename);
         let account = helper.util.fromSeed(actualSeed, ss58Format);
-        if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) == 0n) {
+        if (!seed.ignoreFundsPresence && await helper.balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND) {
           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);
         }
@@ -53,6 +53,9 @@
   }
 };
 
+export const MINIMUM_DONOR_FUND = 100_000n;
+export const DONOR_FUNDING = 1_000_000n;
+
 export enum Pallets {
   Inflation = 'inflation',
   RmrkCore = 'rmrkcore',