1234567891011121314151617import {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({url: import.meta.url});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 50 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 });5354 itSub('can be any valid CrossAccountId', async ({helper}) => {55 56 57 const api = helper.getApi();58 const [account] = await helper.arrange.createAccounts([10n], donor);59 const ethAccount = helper.address.substrateToEth(account.address);60 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;6364 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 });6869 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'});7374 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;7778 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;79 });80 });81});82