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
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;
   }