From b84fc5ccc1843ba5cc5737ed3fe55c56cf6bbdeb Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Mon, 13 Feb 2023 14:40:24 +0000 Subject: [PATCH] Fix test and improve throwing errors --- --- 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); --- 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 { --- 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; -- gitstuff