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
247 // unstake has no effect if no stakes at all247 // unstake has no effect if no stakes at all
248 testCase.method === 'unstakeAll'248 testCase.method === 'unstakeAll'
249 ? await helper.staking.unstakeAll(staker)249 ? await helper.staking.unstakeAll(staker)
250 : await helper.staking.unstakePartial(staker, 100n * nominal);250 : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
251251
252 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);252 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);
253 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper253 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper
262 await helper.staking.unstakeAll(staker);262 await helper.staking.unstakeAll(staker);
263 } else {263 } else {
264 await helper.staking.unstakePartial(staker, 100n * nominal);264 await helper.staking.unstakePartial(staker, 100n * nominal);
265 await helper.staking.unstakePartial(staker, 100n * nominal);265 await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
266 }266 }
267267
268 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);268 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);
modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -21,7 +21,7 @@
       }[];
   },
   blockHash: string,
-  moduleError?: string;
+  moduleError?: string | object;
 }
 
 export interface ISubscribeBlockEventsData {
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;