difftreelog
tests: refactor and adapt some tests for asynchronicity
in: master
14 files changed
tests/src/app-promotion.test.tsdiffbeforeafterboth37 before(async function () {37 before(async function () {38 await usingPlaygrounds(async (helper, privateKey) => {38 await usingPlaygrounds(async (helper, privateKey) => {39 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);39 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);40 alice = await privateKey({filename: __filename});40 alice = await privateKey('//Alice');41 [palletAdmin] = await helper.arrange.createAccounts([100n], alice);41 [palletAdmin] = await helper.arrange.createAccounts([100n], alice);42 const api = helper.getApi();42 const api = helper.getApi();43 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));43 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));557 557 558 // caller payed for call558 // caller payed for call559 expect(1000n * nominal > callerBalance).to.be.true;559 expect(1000n * nominal > callerBalance).to.be.true;560 expect(contractBalanceAfter).to.be.equal(1000n * nominal);560 expect(contractBalanceAfter).to.be.equal(100n * nominal);561 });561 });562 562 563 itEth('can not be called by non-admin', async ({helper}) => {563 itEth('can not be called by non-admin', async ({helper}) => {613 await helper.staking.stake(staker, 200n * nominal);613 await helper.staking.stake(staker, 200n * nominal);614 614 615 // wait rewards are available:615 // wait rewards are available:616 const [_, stake2] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});616 const [_stake1, stake2] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});617 await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stake2.block));617 await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stake2.block));618 618 619 const payoutToStaker = (await helper.admin.payoutStakers(palletAdmin, 100)).find((payout) => payout.staker === staker.address)?.payout;619 const payoutToStaker = (await helper.admin.payoutStakers(palletAdmin, 100)).find((payout) => payout.staker === staker.address)?.payout;tests/src/confirmSponsorship.test.tsdiffbeforeafterboth109 });109 });110110111 itSub('NFT: Sponsoring of transfers is rate limited', async ({helper}) => {111 itSub('NFT: Sponsoring of transfers is rate limited', async ({helper}) => {112 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});112 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {113 sponsorTransferTimeout: 1000,114 }});113 await collection.setSponsor(alice, bob.address);115 await collection.setSponsor(alice, bob.address);114 await collection.confirmSponsorship(bob);116 await collection.confirmSponsorship(bob);115117125 });127 });126128127 itSub('Fungible: Sponsoring is rate limited', async ({helper}) => {129 itSub('Fungible: Sponsoring is rate limited', async ({helper}) => {128 const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});130 const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {131 sponsorTransferTimeout: 1000,132 }});129 await collection.setSponsor(alice, bob.address);133 await collection.setSponsor(alice, bob.address);130 await collection.confirmSponsorship(bob);134 await collection.confirmSponsorship(bob);131135141 });145 });142146143 itSub.ifWithPallets('ReFungible: Sponsoring is rate limited', [Pallets.ReFungible], async ({helper}) => {147 itSub.ifWithPallets('ReFungible: Sponsoring is rate limited', [Pallets.ReFungible], async ({helper}) => {144 const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});148 const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {149 sponsorTransferTimeout: 1000,150 }});145 await collection.setSponsor(alice, bob.address);151 await collection.setSponsor(alice, bob.address);146 await collection.confirmSponsorship(bob);152 await collection.confirmSponsorship(bob);147153tests/src/creditFeesToTreasury.seqtest.tsdiffbeforeafterbothno changes
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterbothno changes
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth9910 before(async () => {10 before(async () => {11 await usingPlaygrounds(async (helper, privateKey) => {11 await usingPlaygrounds(async (helper, privateKey) => {12 donor = privateKey('//Alice');12 donor = await privateKey({filename: __filename});13 [alice] = await helper.arrange.createAccounts([100n], donor);13 nominal = helper.balance.getOneTokenNominal();14 nominal = helper.balance.getOneTokenNominal();14 });15 });15 });16 });1617 17 beforeEach(async () => {18 await usingPlaygrounds(async (helper) => {19 [alice] = await helper.arrange.createAccounts([1000n], donor);20 });21 });2223 itEth('sponsors mint transactions', async ({helper}) => {18 itEth('sponsors mint transactions', async ({helper}) => {24 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});19 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth262627 before(async () => {27 before(async () => {28 await usingPlaygrounds(async (_helper, privateKey) => {28 await usingPlaygrounds(async (_helper, privateKey) => {29 donor = privateKey('//Alice');29 donor = await privateKey({filename: __filename});30 });30 });31 });31 });323233 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {33 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);34 const owner = await helper.eth.createAccountWithBalance(donor);35 const flipper = await helper.eth.deployFlipper(owner);35 const flipper = await helper.eth.deployFlipper(owner);36 const helpers = helper.ethNativeContract.contractHelpers(owner);36 const helpers = helper.ethNativeContract.contractHelpers(owner);517517518 before(async () => {518 before(async () => {519 await usingEthPlaygrounds(async (helper, privateKey) => {519 await usingEthPlaygrounds(async (helper, privateKey) => {520 donor = privateKey('//Alice');520 donor = await privateKey({filename: __filename});521 [alice] = await helper.arrange.createAccounts([100n], donor);521 DEFAULT_GAS = helper.eth.DEFAULT_GAS;522 DEFAULT_GAS = helper.eth.DEFAULT_GAS;522 });523 });523 });524 });524525 beforeEach(async () => {526 await usingPlaygrounds(async (helper) => {527 [alice] = await helper.arrange.createAccounts([1000n], donor);528 });529 });530525531 let testContract: CompiledContract;526 let testContract: CompiledContract;532 584 expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);577 expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);585 });578 });586579587 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {580 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper}) => {588 const owner = await helper.eth.createAccountWithBalance(donor);581 const owner = await helper.eth.createAccountWithBalance(donor);589 const sponsor = await helper.eth.createAccountWithBalance(donor);582 const sponsor = await helper.eth.createAccountWithBalance(donor);590 const helpers = helper.ethNativeContract.contractHelpers(owner);583 const helpers = helper.ethNativeContract.contractHelpers(owner);tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth35 const description = 'Some description';35 const description = 'Some description';36 const prefix = 'token prefix';36 const prefix = 'token prefix';373738 // todo:playgrounds this might fail when in async environment.39 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;40 const {collectionId} = await helper.eth.createNonfungibleCollection(owner, name, description, prefix);38 const {collectionId} = await helper.eth.createNonfungibleCollection(owner, name, description, prefix);41 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;4243 const collection = helper.nft.getCollectionObject(collectionId);44 const data = (await collection.getData())!;39 const data = (await helper.rft.getData(collectionId))!;45 40 46 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);47 expect(collectionId).to.be.eq(collectionCountAfter);48 expect(data.name).to.be.eq(name);41 expect(data.name).to.be.eq(name);49 expect(data.description).to.be.eq(description);42 expect(data.description).to.be.eq(description);50 expect(data.raw.tokenPrefix).to.be.eq(prefix);43 expect(data.raw.tokenPrefix).to.be.eq(prefix);51 expect(data.raw.mode).to.be.eq('NFT');44 expect(data.raw.mode).to.be.eq('NFT');52 });45 });534654 // todo:playgrounds this test will fail when in async environment.47 // this test will occasionally fail when in async environment.55 itEth('Check collection address exist', async ({helper}) => {48 itEth.skip('Check collection address exist', async ({helper}) => {56 const owner = await helper.eth.createAccountWithBalance(donor);49 const owner = await helper.eth.createAccountWithBalance(donor);575058 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;51 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth37 const description = 'Some description';37 const description = 'Some description';38 const prefix = 'token prefix';38 const prefix = 'token prefix';39 39 40 // todo:playgrounds this might fail when in async environment.41 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42 const {collectionId} = await helper.eth.createRefungibleCollection(owner, name, description, prefix);40 const {collectionId} = await helper.eth.createRefungibleCollection(owner, name, description, prefix);43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;44 45 const data = (await helper.rft.getData(collectionId))!;41 const data = (await helper.rft.getData(collectionId))!;464247 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);48 expect(collectionId).to.be.eq(collectionCountAfter);49 expect(data.name).to.be.eq(name);43 expect(data.name).to.be.eq(name);50 expect(data.description).to.be.eq(description);44 expect(data.description).to.be.eq(description);51 expect(data.raw.tokenPrefix).to.be.eq(prefix);45 expect(data.raw.tokenPrefix).to.be.eq(prefix);52 expect(data.raw.mode).to.be.eq('ReFungible');46 expect(data.raw.mode).to.be.eq('ReFungible');53 });47 });5448 55 // todo:playgrounds this test will fail when in async environment.49 // this test will occasionally fail when in async environment.56 itEth('Check collection address exist', async ({helper}) => {50 itEth.skip('Check collection address exist', async ({helper}) => {57 const owner = await helper.eth.createAccountWithBalance(donor);51 const owner = await helper.eth.createAccountWithBalance(donor);585259 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;53 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {usingPlaygrounds} from './../../util/playgrounds/index';18import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';19import {readFile} from 'fs/promises';18import {readFile} from 'fs/promises';20import {itEth, expect, SponsoringMode} from '../util/playgrounds';19import {itEth, usingEthPlaygrounds, expect, SponsoringMode} from '../util/playgrounds';212022describe('Matcher contract usage', () => {21describe('Matcher contract usage', () => {23 const PRICE = 2000n;22 const PRICE = 2000n;29 let sellerMirror: string;28 let sellerMirror: string;302931 before(async () => {30 before(async () => {32 await usingPlaygrounds(async (_helper, privateKey) => {31 await usingEthPlaygrounds(async (_helper, privateKey) => {33 donor = privateKey('//Alice');32 donor = await privateKey({filename: __filename});34 }); 33 }); 35 });34 });363537 beforeEach(async () => {36 beforeEach(async () => {38 await usingPlaygrounds(async (helper, privateKey) => {37 await usingEthPlaygrounds(async (helper, privateKey) => {39 [alice] = await helper.arrange.createAccounts([10000n], donor);38 [alice] = await helper.arrange.createAccounts([1000n], donor);40 aliceMirror = helper.address.substrateToEth(alice.address).toLowerCase();39 aliceMirror = helper.address.substrateToEth(alice.address).toLowerCase();41 aliceDoubleMirror = helper.address.ethToSubstrate(aliceMirror);40 aliceDoubleMirror = helper.address.ethToSubstrate(aliceMirror);42 seller = privateKey(`//Seller/${Date.now()}`);41 seller = await privateKey(`//Seller/${Date.now()}`);43 sellerMirror = helper.address.substrateToEth(seller.address).toLowerCase();42 sellerMirror = helper.address.substrateToEth(seller.address).toLowerCase();444345 await helper.balance.transferToSubstrate(donor, aliceDoubleMirror, 10_000_000_000_000_000_000n);44 await helper.balance.transferToSubstrate(donor, aliceDoubleMirror, 10_000_000_000_000_000_000n);tests/src/eth/sponsoring.test.tsdiffbeforeafterboth22 let donor: IKeyringPair;22 let donor: IKeyringPair;232324 before(async () => {24 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {25 await usingPlaygrounds(async (_helper, privateKey) => {26 donor = privateKey('//Alice');26 donor = await privateKey({filename: __filename});27 });27 });28 });28 });2929tests/src/nesting/collectionProperties.test.tsdiffbeforeafterbothno changes
tests/src/nesting/properties.test.tsdiffbeforeafterbothno changes
tests/src/nesting/propertyPermissions.test.tsdiffbeforeafterbothno changes
tests/src/nesting/tokenProperties.test.tsdiffbeforeafterbothno changes