git.delta.rocks / unique-network / refs/commits / 4a02655589a8

difftreelog

feat catch dispatchError in playgrounds

Daniel Shiposha2022-10-06parent: #a693ced.patch.diff
in: master

2 files changed

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      events: {18        phase: any, // {ApplyExtrinsic: number} | 'Initialization',19        event: IEvent;20      }[];21  },22  moduleError?: string;23}2425export interface ISubscribeBlockEventsData {26  number: number;27  hash: string;28  timestamp: number; 29  events: IEvent[];30}3132export interface ILogger {33  log: (msg: any, level?: string) => void;34  level: {35    ERROR: 'ERROR';36    WARNING: 'WARNING';37    INFO: 'INFO';38    [key: string]: string;39  }40}4142export interface IUniqueHelperLog {43  executedAt: number;44  executionTime: number;45  type: 'extrinsic' | 'rpc';46  status: 'Fail' | 'Success';47  call: string;48  params: any[];49  moduleError?: string;50  events?: any;51}5253export interface IApiListeners {54  connected?: (...args: any[]) => any;55  disconnected?: (...args: any[]) => any;56  error?: (...args: any[]) => any;57  ready?: (...args: any[]) => any; 58  decorated?: (...args: any[]) => any;59}6061export interface ICrossAccountId {62  Substrate?: TSubstrateAccount;63  Ethereum?: TEthereumAccount;64}6566export interface ICrossAccountIdLower {67  substrate?: TSubstrateAccount;68  ethereum?: TEthereumAccount;69}7071export interface ICollectionLimits {72  accountTokenOwnershipLimit?: number | null;73  sponsoredDataSize?: number | null;74  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;75  tokenLimit?: number | null;76  sponsorTransferTimeout?: number | null;77  sponsorApproveTimeout?: number | null;78  ownerCanTransfer?: boolean | null;79  ownerCanDestroy?: boolean | null;80  transfersEnabled?: boolean | null;81}8283export interface INestingPermissions {84  tokenOwner?: boolean;85  collectionAdmin?: boolean;86  restricted?: number[] | null;87}8889export interface ICollectionPermissions {90  access?: 'Normal' | 'AllowList';91  mintMode?: boolean;92  nesting?: INestingPermissions;93}9495export interface IProperty {96  key: string;97  value?: string;98}99100export interface ITokenPropertyPermission {101  key: string;102  permission: {103    mutable?: boolean;104    tokenOwner?: boolean;105    collectionAdmin?: boolean;106  }107}108109export interface IToken {110  collectionId: number;111  tokenId: number;112}113114export interface IBlock {115  extrinsics: IExtrinsic[]116  header: {117    parentHash: string,118    number: number,119  };120}121122export interface IExtrinsic {123  isSigned: boolean,124  method: {125    method: string,126    section: string,127    args: any[]128  }129}130131export interface ICollectionCreationOptions {132  name?: string | number[];133  description?: string | number[];134  tokenPrefix?: string | number[];135  mode?: {136    nft?: null;137    refungible?: null;138    fungible?: number;139  }140  permissions?: ICollectionPermissions;141  properties?: IProperty[];142  tokenPropertyPermissions?: ITokenPropertyPermission[];143  limits?: ICollectionLimits;144  pendingSponsor?: TSubstrateAccount;145}146147export interface IChainProperties {148  ss58Format: number;149  tokenDecimals: number[];150  tokenSymbol: string[]151}152153export interface ISubstrateBalance {154  free: bigint,155  reserved: bigint,156  miscFrozen: bigint,157  feeFrozen: bigint158}159160export interface IStakingInfo {161  block: bigint,162  amount: bigint,163}164165export type TSubstrateAccount = string;166export type TEthereumAccount = string;167export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';168export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';169export type TSigner = IKeyringPair; // | 'string'
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  moduleError?: string;24}2526export interface ISubscribeBlockEventsData {27  number: number;28  hash: string;29  timestamp: number; 30  events: IEvent[];31}3233export interface ILogger {34  log: (msg: any, level?: string) => void;35  level: {36    ERROR: 'ERROR';37    WARNING: 'WARNING';38    INFO: 'INFO';39    [key: string]: string;40  }41}4243export interface IUniqueHelperLog {44  executedAt: number;45  executionTime: number;46  type: 'extrinsic' | 'rpc';47  status: 'Fail' | 'Success';48  call: string;49  params: any[];50  moduleError?: string;51  dispatchError?: any;52  events?: any;53}5455export interface IApiListeners {56  connected?: (...args: any[]) => any;57  disconnected?: (...args: any[]) => any;58  error?: (...args: any[]) => any;59  ready?: (...args: any[]) => any; 60  decorated?: (...args: any[]) => any;61}6263export interface ICrossAccountId {64  Substrate?: TSubstrateAccount;65  Ethereum?: TEthereumAccount;66}6768export interface ICrossAccountIdLower {69  substrate?: TSubstrateAccount;70  ethereum?: TEthereumAccount;71}7273export interface ICollectionLimits {74  accountTokenOwnershipLimit?: number | null;75  sponsoredDataSize?: number | null;76  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;77  tokenLimit?: number | null;78  sponsorTransferTimeout?: number | null;79  sponsorApproveTimeout?: number | null;80  ownerCanTransfer?: boolean | null;81  ownerCanDestroy?: boolean | null;82  transfersEnabled?: boolean | null;83}8485export interface INestingPermissions {86  tokenOwner?: boolean;87  collectionAdmin?: boolean;88  restricted?: number[] | null;89}9091export interface ICollectionPermissions {92  access?: 'Normal' | 'AllowList';93  mintMode?: boolean;94  nesting?: INestingPermissions;95}9697export interface IProperty {98  key: string;99  value?: string;100}101102export interface ITokenPropertyPermission {103  key: string;104  permission: {105    mutable?: boolean;106    tokenOwner?: boolean;107    collectionAdmin?: boolean;108  }109}110111export interface IToken {112  collectionId: number;113  tokenId: number;114}115116export interface IBlock {117  extrinsics: IExtrinsic[]118  header: {119    parentHash: string,120    number: number,121  };122}123124export interface IExtrinsic {125  isSigned: boolean,126  method: {127    method: string,128    section: string,129    args: any[]130  }131}132133export interface ICollectionCreationOptions {134  name?: string | number[];135  description?: string | number[];136  tokenPrefix?: string | number[];137  mode?: {138    nft?: null;139    refungible?: null;140    fungible?: number;141  }142  permissions?: ICollectionPermissions;143  properties?: IProperty[];144  tokenPropertyPermissions?: ITokenPropertyPermission[];145  limits?: ICollectionLimits;146  pendingSponsor?: TSubstrateAccount;147}148149export interface IChainProperties {150  ss58Format: number;151  tokenDecimals: number[];152  tokenSymbol: string[]153}154155export interface ISubstrateBalance {156  free: bigint,157  reserved: bigint,158  miscFrozen: bigint,159  feeFrozen: bigint160}161162export interface IStakingInfo {163  block: bigint,164  amount: bigint,165}166167export type TSubstrateAccount = string;168export type TEthereumAccount = string;169export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';170export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';171export type TSigner = IKeyringPair; // | 'string'
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -514,12 +514,18 @@
       params,
     } as IUniqueHelperLog;
 
-    if(result.status !== this.transactionStatus.SUCCESS && result.moduleError) log.moduleError = result.moduleError;
+    if(result.status !== this.transactionStatus.SUCCESS) {
+      if (result.moduleError) log.moduleError = result.moduleError;
+      else if (result.result.dispatchError) log.dispatchError = result.result.dispatchError;
+    }
     if(events.length > 0) log.events = events;
 
     this.chainLog.push(log);
 
-    if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(`${result.moduleError}`);
+    if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) {
+      if (result.moduleError) throw Error(`${result.moduleError}`);
+      else if (result.result.dispatchError) throw Error(JSON.stringify(result.result.dispatchError));
+    }
     return result;
   }