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

fix: cleanup tests

parent 872418cd
No related merge requests found
...@@ -3,6 +3,7 @@ import { ApiPromise } from '@polkadot/api'; ...@@ -3,6 +3,7 @@ import { ApiPromise } from '@polkadot/api';
import { AugmentedConst } from '@polkadot/api/types/consts'; import { AugmentedConst } from '@polkadot/api/types/consts';
import { RpcPromiseResult } from '@polkadot/api/types/rpc'; import { RpcPromiseResult } from '@polkadot/api/types/rpc';
import { GenericExtrinsic } from '@polkadot/types'; import { GenericExtrinsic } from '@polkadot/types';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import { GenericCall } from '@polkadot/types/generic'; import { GenericCall } from '@polkadot/types/generic';
import { import {
BalanceOf, BalanceOf,
...@@ -185,49 +186,61 @@ describe('BlocksService', () => { ...@@ -185,49 +186,61 @@ describe('BlocksService', () => {
calcFee?.calc_fee(BigInt(941325000000), 1247, BigInt(125000000)) calcFee?.calc_fee(BigInt(941325000000), 1247, BigInt(125000000))
).toBe('1257000075'); ).toBe('1257000075');
}); });
});
describe('BlocksService.getDecorateAndExtractWeight', () => {
const baseWeight = (125000000 as unknown) as AbstractInt;
it('Should extract extrinsicBaseWeight correctly when were in a non-polkadot the chain and the runtime is the same as the api', async () => {
const baseWeightObject = await blocksService[
'getDecorateAndExtractWeight'
](mockApi, ('0xParentHash' as unknown) as Hash, 16, 'westend');
it('Should fill the cache with decorated and runtimeVersion data when running on a Non-Polkadot-Kusama chain', async () => { expect(
// (mockApi.runtimeVersion BigInt(
// .specName as unknown) = polkadotRegistry.createType('Text', 'westend'); baseWeightObject['16'].decorated.consts.system.extrinsicBaseWeight
// await blocksService['createCalcFee']( )
// mockApi, ).toBe(BigInt(baseWeight));
// ('0xParentHash' as unknown) as Hash, });
// mockBlock789629
// ); it('Should extract extrinsicBaseWeight correctly when the block runtimeVersion matches the api', async () => {
// /** const baseWeightObject = await blocksService[
// * This checks to make sure the cache is updated. 'getDecorateAndExtractWeight'
// */ ](mockApi, ('0xParentHash' as unknown) as Hash, 16, 'polkadot');
// expect(that.cache.decorated).toBeTruthy();
// /** expect(
// * Check runtimeVersion. Westend's actual version might be different BigInt(
// * but because we are checking just createCalcFee we just need to make baseWeightObject['16'].decorated.consts.system.extrinsicBaseWeight
// * sure it stores the mockApi block's default runtime. )
// */ ).toBe(BigInt(baseWeight));
// expect(that.cache.runtimeVersion).toBe(16);
// (mockApi.runtimeVersion
// .specName as unknown) = polkadotRegistry.createType('Text', 'polkadot');
}); });
it('Should cache the correct block runtime when different from the api runtime', async () => { it('Should extract extrinsicBaseWeight correctly using expandMetadata when runtimes do not match ', async () => {
/** /**
* The mockApi take runtimeVersion is shared between the api and block * The default mockApi is runtimeVersion is 16 so we are testing it against 20
* so updating the mockApi runtimeVersion will update the version to be cached
* from the block.
*/ */
// (mockApi.runtimeVersion const baseWeightObject = await blocksService[
// .specVersion as unknown) = polkadotRegistry.createType('u32', 20); 'getDecorateAndExtractWeight'
// (mockApi.runtimeVersion ](mockApi, ('0xParentHash' as unknown) as Hash, 20, 'westend');
// .specName as unknown) = polkadotRegistry.createType('Text', 'westend');
// await blocksService['createCalcFee']( expect(
// mockApi, BigInt(
// ('0xParentHash' as unknown) as Hash, baseWeightObject['20'].decorated.consts.system.extrinsicBaseWeight
// mockBlock789629 )
// ); ).toBe(BigInt(baseWeight));
// expect(that.cache.runtimeVersion).toBe(20); });
// (mockApi.runtimeVersion
// .specVersion as unknown) = polkadotRegistry.createType('u32', 16); it('Should extract blockWeights correctly', async () => {
// (mockApi.runtimeVersion const baseWeightObject = await blocksService[
// .specName as unknown) = polkadotRegistry.createType('Text', 'polkadot'); 'getDecorateAndExtractWeight'
](mockApi, ('0xParentHash' as unknown) as Hash, 28, 'polkadot');
expect(
BigInt(
baseWeightObject['28'].decorated.consts.system.blockWeights?.perClass
.normal.baseExtrinsic
)
).toBe(BigInt(baseWeight));
}); });
}); });
......
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