difftreelog
Split promotion tests to sequential and parallel
in: master
- add globalSetup script to set app promotion admin - move calculatePalleteAddress helper to DevUniqueHelper
5 files changed
tests/globalSetup.tsdiffbeforeafterbothno changes
tests/package.jsondiffbeforeafterboth21 },21 },22 "mocha": {22 "mocha": {23 "timeout": 9999999,23 "timeout": 9999999,24 "require": "ts-node/register"24 "require": ["ts-node/register", "./globalSetup.ts"]25 },25 },26 "scripts": {26 "scripts": {27 "lint": "eslint --ext .ts,.js src/",27 "lint": "eslint --ext .ts,.js src/",tests/src/app-promotion.seqtest.tsdiffbeforeafterbothno changes
tests/src/app-promotion.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util/playgrounds';18import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util/playgrounds';19import {encodeAddress} from '@polkadot/util-crypto';20import {stringToU8a} from '@polkadot/util';21import {DevUniqueHelper} from './util/playgrounds/unique.dev';19import {DevUniqueHelper} from './util/playgrounds/unique.dev';22import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';20import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';232124let superuser: IKeyringPair;25let donor: IKeyringPair;22let donor: IKeyringPair;26let palletAdmin: IKeyringPair;23let palletAdmin: IKeyringPair;27let nominal: bigint;24let nominal: bigint;28const palletAddress = calculatePalleteAddress('appstake');25let palletAddress: string;29let accounts: IKeyringPair[] = [];26let accounts: IKeyringPair[];30const LOCKING_PERIOD = 20n; // 20 blocks of relay27const LOCKING_PERIOD = 20n; // 20 blocks of relay31const UNLOCKING_PERIOD = 10n; // 10 blocks of parachain28const UNLOCKING_PERIOD = 10n; // 10 blocks of parachain32const rewardAvailableInBlock = (stakedInBlock: bigint) => {29const rewardAvailableInBlock = (stakedInBlock: bigint) => {38 before(async function () {35 before(async function () {39 await usingPlaygrounds(async (helper, privateKey) => {36 await usingPlaygrounds(async (helper, privateKey) => {40 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);37 requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);41 superuser = await privateKey('//Alice');42 donor = await privateKey({filename: __filename});38 donor = await privateKey({filename: __filename});43 [palletAdmin] = await helper.arrange.createAccounts([100n], donor);39 palletAddress = helper.arrange.calculatePalleteAddress('appstake');44 const api = helper.getApi();40 palletAdmin = await privateKey('//PromotionAdmin');45 await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));46 nominal = helper.balance.getOneTokenNominal();41 nominal = helper.balance.getOneTokenNominal();47 await helper.balance.transferToSubstrate(donor, palletAdmin.address, 1000n * nominal);42 await helper.balance.transferToSubstrate(donor, palletAdmin.address, 1000n * nominal);48 await helper.balance.transferToSubstrate(donor, palletAddress, 1000n * nominal);43 await helper.balance.transferToSubstrate(donor, palletAddress, 1000n * nominal);226 });221 });227 });222 });228 223 229 describe('admin adress', () => {230 itSub('can be set by sudo only', async ({helper}) => {231 const api = helper.getApi();232 const nonAdmin = accounts.pop()!;233 // nonAdmin can not set admin not from himself nor as a sudo234 await expect(helper.signTransaction(nonAdmin, 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;236 237 // Alice can238 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;239 });240 241 itSub('can be any valid CrossAccountId', async ({helper}) => {242 // We are not going to set an eth address as a sponsor,243 // but we do want to check, it doesn't break anything;244 const api = helper.getApi();245 const account = accounts.pop()!;246 const ethAccount = helper.address.substrateToEth(account.address); 247 // Alice sets Ethereum address as a sudo. Then Substrate address back...248 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;249 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;250 251 // ...It doesn't break anything;252 const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});253 await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;254 });255 256 itSub('can be reassigned', async ({helper}) => {257 const api = helper.getApi();258 const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];259 const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});260 261 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;262 await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;263 await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;264 265 await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;266 });267 });268 269 describe('collection sponsoring', () => {224 describe('collection sponsoring', () => {270 before(async function () {271 await usingPlaygrounds(async (helper) => {272 const api = helper.getApi();273 const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));274 await helper.signTransaction(superuser, tx);275 });276 });277 278 itSub('should actually sponsor transactions', async ({helper}) => {225 itSub('should actually sponsor transactions', async ({helper}) => {279 const api = helper.getApi();226 const api = helper.getApi();280 const [collectionOwner, tokenSender, receiver] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];227 const [collectionOwner, tokenSender, receiver] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];708 });655 });709 });656 });710});657});711712function calculatePalleteAddress(palletId: any) {713 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));714 return encodeAddress(address);715}716658717function calculateIncome(base: bigint, calcPeriod: bigint, iter = 0): bigint {659function calculateIncome(base: bigint, calcPeriod: bigint, iter = 0): bigint {718 const DAY = 7200n;660 const DAY = 7200n;tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.02// SPDX-License-Identifier: Apache-2.0334import {stringToU8a} from '@polkadot/util';4import {mnemonicGenerate} from '@polkadot/util-crypto';5import {encodeAddress, mnemonicGenerate} from '@polkadot/util-crypto';5import {UniqueHelper} from './unique';6import {UniqueHelper} from './unique';6import {ApiPromise, WsProvider} from '@polkadot/api';7import {ApiPromise, WsProvider} from '@polkadot/api';7import * as defs from '../../interfaces/definitions';8import * as defs from '../../interfaces/definitions';244 return balance;245 return balance;245 }246 }247248 calculatePalleteAddress(palletId: any) {249 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));250 return encodeAddress(address);251 }246}252}247253248class WaitGroup {254class WaitGroup {