1234567891011121314151617import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 21 createMultipleItemsExpectSuccess,22 isTokenExists,23 getLastTokenId,24 getAllowance,25 approve,26 transferFrom,27 createCollection,28 transfer,29 burnItem,30 normalizeAccountId,31 CrossAccountId,32 createFungibleItemExpectSuccess,33 U128_MAX,34 burnFromExpectSuccess,35 UNIQUE,36} from './util/helpers';3738import chai from 'chai';39import chaiAsPromised from 'chai-as-promised';40import getBalance from './substrate/get-balance';41import { unique } from './interfaces/definitions';42chai.use(chaiAsPromised);43const expect = chai.expect;4445let alice: IKeyringPair;46let bob: IKeyringPair;47let palletAdmin: IKeyringPair;4849describe('integration test: AppPromotion', () => {50 before(async () => {51 await usingApi(async (api, privateKeyWrapper) => {52 alice = privateKeyWrapper('//Alice');53 bob = privateKeyWrapper('//Bob');54 palletAdmin = privateKeyWrapper('//palletAdmin');55 const tx = api.tx.sudo.sudo(api.tx.promotion.setAdminAddress(palletAdmin.addressRaw));56 await submitTransactionAsync(alice, tx);57 });58 });59 it('will change balance state to "locked", add it to "staked" map, and increase "totalStaked" amount', async () => {60 61 62 63 64 65 66 67 68 69 70 71 72 await usingApi(async (api, privateKeyWrapper) => {73 await submitTransactionAsync(alice, api.tx.balances.transfer(bob.addressRaw, 10n * UNIQUE));74 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);75 76 console.log(`alice: ${alicesBalanceBefore} \n bob: ${bobsBalanceBefore}`);77 78 await submitTransactionAsync(alice, api.tx.promotion.stake(1n * UNIQUE));79 await submitTransactionAsync(bob, api.tx.promotion.stake(1n * UNIQUE));80 const alice_total_staked = (await (api.rpc.unique.totalStaked(normalizeAccountId(alice)))).toBigInt();81 const bob_total_staked = (await api.rpc.unique.totalStaked(normalizeAccountId(bob))).toBigInt();82 83 console.log(`alice staked: ${alice_total_staked} \n bob staked: ${bob_total_staked}, total staked: ${(await api.rpc.unique.totalStaked()).toBigInt()}`);84 85 86 87 });88 });8990});