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

difftreelog

source

tests/src/app-promotion.test.ts3.5 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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    // arrange: Alice balance = 100061    // act:     Alice calls appPromotion.stake(100)62    // assert:  Alice locked balance equal 10063    // assert:  Alice free balance closeTo 90064    // assert:  query appPromotion.staked(Alice) equal [100]65    // assert:  query appPromotion.totalStaked() increased by 10066    // act:     Alice extrinsic appPromotion.stake(200)67  68    // assert:  Alice locked balance equal 30069    // assert:  query appPromotion.staked(Alice) equal [100, 200]70    // assert:  query appPromotion.totalStaked() increased by 20071    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});