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
--- 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
672 params,672 params,
673 } as IUniqueHelperLog;673 } as IUniqueHelperLog;
674
675 let errorMessage = '';
674676
675 if(result.status !== this.transactionStatus.SUCCESS) {677 if(result.status !== this.transactionStatus.SUCCESS) {
676 if (result.moduleError) log.moduleError = result.moduleError;678 if (result.moduleError) {
679 errorMessage = typeof result.moduleError === 'string'
680 ? result.moduleError
681 : `${Object.keys(result.moduleError)[0]}: ${Object.values(result.moduleError)[0]}`;
682 log.moduleError = errorMessage;
683 }
677 else if (result.result.dispatchError) log.dispatchError = result.result.dispatchError;684 else if (result.result.dispatchError) log.dispatchError = result.result.dispatchError;
678 }685 }
679 if(events.length > 0) log.events = events;686 if(events.length > 0) log.events = events;
680687
681 this.chainLog.push(log);688 this.chainLog.push(log);
682689
683 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) {690 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) {
684 if (result.moduleError) throw Error(`${result.moduleError}`);691 if (result.moduleError) throw Error(`${errorMessage}`);
685 else if (result.result.dispatchError) throw Error(JSON.stringify(result.result.dispatchError));692 else if (result.result.dispatchError) throw Error(JSON.stringify(result.result.dispatchError));
686 }693 }
687 return result;694 return result;