--- a/tests/src/sub/appPromotion/appPromotion.test.ts +++ b/tests/src/sub/appPromotion/appPromotion.test.ts @@ -89,7 +89,7 @@ // Staker balance is: frozen: 100, reserved: 0n... // ...so he can not transfer 900 expect(await helper.balance.getSubstrateFull(staker.address)).to.contain({frozen: 100n * nominal, reserved: 0n}); - expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal, reasons: 'All'}]); + expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal}]); await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith(/^Token: Frozen$/); expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal); @@ -157,7 +157,8 @@ await helper.staking.stake(staker, 1000n * nominal); await helper.staking.stake(staker, 199n * nominal); // check balances - expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}, {id: 'appstake', amount: 1199n * nominal, reasons: 'All'}]); + expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}]); + expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: 1199n * nominal}]); expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 1199n * nominal}); expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(1199n); expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(1199n * nominal); @@ -218,7 +219,7 @@ // Right after unstake tokens are still locked expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0); - expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: STAKE_AMOUNT, reasons: 'All'}]); + expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: STAKE_AMOUNT}]); expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: STAKE_AMOUNT}); // Staker can not transfer await expect(helper.balance.transferToSubstrate(staker, recepient.address, 100n * nominal)).to.be.rejectedWith(/^Token: Frozen$/); @@ -453,7 +454,7 @@ const [_unstake1, unstake2] = await helper.staking.getPendingUnstakePerBlock({Substrate: staker.address}); await helper.wait.forParachainBlockNumber(unstake2.block); - expect(await helper.balance.getLocked(staker.address)).to.deep.eq([]); + expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([]); expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 0n}); expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(999n); expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(0n); --- a/tests/src/util/playgrounds/unique.ts +++ b/tests/src/util/playgrounds/unique.ts @@ -7,11 +7,8 @@ import {ApiPromise, WsProvider, Keyring} from '@polkadot/api'; import {SignerOptions} from '@polkadot/api/types/submittable'; -import '../../interfaces/augment-api-tx'; +import '../../interfaces/augment-api'; import {AugmentedSubmittables} from '@polkadot/api-base/types/submittable'; -import {RpcInterface} from '@polkadot/rpc-core/types'; -import {QueryableStorage} from '@polkadot/api-base/types/storage'; -import {DecoratedRpc} from '@polkadot/api-base/types/rpc'; import {ApiInterfaceEvents} from '@polkadot/api/types'; import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm, base58Encode, blake2AsU8a} from '@polkadot/util-crypto'; import {IKeyringPair} from '@polkadot/types/types'; @@ -50,7 +47,7 @@ } from './types'; import {RuntimeDispatchInfo} from '@polkadot/types/interfaces'; import type {Vec} from '@polkadot/types-codec'; -import {FrameSystemEventRecord} from '@polkadot/types/lookup'; +import {FrameSystemEventRecord, PalletBalancesIdAmount} from '@polkadot/types/lookup'; export class CrossAccountId { Substrate!: TSubstrateAccount; @@ -379,15 +376,6 @@ type Get2 = P extends `${infer Key}.${infer Key2}` ? Key extends keyof T ? Key2 extends keyof T[Key] ? T[Key][Key2] : E : E : E; type ForceFunction = T extends (...args: any) => any ? T : (...args: any) => Invalid<'not a function'>; -type ReturnTypeWithArgs any, ARGS_T> = - Extract< - T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; (...args: infer A3): infer R3; (...args: infer A4): infer R4; } ? [A1, R1] | [A2, R2] | [A3, R3] | [A4, R4] : - T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; (...args: infer A3): infer R3; } ? [A1, R1] | [A2, R2] | [A3, R3] : - T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; } ? [A1, R1] | [A2, R2] : - T extends { (...args: infer A1): infer R1; } ? [A1, R1] : - never, - [ARGS_T, any] - >[1] export class ChainHelperBase { helperBase: any; @@ -677,12 +665,12 @@ async executeExtrinsic< E extends string, V extends ( -...args: any) => any = ForceFunction< - Get2< - AugmentedSubmittables<'promise'>, - E, (...args: any) => Invalid<'not found'> + ...args: any) => any = ForceFunction< + Get2< + AugmentedSubmittables<'promise'>, + E, (...args: any) => Invalid<'not found'> + > > - > >( sender: TSigner, extrinsic: `api.tx.${E}`, @@ -1756,9 +1744,7 @@ children = await this.helper.callRpc('api.rpc.unique.tokenChildren', [collectionId, tokenId, blockHashAt]); } - return children.toJSON().map((x: any) => { - return {collectionId: x.collection, tokenId: x.token}; - }); + return children.toJSON().map((x: any) => ({collectionId: x.collection, tokenId: x.token})); } /** @@ -2409,9 +2395,13 @@ return total.toBigInt(); } - async getLocked(address: TSubstrateAccount): Promise<[{id: string, amount: bigint, reason: string}]> { + async getLocked(address: TSubstrateAccount): Promise<[{ id: string, amount: bigint, reason: string }]> { const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman(); - return locks.map((lock: any) => { return {id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons}; }); + return locks.map((lock: any) => ({id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons})); + } + async getFrozen(address: TSubstrateAccount): Promise<{ id: string, amount: bigint }[]> { + const locks = await this.helper.api!.query.balances.freezes(address); + return locks.map(lock => ({id: lock.id.toString(), amount: lock.amount.toBigInt()})); } } @@ -2508,12 +2498,22 @@ * Get locked balances * @param address substrate address * @returns locked balances with reason via api.query.balances.locks + * @deprecated all the methods should switch to getFrozen */ getLocked(address: TSubstrateAccount) { return this.subBalanceGroup.getLocked(address); } /** + * Get frozen balances + * @param address substrate address + * @returns locked balances with reason via api.query.balances.locks + */ + getFrozen(address: TSubstrateAccount) { + return this.subBalanceGroup.getFrozen(address); + } + + /** * Get ethereum address balance * @param address ethereum address * @example getEthereum("0x9F0583DbB855d...")