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
21 }[];21 }[];
22 },22 },
23 blockHash: string,23 blockHash: string,
24 moduleError?: string;24 moduleError?: string | object;
25}25}
2626
27export interface ISubscribeBlockEventsData {27export 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;