--- a/tests/src/app-promotion.test.ts +++ b/tests/src/app-promotion.test.ts @@ -21,7 +21,8 @@ import {DevUniqueHelper} from './util/playgrounds/unique.dev'; import {itEth, expect, SponsoringMode} from './eth/util/playgrounds'; -let alice: IKeyringPair; +let superuser: IKeyringPair; +let donor: IKeyringPair; let palletAdmin: IKeyringPair; let nominal: bigint; const palletAddress = calculatePalleteAddress('appstake'); @@ -37,14 +38,15 @@ before(async function () { await usingPlaygrounds(async (helper, privateKey) => { requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]); - alice = await privateKey('//Alice'); - [palletAdmin] = await helper.arrange.createAccounts([100n], alice); + superuser = await privateKey('//Alice'); + donor = await privateKey({filename: __filename}); + [palletAdmin] = await helper.arrange.createAccounts([100n], donor); const api = helper.getApi(); - await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}))); + await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}))); nominal = helper.balance.getOneTokenNominal(); - await helper.balance.transferToSubstrate(alice, palletAdmin.address, 1000n * nominal); - await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal); - accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests + await helper.balance.transferToSubstrate(donor, palletAdmin.address, 1000n * nominal); + await helper.balance.transferToSubstrate(donor, palletAddress, 1000n * nominal); + accounts = await helper.arrange.createCrowd(100, 1000n, donor); // create accounts-pool to speed up tests }); }); @@ -76,7 +78,7 @@ }); itSub('should allow to create maximum 10 stakes for account', async ({helper}) => { - const [staker] = await helper.arrange.createAccounts([2000n], alice); + const [staker] = await helper.arrange.createAccounts([2000n], donor); for (let i = 0; i < 10; i++) { await helper.staking.stake(staker, 100n * nominal); } @@ -144,7 +146,7 @@ expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // staker can transfer: - await helper.balance.transferToSubstrate(staker, alice.address, 998n * nominal); + await helper.balance.transferToSubstrate(staker, donor.address, 998n * nominal); expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(1n); }); @@ -233,7 +235,7 @@ await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected; // Alice can - await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled; + await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled; }); itSub('can be any valid CrossAccountId', async ({helper}) => { @@ -243,8 +245,8 @@ const account = accounts.pop()!; const ethAccount = helper.address.substrateToEth(account.address); // Alice sets Ethereum address as a sudo. Then Substrate address back... - await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled; - await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled; + await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled; + await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled; // ...It doesn't break anything; const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'}); @@ -256,8 +258,8 @@ const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!]; const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'}); - await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled; - await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled; + await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled; + await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled; await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected; await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled; @@ -269,7 +271,7 @@ await usingPlaygrounds(async (helper) => { const api = helper.getApi(); const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})); - await helper.signTransaction(alice, tx); + await helper.signTransaction(superuser, tx); }); }); @@ -343,7 +345,7 @@ itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => { const api = helper.getApi(); const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0}; - const collectionWithLimits = await helper.nft.mintCollection(alice, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits}); + const collectionWithLimits = await helper.nft.mintCollection(accounts.pop()!, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits}); await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled; expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits); @@ -416,7 +418,7 @@ describe('contract sponsoring', () => { itEth('should set palletes address as a sponsor', async ({helper}) => { - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); @@ -432,7 +434,7 @@ }); itEth('should overwrite sponsoring mode and existed sponsor', async ({helper}) => { - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); @@ -459,7 +461,7 @@ }); itEth('can be overwritten by contract owner', async ({helper}) => { - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); @@ -480,7 +482,7 @@ itEth('can not be set by non admin', async ({helper}) => { const nonAdmin = accounts.pop()!; - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); @@ -499,18 +501,18 @@ itEth('should actually sponsor transactions', async ({helper}) => { // Contract caller - const caller = await helper.eth.createAccountWithBalance(alice, 1000n); + const caller = await helper.eth.createAccountWithBalance(donor, 1000n); const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress); // Deploy flipper - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); // Owner sets to sponsor every tx await contractHelper.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: contractOwner}); await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner}); - await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n); + await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n); // Set promotion to the Flipper await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true); @@ -533,10 +535,10 @@ describe('stopSponsoringContract', () => { itEth('should remove pallet address from contract sponsors', async ({helper}) => { - const caller = await helper.eth.createAccountWithBalance(alice, 1000n); - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const caller = await helper.eth.createAccountWithBalance(donor, 1000n); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); - await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address); + await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner}); @@ -563,7 +565,7 @@ itEth('can not be called by non-admin', async ({helper}) => { const nonAdmin = accounts.pop()!; - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]); @@ -573,7 +575,7 @@ itEth('should not affect a contract which is not sponsored by pallete', async ({helper}) => { const nonAdmin = accounts.pop()!; - const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase(); + const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase(); const flipper = await helper.eth.deployFlipper(contractOwner); const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner); await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled; @@ -679,7 +681,7 @@ itSub.skip('can be paid 1000 rewards in a time', async ({helper}) => { // all other stakes should be unstaked - const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, alice); + const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, donor); // stakers stakes 10 times each for (let i = 0; i < 10; i++) { @@ -690,7 +692,6 @@ }); itSub.skip('can handle 40.000 rewards', async ({helper}) => { - const [donor] = await helper.arrange.createAccounts([7_000_000n], alice); const crowdStakes = async () => { // each account in the crowd stakes 2 times const crowd = await helper.arrange.createCrowd(500, 300n, donor);