difftreelog
test(appPromotion) read freezes instead of locks
in: master
2 files changed
tests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth89 // Staker balance is: frozen: 100, reserved: 0n...89 // Staker balance is: frozen: 100, reserved: 0n...90 // ...so he can not transfer 90090 // ...so he can not transfer 90091 expect(await helper.balance.getSubstrateFull(staker.address)).to.contain({frozen: 100n * nominal, reserved: 0n});91 expect(await helper.balance.getSubstrateFull(staker.address)).to.contain({frozen: 100n * nominal, reserved: 0n});92 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal, reasons: 'All'}]);92 expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: 100n * nominal}]);93 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith(/^Token: Frozen$/);93 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 900n * nominal)).to.be.rejectedWith(/^Token: Frozen$/);949495 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal);95 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.be.equal(100n * nominal);157 await helper.staking.stake(staker, 1000n * nominal);157 await helper.staking.stake(staker, 1000n * nominal);158 await helper.staking.stake(staker, 199n * nominal);158 await helper.staking.stake(staker, 199n * nominal);159 // check balances159 // check balances160 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}, {id: 'appstake', amount: 1199n * nominal, reasons: 'All'}]);160 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'ormlvest', amount: 200n * nominal, reasons: 'All'}]);161 expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: 1199n * nominal}]);161 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 1199n * nominal});162 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 1199n * nominal});162 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(1199n);163 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(1199n);163 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(1199n * nominal);164 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(1199n * nominal);218219219 // Right after unstake tokens are still locked220 // Right after unstake tokens are still locked220 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);221 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);221 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([{id: 'appstake', amount: STAKE_AMOUNT, reasons: 'All'}]);222 expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([{id: 'appstake', amount: STAKE_AMOUNT}]);222 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: STAKE_AMOUNT});223 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: STAKE_AMOUNT});223 // Staker can not transfer224 // Staker can not transfer224 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 100n * nominal)).to.be.rejectedWith(/^Token: Frozen$/);225 await expect(helper.balance.transferToSubstrate(staker, recepient.address, 100n * nominal)).to.be.rejectedWith(/^Token: Frozen$/);453 const [_unstake1, unstake2] = await helper.staking.getPendingUnstakePerBlock({Substrate: staker.address});454 const [_unstake1, unstake2] = await helper.staking.getPendingUnstakePerBlock({Substrate: staker.address});454 await helper.wait.forParachainBlockNumber(unstake2.block);455 await helper.wait.forParachainBlockNumber(unstake2.block);455456456 expect(await helper.balance.getLocked(staker.address)).to.deep.eq([]);457 expect(await helper.balance.getFrozen(staker.address)).to.deep.eq([]);457 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 0n});458 expect(await helper.balance.getSubstrateFull(staker.address)).to.deep.contain({reserved: 0n, frozen: 0n});458 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(999n);459 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.eq(999n);459 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(0n);460 expect(await helper.staking.getTotalStaked({Substrate: staker.address})).to.eq(0n);tests/src/util/playgrounds/unique.tsdiffbeforeafterboth778import {ApiPromise, WsProvider, Keyring} from '@polkadot/api';8import {ApiPromise, WsProvider, Keyring} from '@polkadot/api';9import {SignerOptions} from '@polkadot/api/types/submittable';9import {SignerOptions} from '@polkadot/api/types/submittable';10import '../../interfaces/augment-api-tx';10import '../../interfaces/augment-api';11import {AugmentedSubmittables} from '@polkadot/api-base/types/submittable';11import {AugmentedSubmittables} from '@polkadot/api-base/types/submittable';12import {RpcInterface} from '@polkadot/rpc-core/types';13import {QueryableStorage} from '@polkadot/api-base/types/storage';14import {DecoratedRpc} from '@polkadot/api-base/types/rpc';15import {ApiInterfaceEvents} from '@polkadot/api/types';12import {ApiInterfaceEvents} from '@polkadot/api/types';16import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm, base58Encode, blake2AsU8a} from '@polkadot/util-crypto';13import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm, base58Encode, blake2AsU8a} from '@polkadot/util-crypto';17import {IKeyringPair} from '@polkadot/types/types';14import {IKeyringPair} from '@polkadot/types/types';50} from './types';47} from './types';51import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';48import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';52import type {Vec} from '@polkadot/types-codec';49import type {Vec} from '@polkadot/types-codec';53import {FrameSystemEventRecord} from '@polkadot/types/lookup';50import {FrameSystemEventRecord, PalletBalancesIdAmount} from '@polkadot/types/lookup';545155export class CrossAccountId {52export class CrossAccountId {56 Substrate!: TSubstrateAccount;53 Substrate!: TSubstrateAccount;379type Get2<T, P extends string, E> =376type Get2<T, P extends string, E> =380 P extends `${infer Key}.${infer Key2}` ? Key extends keyof T ? Key2 extends keyof T[Key] ? T[Key][Key2] : E : E : E;377 P extends `${infer Key}.${infer Key2}` ? Key extends keyof T ? Key2 extends keyof T[Key] ? T[Key][Key2] : E : E : E;381type ForceFunction<T> = T extends (...args: any) => any ? T : (...args: any) => Invalid<'not a function'>;378type ForceFunction<T> = T extends (...args: any) => any ? T : (...args: any) => Invalid<'not a function'>;382type ReturnTypeWithArgs<T extends (...args: any[]) => any, ARGS_T> =383 Extract<384 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] :385 T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; (...args: infer A3): infer R3; } ? [A1, R1] | [A2, R2] | [A3, R3] :386 T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; } ? [A1, R1] | [A2, R2] :387 T extends { (...args: infer A1): infer R1; } ? [A1, R1] :388 never,389 [ARGS_T, any]390 >[1]391379392export class ChainHelperBase {380export class ChainHelperBase {393 helperBase: any;381 helperBase: any;1756 children = await this.helper.callRpc('api.rpc.unique.tokenChildren', [collectionId, tokenId, blockHashAt]);1744 children = await this.helper.callRpc('api.rpc.unique.tokenChildren', [collectionId, tokenId, blockHashAt]);1757 }1745 }175817461759 return children.toJSON().map((x: any) => {1747 return children.toJSON().map((x: any) => ({collectionId: x.collection, tokenId: x.token}));1760 return {collectionId: x.collection, tokenId: x.token};1761 });1762 }1748 }17631749241123972412 async getLocked(address: TSubstrateAccount): Promise<[{id: string, amount: bigint, reason: string}]> {2398 async getLocked(address: TSubstrateAccount): Promise<[{ id: string, amount: bigint, reason: string }]> {2413 const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman();2399 const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman();2414 return locks.map((lock: any) => { return {id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons}; });2400 return locks.map((lock: any) => ({id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons}));2415 }2401 }2402 async getFrozen(address: TSubstrateAccount): Promise<{ id: string, amount: bigint }[]> {2403 const locks = await this.helper.api!.query.balances.freezes(address);2404 return locks.map(lock => ({id: lock.id.toString(), amount: lock.amount.toBigInt()}));2405 }2416}2406}241724072418class EthereumBalanceGroup<T extends ChainHelperBase> extends HelperGroup<T> {2408class EthereumBalanceGroup<T extends ChainHelperBase> extends HelperGroup<T> {2504 return this.subBalanceGroup.getTotalIssuance();2494 return this.subBalanceGroup.getTotalIssuance();2505 }2495 }250624962507 /**2497 /**2508 * Get locked balances2498 * Get locked balances2509 * @param address substrate address2499 * @param address substrate address2510 * @returns locked balances with reason via api.query.balances.locks2500 * @returns locked balances with reason via api.query.balances.locks2511 */2501 * @deprecated all the methods should switch to getFrozen2502 */2512 getLocked(address: TSubstrateAccount) {2503 getLocked(address: TSubstrateAccount) {2513 return this.subBalanceGroup.getLocked(address);2504 return this.subBalanceGroup.getLocked(address);2514 }2505 }25062507 /**2508 * Get frozen balances2509 * @param address substrate address2510 * @returns locked balances with reason via api.query.balances.locks2511 */2512 getFrozen(address: TSubstrateAccount) {2513 return this.subBalanceGroup.getFrozen(address);2514 }251525152516 /**2516 /**2517 * Get ethereum address balance2517 * Get ethereum address balance