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

difftreelog

Add donor to app-promotion

Maksandre2022-10-10parent: #797fec6.patch.diff
in: master
Rename alice -> superuser
Use donor for account creation instead of superuser

1 file changed

modifiedtests/src/app-promotion.test.tsdiffbeforeafterboth
21import {DevUniqueHelper} from './util/playgrounds/unique.dev';21import {DevUniqueHelper} from './util/playgrounds/unique.dev';
22import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';22import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';
2323
24let alice: IKeyringPair;24let superuser: IKeyringPair;
25let donor: IKeyringPair;
25let palletAdmin: IKeyringPair;26let palletAdmin: IKeyringPair;
26let nominal: bigint;27let nominal: bigint;
27const palletAddress = calculatePalleteAddress('appstake');28const palletAddress = calculatePalleteAddress('appstake');
37 before(async function () {38 before(async function () {
38 await usingPlaygrounds(async (helper, privateKey) => {39 await usingPlaygrounds(async (helper, privateKey) => {
39 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);40 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);
40 alice = await privateKey('//Alice');41 superuser = await privateKey('//Alice');
42 donor = await privateKey({filename: __filename});
41 [palletAdmin] = await helper.arrange.createAccounts([100n], alice);43 [palletAdmin] = await helper.arrange.createAccounts([100n], donor);
42 const api = helper.getApi();44 const api = helper.getApi();
43 await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));45 await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
44 nominal = helper.balance.getOneTokenNominal();46 nominal = helper.balance.getOneTokenNominal();
45 await helper.balance.transferToSubstrate(alice, palletAdmin.address, 1000n * nominal);47 await helper.balance.transferToSubstrate(donor, palletAdmin.address, 1000n * nominal);
46 await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal);48 await helper.balance.transferToSubstrate(donor, palletAddress, 1000n * nominal);
47 accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests49 accounts = await helper.arrange.createCrowd(100, 1000n, donor); // create accounts-pool to speed up tests
48 });50 });
49 });51 });
5052
76 });78 });
77 79
78 itSub('should allow to create maximum 10 stakes for account', async ({helper}) => {80 itSub('should allow to create maximum 10 stakes for account', async ({helper}) => {
79 const [staker] = await helper.arrange.createAccounts([2000n], alice);81 const [staker] = await helper.arrange.createAccounts([2000n], donor);
80 for (let i = 0; i < 10; i++) {82 for (let i = 0; i < 10; i++) {
81 await helper.staking.stake(staker, 100n * nominal);83 await helper.staking.stake(staker, 100n * nominal);
82 }84 }
144 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n);146 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n);
145 147
146 // staker can transfer:148 // staker can transfer:
147 await helper.balance.transferToSubstrate(staker, alice.address, 998n * nominal);149 await helper.balance.transferToSubstrate(staker, donor.address, 998n * nominal);
148 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(1n);150 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(1n);
149 });151 });
150 152
233 await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;235 await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;
234 236
235 // Alice can237 // Alice can
236 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;238 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
237 });239 });
238 240
239 itSub('can be any valid CrossAccountId', async ({helper}) => {241 itSub('can be any valid CrossAccountId', async ({helper}) => {
243 const account = accounts.pop()!;245 const account = accounts.pop()!;
244 const ethAccount = helper.address.substrateToEth(account.address); 246 const ethAccount = helper.address.substrateToEth(account.address);
245 // Alice sets Ethereum address as a sudo. Then Substrate address back...247 // Alice sets Ethereum address as a sudo. Then Substrate address back...
246 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;248 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;
247 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;249 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
248 250
249 // ...It doesn't break anything;251 // ...It doesn't break anything;
250 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});252 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
256 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];258 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
257 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});259 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
258 260
259 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;261 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;
260 await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;262 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;
261 await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;263 await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
262 264
263 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;265 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;
269 await usingPlaygrounds(async (helper) => {271 await usingPlaygrounds(async (helper) => {
270 const api = helper.getApi();272 const api = helper.getApi();
271 const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));273 const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));
272 await helper.signTransaction(alice, tx);274 await helper.signTransaction(superuser, tx);
273 });275 });
274 });276 });
275 277
343 itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => {345 itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => {
344 const api = helper.getApi();346 const api = helper.getApi();
345 const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0};347 const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0};
346 const collectionWithLimits = await helper.nft.mintCollection(alice, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});348 const collectionWithLimits = await helper.nft.mintCollection(accounts.pop()!, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});
347 349
348 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled;350 await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled;
349 expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits);351 expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits);
416 418
417 describe('contract sponsoring', () => {419 describe('contract sponsoring', () => {
418 itEth('should set palletes address as a sponsor', async ({helper}) => {420 itEth('should set palletes address as a sponsor', async ({helper}) => {
419 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();421 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
420 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);422 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
421 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);423 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
422 424
432 });434 });
433 435
434 itEth('should overwrite sponsoring mode and existed sponsor', async ({helper}) => {436 itEth('should overwrite sponsoring mode and existed sponsor', async ({helper}) => {
435 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();437 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
436 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);438 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
437 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);439 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
438 440
459 });461 });
460 462
461 itEth('can be overwritten by contract owner', async ({helper}) => {463 itEth('can be overwritten by contract owner', async ({helper}) => {
462 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();464 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
463 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);465 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
464 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);466 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
465 467
480 482
481 itEth('can not be set by non admin', async ({helper}) => {483 itEth('can not be set by non admin', async ({helper}) => {
482 const nonAdmin = accounts.pop()!;484 const nonAdmin = accounts.pop()!;
483 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();485 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
484 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);486 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
485 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);487 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
486 488
499 501
500 itEth('should actually sponsor transactions', async ({helper}) => {502 itEth('should actually sponsor transactions', async ({helper}) => {
501 // Contract caller503 // Contract caller
502 const caller = await helper.eth.createAccountWithBalance(alice, 1000n);504 const caller = await helper.eth.createAccountWithBalance(donor, 1000n);
503 const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress);505 const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress);
504 506
505 // Deploy flipper507 // Deploy flipper
506 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();508 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
507 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);509 const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
508 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);510 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
509 511
510 // Owner sets to sponsor every tx512 // Owner sets to sponsor every tx
511 await contractHelper.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: contractOwner});513 await contractHelper.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: contractOwner});
512 await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});514 await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});
513 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);515 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);
514 516
515 // Set promotion to the Flipper517 // Set promotion to the Flipper
516 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true);518 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true);
533 535
534 describe('stopSponsoringContract', () => { 536 describe('stopSponsoringContract', () => {
535 itEth('should remove pallet address from contract sponsors', async ({helper}) => {537 itEth('should remove pallet address from contract sponsors', async ({helper}) => {
536 const caller = await helper.eth.createAccountWithBalance(alice, 1000n);538 const caller = await helper.eth.createAccountWithBalance(donor, 1000n);
537 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();539 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
538 const flipper = await helper.eth.deployFlipper(contractOwner);540 const flipper = await helper.eth.deployFlipper(contractOwner);
539 await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);541 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
540 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);542 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
541 543
542 await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});544 await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});
563 565
564 itEth('can not be called by non-admin', async ({helper}) => {566 itEth('can not be called by non-admin', async ({helper}) => {
565 const nonAdmin = accounts.pop()!;567 const nonAdmin = accounts.pop()!;
566 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();568 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
567 const flipper = await helper.eth.deployFlipper(contractOwner);569 const flipper = await helper.eth.deployFlipper(contractOwner);
568 570
569 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]);571 await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]);
573 575
574 itEth('should not affect a contract which is not sponsored by pallete', async ({helper}) => {576 itEth('should not affect a contract which is not sponsored by pallete', async ({helper}) => {
575 const nonAdmin = accounts.pop()!;577 const nonAdmin = accounts.pop()!;
576 const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();578 const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
577 const flipper = await helper.eth.deployFlipper(contractOwner);579 const flipper = await helper.eth.deployFlipper(contractOwner);
578 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);580 const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
579 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled;581 await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled;
679 681
680 itSub.skip('can be paid 1000 rewards in a time', async ({helper}) => {682 itSub.skip('can be paid 1000 rewards in a time', async ({helper}) => {
681 // all other stakes should be unstaked683 // all other stakes should be unstaked
682 const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, alice);684 const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, donor);
683 685
684 // stakers stakes 10 times each686 // stakers stakes 10 times each
685 for (let i = 0; i < 10; i++) {687 for (let i = 0; i < 10; i++) {
690 });692 });
691 693
692 itSub.skip('can handle 40.000 rewards', async ({helper}) => {694 itSub.skip('can handle 40.000 rewards', async ({helper}) => {
693 const [donor] = await helper.arrange.createAccounts([7_000_000n], alice);
694 const crowdStakes = async () => {695 const crowdStakes = async () => {
695 // each account in the crowd stakes 2 times696 // each account in the crowd stakes 2 times
696 const crowd = await helper.arrange.createCrowd(500, 300n, donor);697 const crowd = await helper.arrange.createCrowd(500, 300n, donor);