git.delta.rocks / unique-network / refs/commits / 9efe15d9b711

difftreelog

source

tests/src/vesting.test.ts4.6 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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('Vesting', () => {21  let donor: IKeyringPair;22  let nominal: bigint;2324  before(async () => {25    await usingPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({filename: __filename});27      nominal = helper.balance.getOneTokenNominal();28    });29  });3031  itSub.only('can perform vestedTransfer and claim tokens', async ({helper}) => {32    // arrange33    const [sender, recepient] = await helper.arrange.createAccounts([1000n, 1n], donor);34    const currentRelayBlock = await helper.chain.getRelayBlockNumber();35    const schedule1 = {startRelayBlock: currentRelayBlock + 4n, periodBlocks: 4n, periodCount: 2n, perPeriod: 50n * nominal};36    const schedule2 = {startRelayBlock: currentRelayBlock + 8n, periodBlocks: 8n, periodCount: 2n, perPeriod: 100n * nominal};3738    // act39    await helper.balance.vestedTransfer(sender, recepient.address, schedule1);40    await helper.balance.vestedTransfer(sender, recepient.address, schedule2);41    let schedule = await helper.balance.getVestingSchedules(recepient.address);4243    // check senders balance after vesting:44    let balanceSender = await helper.balance.getSubstrateFull(sender.address);45    expect(balanceSender.free / nominal).to.eq(699n);46    expect(balanceSender.feeFrozen).to.eq(0n);47    expect(balanceSender.miscFrozen).to.eq(0n);48    expect(balanceSender.reserved).to.eq(0n);4950    // check recepient balance after vesting:51    let balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);52    expect(balanceRecepient.free).to.eq(301n * nominal);53    expect(balanceRecepient.feeFrozen).to.eq(300n * nominal);54    expect(balanceRecepient.miscFrozen).to.eq(300n * nominal);55    expect(balanceRecepient.reserved).to.eq(0n);5657    // Schedules list correct:58    expect(schedule).to.has.length(2);59    expect(schedule[0]).to.deep.eq(schedule1);60    expect(schedule[1]).to.deep.eq(schedule2);6162    await helper.wait.forRelayBlockNumber(currentRelayBlock + 8n);63    await helper.balance.claim(recepient);6465    // check recepient balance after claim (50 tokens claimed):66    balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);67    expect(balanceRecepient.free / nominal).to.eq(300n);68    expect(balanceRecepient.feeFrozen).to.eq(250n * nominal);69    expect(balanceRecepient.miscFrozen).to.eq(250n * nominal);70    expect(balanceRecepient.reserved).to.eq(0n);71    72    await helper.wait.forRelayBlockNumber(currentRelayBlock + 16n);73    await helper.balance.claim(recepient);7475    // check recepient balance after second claim (150 tokens claimed):76    balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);77    expect(balanceRecepient.free / nominal).to.eq(300n);78    expect(balanceRecepient.feeFrozen).to.eq(100n * nominal);79    expect(balanceRecepient.miscFrozen).to.eq(100n * nominal);80    expect(balanceRecepient.reserved).to.eq(0n);81    82    // Schedules list contain 1 vesting:83    schedule = await helper.balance.getVestingSchedules(recepient.address);84    expect(schedule).to.has.length(1);85    expect(schedule[0]).to.deep.eq(schedule2);8687    await helper.wait.forRelayBlockNumber(currentRelayBlock + 24n);88    await helper.balance.claim(recepient);8990    // check recepient balance after second claim (100 tokens claimed):91    balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);92    expect(balanceRecepient.free / nominal).to.eq(300n);93    expect(balanceRecepient.feeFrozen).to.eq(0n);94    expect(balanceRecepient.miscFrozen).to.eq(0n);95    expect(balanceRecepient.reserved).to.eq(0n);96    97    // check sender balance does not changed:98    balanceSender = await helper.balance.getSubstrateFull(sender.address);99    expect(balanceSender.free / nominal).to.eq(699n);100    expect(balanceSender.feeFrozen).to.eq(0n);101    expect(balanceSender.miscFrozen).to.eq(0n);102    expect(balanceSender.reserved).to.eq(0n);103  });104});