difftreelog
Fix helpers and tests
in: master
2 files changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2343,8 +2343,8 @@
* @param schedule Schedule params
* @example vestedTransfer(signer, recepient.address, 20000, 100, 10, 50 * nominal); // total amount of vested tokens will be 100 * 50 = 5000
*/
- async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: {startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {
- const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, {start: schedule.startRelayBlock, period: schedule.periodBlocks, periodCount: schedule.periodCount, perPeriod: schedule.perPeriod}]);
+ async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: {start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}): Promise<void> {
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, schedule]);
const event = result.result.events
.find(e => e.event.section === 'vesting' &&
e.event.method === 'VestingScheduleAdded' &&
@@ -2357,12 +2357,12 @@
* @param address Substrate address of recipient
* @returns
*/
- async getVestingSchedules(address: TSubstrateAccount): Promise<{startRelayBlock: bigint, periodBlocks: bigint, periodCount: bigint, perPeriod: bigint}[]> {
+ async getVestingSchedules(address: TSubstrateAccount): Promise<{start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint}[]> {
const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();
return schedule.map((schedule: any) => {
return {
- startRelayBlock: BigInt(schedule.start),
- periodBlocks: BigInt(schedule.period),
+ start: BigInt(schedule.start),
+ period: BigInt(schedule.period),
periodCount: BigInt(schedule.periodCount),
perPeriod: BigInt(schedule.perPeriod),
};
tests/src/vesting.test.tsdiffbeforeafterboth1// 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('cannot send more tokens than have', async ({helper}) => {32 const [sender, receiver] = await helper.arrange.createAccounts([1000n, 1n], donor);33 const manyPeriodsSchedule = {startRelayBlock: 0n, periodBlocks: 1n, periodCount: 100n, perPeriod: 10n * nominal};34 const oneBigSumSchedule = {startRelayBlock: 0n, periodBlocks: 1n, periodCount: 1n, perPeriod: 5000n * nominal};3536 expect(helper.balance.vestedTransfer(sender, sender.address, manyPeriodsSchedule)).to.be.rejected.with('InsufficientBalanceToLock');37 expect(helper.balance.vestedTransfer(sender, receiver.address, manyPeriodsSchedule)).to.be.rejected.with('InsufficientBalanceToLock');38 expect(helper.balance.vestedTransfer(sender, sender.address, oneBigSumSchedule)).to.be.rejected.with('InsufficientBalanceToLock');39 expect(helper.balance.vestedTransfer(sender, receiver.address, oneBigSumSchedule)).to.be.rejected.with('InsufficientBalanceToLock');4041 const balanceSender = await helper.balance.getSubstrateFull(sender.address);42 const balanceReceiver = await helper.balance.getSubstrateFull(receiver.address);4344 expect(balanceSender.free / nominal).to.eq(999n);45 expect(balanceSender.feeFrozen / nominal).to.eq(0n);46 expect(balanceSender.miscFrozen / nominal).to.eq(0n);47 expect(balanceSender.reserved / nominal).to.eq(0n);4849 expect(balanceReceiver.free).to.be.eq(1n * nominal);50 expect(balanceReceiver.feeFrozen).to.be.eq(0n);51 expect(balanceReceiver.miscFrozen).to.be.eq(0n);52 expect(balanceReceiver.reserved).to.be.eq(0n);53 });5455 itSub('can perform vestedTransfer and claim tokens', async ({helper}) => {56 // arrange57 const [sender, recepient] = await helper.arrange.createAccounts([1000n, 1n], donor);58 const currentRelayBlock = await helper.chain.getRelayBlockNumber();59 const schedule1 = {startRelayBlock: currentRelayBlock + 4n, periodBlocks: 4n, periodCount: 2n, perPeriod: 50n * nominal};60 const schedule2 = {startRelayBlock: currentRelayBlock + 8n, periodBlocks: 8n, periodCount: 2n, perPeriod: 100n * nominal};6162 // act63 await helper.balance.vestedTransfer(sender, recepient.address, schedule1);64 await helper.balance.vestedTransfer(sender, recepient.address, schedule2);65 let schedule = await helper.balance.getVestingSchedules(recepient.address);6667 // check senders balance after vesting:68 let balanceSender = await helper.balance.getSubstrateFull(sender.address);69 expect(balanceSender.free / nominal).to.eq(699n);70 expect(balanceSender.feeFrozen).to.eq(0n);71 expect(balanceSender.miscFrozen).to.eq(0n);72 expect(balanceSender.reserved).to.eq(0n);7374 // check recepient balance after vesting:75 let balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);76 expect(balanceRecepient.free).to.eq(301n * nominal);77 expect(balanceRecepient.feeFrozen).to.eq(300n * nominal);78 expect(balanceRecepient.miscFrozen).to.eq(300n * nominal);79 expect(balanceRecepient.reserved).to.eq(0n);8081 // Schedules list correct:82 expect(schedule).to.has.length(2);83 expect(schedule[0]).to.deep.eq(schedule1);84 expect(schedule[1]).to.deep.eq(schedule2);8586 await helper.wait.forRelayBlockNumber(currentRelayBlock + 8n);87 await helper.balance.claim(recepient);8889 // check recepient balance after claim (50 tokens claimed):90 balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);91 expect(balanceRecepient.free / nominal).to.eq(300n);92 expect(balanceRecepient.feeFrozen).to.eq(250n * nominal);93 expect(balanceRecepient.miscFrozen).to.eq(250n * nominal);94 expect(balanceRecepient.reserved).to.eq(0n);95 96 await helper.wait.forRelayBlockNumber(currentRelayBlock + 16n);97 await helper.balance.claim(recepient);9899 // check recepient balance after second claim (150 tokens claimed):100 balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);101 expect(balanceRecepient.free / nominal).to.eq(300n);102 expect(balanceRecepient.feeFrozen).to.eq(100n * nominal);103 expect(balanceRecepient.miscFrozen).to.eq(100n * nominal);104 expect(balanceRecepient.reserved).to.eq(0n);105 106 // Schedules list contain 1 vesting:107 schedule = await helper.balance.getVestingSchedules(recepient.address);108 expect(schedule).to.has.length(1);109 expect(schedule[0]).to.deep.eq(schedule2);110111 await helper.wait.forRelayBlockNumber(currentRelayBlock + 24n);112 await helper.balance.claim(recepient);113114 // check recepient balance after second claim (100 tokens claimed):115 balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);116 expect(balanceRecepient.free / nominal).to.eq(300n);117 expect(balanceRecepient.feeFrozen).to.eq(0n);118 expect(balanceRecepient.miscFrozen).to.eq(0n);119 expect(balanceRecepient.reserved).to.eq(0n);120 121 // check sender balance does not changed:122 balanceSender = await helper.balance.getSubstrateFull(sender.address);123 expect(balanceSender.free / nominal).to.eq(699n);124 expect(balanceSender.feeFrozen).to.eq(0n);125 expect(balanceSender.miscFrozen).to.eq(0n);126 expect(balanceSender.reserved).to.eq(0n);127 });128});