Skip to content
Snippets Groups Projects
Unverified Commit 49dc2f43 authored by Tarik Gul's avatar Tarik Gul
Browse files

write tests and adjust logic to include tips into partial fee

parent 131aeffa
Branches 986
No related merge requests found
Pipeline #203501 waiting for manual action with stages
in 1 minute and 26 seconds
......@@ -20,6 +20,7 @@ import { PromiseRpcResult } from '@polkadot/api-base/types/rpc';
import { GenericExtrinsic } from '@polkadot/types';
import { GenericCall } from '@polkadot/types/generic';
import { BlockHash, Hash, SignedBlock } from '@polkadot/types/interfaces';
import { Compact } from '@polkadot/types-codec/base';
import { BadRequest } from 'http-errors';
import LRU from 'lru-cache';
......@@ -44,6 +45,7 @@ import {
constructEvent,
treasuryEvent,
withdrawEvent,
withdrawEventForTip,
} from '../test-helpers/mock/data/mockEventData';
import { validators789629Hex } from '../test-helpers/mock/data/validators789629Hex';
import { parseNumberOrThrow } from '../test-helpers/mock/parseNumberOrThrow';
......@@ -589,6 +591,19 @@ describe('BlocksService', () => {
expect(response).toStrictEqual(expectedResponse);
});
it('Should retrieve the correct fee for balances:withdraw events with a tip', () => {
const expectedResponse = { partialFee: '1681144907847007' };
const fee = polkadotRegistry.createType('Balance', '1675415067070856');
const tip = new Compact(polkadotRegistry, 'u64', 5729827274000);
const response = blocksService['getPartialFeeByEvents'](
withdrawEventForTip,
fee,
tip
);
expect(response).toStrictEqual(expectedResponse);
});
it('Should error correctly when there is no fee in the events', () => {
const expectedResponseWithError = {
...expectedResponse,
......
......@@ -533,9 +533,11 @@ export class BlocksService extends AbstractService {
const dataArr = withdrawEvent[0].data.toJSON();
if (Array.isArray(dataArr)) {
const fee = (dataArr as Array<number>)[dataArr.length - 1];
const adjustedFee = tip ? tip.toBn().add(new BN(fee)) : new BN(fee);
const adjustedPartialFee = tip
? tip.toBn().add(partialFee)
: partialFee;
// The difference between values is 00.00001% or less so they are alike.
if (this.areFeesSimilar(adjustedFee, partialFee)) {
if (this.areFeesSimilar(new BN(fee), adjustedPartialFee)) {
return {
partialFee: fee.toString(),
};
......@@ -549,9 +551,11 @@ export class BlocksService extends AbstractService {
const dataArr = treasuryEvent[0].data.toJSON();
if (Array.isArray(dataArr)) {
const fee = (dataArr as Array<number>)[0];
const adjustedFee = tip ? tip.toBn().add(new BN(fee)) : new BN(fee);
const adjustedPartialFee = tip
? tip.toBn().add(partialFee)
: partialFee;
// The difference between values is 00.00001% or less so they are alike.
if (this.areFeesSimilar(adjustedFee, partialFee)) {
if (this.areFeesSimilar(new BN(fee), adjustedPartialFee)) {
return {
partialFee: fee.toString(),
};
......@@ -567,9 +571,9 @@ export class BlocksService extends AbstractService {
({ data }) =>
(sumOfFees = sumOfFees.add(new BN(data[data.length - 1].toString())))
);
const adjustedFee = tip ? tip.toBn().add(sumOfFees) : sumOfFees;
const adjustedPartialFee = tip ? tip.toBn().add(partialFee) : partialFee;
// The difference between values is 00.00001% or less so they are alike.
if (this.areFeesSimilar(adjustedFee, partialFee)) {
if (this.areFeesSimilar(sumOfFees, adjustedPartialFee)) {
return {
partialFee: sumOfFees.toString(),
};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment