1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util/playgrounds';19import {expect} from './eth/util/playgrounds';2021let superuser: IKeyringPair;22let donor: IKeyringPair;23let palletAdmin: IKeyringPair;24let nominal: bigint;25let palletAddress;26let accounts: IKeyringPair[];272829describe('App promotion', () => {30 before(async function () {31 await usingPlaygrounds(async (helper, privateKey) => {32 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);33 superuser = await privateKey('//Alice');34 donor = await privateKey({filename: __filename});35 palletAddress = helper.arrange.calculatePalleteAddress('appstake');36 palletAdmin = await privateKey('//PromotionAdmin');37 const api = helper.getApi();38 await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));39 nominal = helper.balance.getOneTokenNominal();40 await helper.balance.transferToSubstrate(donor, palletAdmin.address, 1000n * nominal);41 await helper.balance.transferToSubstrate(donor, palletAddress, 1000n * nominal);42 accounts = await helper.arrange.createCrowd(100, 1000n, donor); 43 });44 });4546 describe('admin adress', () => {47 itSub('can be set by sudo only', async ({helper}) => {48 const api = helper.getApi();49 const nonAdmin = accounts.pop()!;50 51 await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;52 await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;53 });54 55 itSub('can be any valid CrossAccountId', async ({helper}) => {56 57 58 const api = helper.getApi();59 const account = accounts.pop()!;60 const ethAccount = helper.address.substrateToEth(account.address); 61 62 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;63 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;64 65 66 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});67 await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;68 });69 70 itSub('can be reassigned', async ({helper}) => {71 const api = helper.getApi();72 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];73 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});74 75 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;76 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;77 await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;78 79 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;80 });81 });82});83