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

difftreelog

Fix test and improve throwing errors

Max Andreev2023-02-13parent: #fd5def0.patch.diff
in: master

3 files changed

modifiedtests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth
--- a/tests/src/sub/appPromotion/appPromotion.test.ts
+++ b/tests/src/sub/appPromotion/appPromotion.test.ts
@@ -247,7 +247,7 @@
         // unstake has no effect if no stakes at all
         testCase.method === 'unstakeAll'
           ? await helper.staking.unstakeAll(staker)
-          : await helper.staking.unstakePartial(staker, 100n * nominal);
+          : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
 
         expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);
         expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper
@@ -262,7 +262,7 @@
           await helper.staking.unstakeAll(staker);
         } else {
           await helper.staking.unstakePartial(staker, 100n * nominal);
-          await helper.staking.unstakePartial(staker, 100n * nominal);
+          await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
         }
 
         expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);
modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
before · tests/src/util/playgrounds/types.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56export interface IEvent {7  section: string;8  method: string;9  index: [number, number] | string;10  data: any[];11  phase: {applyExtrinsic: number} | 'Initialization',12}1314export interface ITransactionResult {15  status: 'Fail' | 'Success';16  result: {17      dispatchError: any,18      events: {19        phase: any, // {ApplyExtrinsic: number} | 'Initialization',20        event: IEvent;21      }[];22  },23  blockHash: string,24  moduleError?: string;25}2627export interface ISubscribeBlockEventsData {28  number: number;29  hash: string;30  timestamp: number;31  events: IEvent[];32}3334export interface ILogger {35  log: (msg: any, level?: string) => void;36  level: {37    ERROR: 'ERROR';38    WARNING: 'WARNING';39    INFO: 'INFO';40    [key: string]: string;41  }42}4344export interface IUniqueHelperLog {45  executedAt: number;46  executionTime: number;47  type: 'extrinsic' | 'rpc';48  status: 'Fail' | 'Success';49  call: string;50  params: any[];51  moduleError?: string;52  dispatchError?: any;53  events?: any;54}5556export interface IApiListeners {57  connected?: (...args: any[]) => any;58  disconnected?: (...args: any[]) => any;59  error?: (...args: any[]) => any;60  ready?: (...args: any[]) => any;61  decorated?: (...args: any[]) => any;62}6364export interface ICrossAccountId {65  Substrate?: TSubstrateAccount;66  Ethereum?: TEthereumAccount;67}6869export interface ICrossAccountIdLower {70  substrate?: TSubstrateAccount;71  ethereum?: TEthereumAccount;72}7374export interface IEthCrossAccountId {75  0: TEthereumAccount;76  1: TSubstrateAccount;77  eth: TEthereumAccount;78  sub: TSubstrateAccount;79}8081export interface ICollectionLimits {82  accountTokenOwnershipLimit?: number | null;83  sponsoredDataSize?: number | null;84  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;85  tokenLimit?: number | null;86  sponsorTransferTimeout?: number | null;87  sponsorApproveTimeout?: number | null;88  ownerCanTransfer?: boolean | null;89  ownerCanDestroy?: boolean | null;90  transfersEnabled?: boolean | null;91}9293export interface INestingPermissions {94  tokenOwner?: boolean;95  collectionAdmin?: boolean;96  restricted?: number[] | null;97}9899export interface ICollectionPermissions {100  access?: 'Normal' | 'AllowList';101  mintMode?: boolean;102  nesting?: INestingPermissions;103}104105export interface IProperty {106  key: string;107  value?: string;108}109110export interface ITokenPropertyPermission {111  key: string;112  permission: {113    mutable?: boolean;114    tokenOwner?: boolean;115    collectionAdmin?: boolean;116  }117}118119export interface IToken {120  collectionId: number;121  tokenId: number;122}123124export interface IBlock {125  extrinsics: IExtrinsic[]126  header: {127    parentHash: string,128    number: number,129  };130}131132export interface IExtrinsic {133  isSigned: boolean,134  method: {135    method: string,136    section: string,137    args: any[]138  }139}140141export interface ICollectionCreationOptions {142  name?: string | number[];143  description?: string | number[];144  tokenPrefix?: string | number[];145  mode?: {146    nft?: null;147    refungible?: null;148    fungible?: number;149  }150  permissions?: ICollectionPermissions;151  properties?: IProperty[];152  tokenPropertyPermissions?: ITokenPropertyPermission[];153  limits?: ICollectionLimits;154  pendingSponsor?: TSubstrateAccount;155}156157export interface IChainProperties {158  ss58Format: number;159  tokenDecimals: number[];160  tokenSymbol: string[]161}162163export interface ISubstrateBalance {164  free: bigint,165  reserved: bigint,166  miscFrozen: bigint,167  feeFrozen: bigint168}169170export interface IStakingInfo {171  block: bigint,172  amount: bigint,173}174175export interface IPovInfo {176  proofSize: number,177  compactProofSize: number,178  compressedProofSize: number,179  results: any[],180  kv: any,181}182183export interface ISchedulerOptions {184  scheduledId?: string,185  priority?: number,186  periodic?: {187    period: number,188    repetitions: number,189  },190}191192export interface IForeignAssetMetadata {193  name?: number | Uint8Array,194  symbol?: string,195  decimals?: number,196  minimalBalance?: bigint,197}198199export interface MoonbeamAssetInfo {200  location: any,201  metadata: {202    name: string,203    symbol: string,204    decimals: number,205    isFrozen: boolean,206    minimalBalance: bigint,207  },208  existentialDeposit: bigint,209  isSufficient: boolean,210  unitsPerSecond: bigint,211  numAssetsWeightHint: number,212}213214export interface AcalaAssetMetadata {215  name: string,216  symbol: string,217  decimals: number,218  minimalBalance: bigint,219}220221export interface DemocracyStandardAccountVote {222  balance: bigint,223  vote: {224    aye: boolean,225    conviction: number,226  },227}228229export type TSubstrateAccount = string;230export type TEthereumAccount = string;231export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';232export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';233export type TSiblingNetworkds = 'moonbeam' | 'moonriver' | 'acala' | 'karura' | 'westmint';234export type TRelayNetworks = 'rococo' | 'westend';235export type TNetworks = TUniqueNetworks | TSiblingNetworkds | TRelayNetworks;236export type TSigner = IKeyringPair; // | 'string'237export type TCollectionMode = 'nft' | 'rft' | 'ft';
after · tests/src/util/playgrounds/types.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56export interface IEvent {7  section: string;8  method: string;9  index: [number, number] | string;10  data: any[];11  phase: {applyExtrinsic: number} | 'Initialization',12}1314export interface ITransactionResult {15  status: 'Fail' | 'Success';16  result: {17      dispatchError: any,18      events: {19        phase: any, // {ApplyExtrinsic: number} | 'Initialization',20        event: IEvent;21      }[];22  },23  blockHash: string,24  moduleError?: string | object;25}2627export interface ISubscribeBlockEventsData {28  number: number;29  hash: string;30  timestamp: number;31  events: IEvent[];32}3334export interface ILogger {35  log: (msg: any, level?: string) => void;36  level: {37    ERROR: 'ERROR';38    WARNING: 'WARNING';39    INFO: 'INFO';40    [key: string]: string;41  }42}4344export interface IUniqueHelperLog {45  executedAt: number;46  executionTime: number;47  type: 'extrinsic' | 'rpc';48  status: 'Fail' | 'Success';49  call: string;50  params: any[];51  moduleError?: string;52  dispatchError?: any;53  events?: any;54}5556export interface IApiListeners {57  connected?: (...args: any[]) => any;58  disconnected?: (...args: any[]) => any;59  error?: (...args: any[]) => any;60  ready?: (...args: any[]) => any;61  decorated?: (...args: any[]) => any;62}6364export interface ICrossAccountId {65  Substrate?: TSubstrateAccount;66  Ethereum?: TEthereumAccount;67}6869export interface ICrossAccountIdLower {70  substrate?: TSubstrateAccount;71  ethereum?: TEthereumAccount;72}7374export interface IEthCrossAccountId {75  0: TEthereumAccount;76  1: TSubstrateAccount;77  eth: TEthereumAccount;78  sub: TSubstrateAccount;79}8081export interface ICollectionLimits {82  accountTokenOwnershipLimit?: number | null;83  sponsoredDataSize?: number | null;84  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;85  tokenLimit?: number | null;86  sponsorTransferTimeout?: number | null;87  sponsorApproveTimeout?: number | null;88  ownerCanTransfer?: boolean | null;89  ownerCanDestroy?: boolean | null;90  transfersEnabled?: boolean | null;91}9293export interface INestingPermissions {94  tokenOwner?: boolean;95  collectionAdmin?: boolean;96  restricted?: number[] | null;97}9899export interface ICollectionPermissions {100  access?: 'Normal' | 'AllowList';101  mintMode?: boolean;102  nesting?: INestingPermissions;103}104105export interface IProperty {106  key: string;107  value?: string;108}109110export interface ITokenPropertyPermission {111  key: string;112  permission: {113    mutable?: boolean;114    tokenOwner?: boolean;115    collectionAdmin?: boolean;116  }117}118119export interface IToken {120  collectionId: number;121  tokenId: number;122}123124export interface IBlock {125  extrinsics: IExtrinsic[]126  header: {127    parentHash: string,128    number: number,129  };130}131132export interface IExtrinsic {133  isSigned: boolean,134  method: {135    method: string,136    section: string,137    args: any[]138  }139}140141export interface ICollectionCreationOptions {142  name?: string | number[];143  description?: string | number[];144  tokenPrefix?: string | number[];145  mode?: {146    nft?: null;147    refungible?: null;148    fungible?: number;149  }150  permissions?: ICollectionPermissions;151  properties?: IProperty[];152  tokenPropertyPermissions?: ITokenPropertyPermission[];153  limits?: ICollectionLimits;154  pendingSponsor?: TSubstrateAccount;155}156157export interface IChainProperties {158  ss58Format: number;159  tokenDecimals: number[];160  tokenSymbol: string[]161}162163export interface ISubstrateBalance {164  free: bigint,165  reserved: bigint,166  miscFrozen: bigint,167  feeFrozen: bigint168}169170export interface IStakingInfo {171  block: bigint,172  amount: bigint,173}174175export interface IPovInfo {176  proofSize: number,177  compactProofSize: number,178  compressedProofSize: number,179  results: any[],180  kv: any,181}182183export interface ISchedulerOptions {184  scheduledId?: string,185  priority?: number,186  periodic?: {187    period: number,188    repetitions: number,189  },190}191192export interface IForeignAssetMetadata {193  name?: number | Uint8Array,194  symbol?: string,195  decimals?: number,196  minimalBalance?: bigint,197}198199export interface MoonbeamAssetInfo {200  location: any,201  metadata: {202    name: string,203    symbol: string,204    decimals: number,205    isFrozen: boolean,206    minimalBalance: bigint,207  },208  existentialDeposit: bigint,209  isSufficient: boolean,210  unitsPerSecond: bigint,211  numAssetsWeightHint: number,212}213214export interface AcalaAssetMetadata {215  name: string,216  symbol: string,217  decimals: number,218  minimalBalance: bigint,219}220221export interface DemocracyStandardAccountVote {222  balance: bigint,223  vote: {224    aye: boolean,225    conviction: number,226  },227}228229export type TSubstrateAccount = string;230export type TEthereumAccount = string;231export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';232export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';233export type TSiblingNetworkds = 'moonbeam' | 'moonriver' | 'acala' | 'karura' | 'westmint';234export type TRelayNetworks = 'rococo' | 'westend';235export type TNetworks = TUniqueNetworks | TSiblingNetworkds | TRelayNetworks;236export type TSigner = IKeyringPair; // | 'string'237export type TCollectionMode = 'nft' | 'rft' | 'ft';
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -672,8 +672,15 @@
       params,
     } as IUniqueHelperLog;
 
+    let errorMessage = '';
+
     if(result.status !== this.transactionStatus.SUCCESS) {
-      if (result.moduleError) log.moduleError = result.moduleError;
+      if (result.moduleError) {
+        errorMessage = typeof result.moduleError === 'string'
+          ? result.moduleError
+          : `${Object.keys(result.moduleError)[0]}: ${Object.values(result.moduleError)[0]}`;
+        log.moduleError = errorMessage;
+      }
       else if (result.result.dispatchError) log.dispatchError = result.result.dispatchError;
     }
     if(events.length > 0) log.events = events;
@@ -681,7 +688,7 @@
     this.chainLog.push(log);
 
     if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) {
-      if (result.moduleError) throw Error(`${result.moduleError}`);
+      if (result.moduleError) throw Error(`${errorMessage}`);
       else if (result.result.dispatchError) throw Error(JSON.stringify(result.result.dispatchError));
     }
     return result;