Skip to content

Commit

Permalink
replaced mocked data of block 18207445 with those of block 18468942
Browse files Browse the repository at this point in the history
- in block 18468942 we have 2 upward msgs from two different parachains so with the same mocked data we can add 2 tests
- added a test to check the query param paraId is working as expected
  • Loading branch information
Imod7 committed Jan 12, 2024
1 parent 6ad6e16 commit 3e9982d
Show file tree
Hide file tree
Showing 13 changed files with 8,699 additions and 3,811 deletions.
2 changes: 1 addition & 1 deletion src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023 Parity Technologies (UK) Ltd.
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand Down
132 changes: 75 additions & 57 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,24 @@ import {
blockHash100000,
blockHash789629,
blockHash5831776,
blockHash18207445,
blockHash18468942,
defaultMockApi,
defaultMockApiBlock18207445,
mockApiBlock18468942,
mockAssetHubKusamaApiBlock5831776,
mockForkedBlock789629,
} from '../test-helpers/mock';
import block789629 from '../test-helpers/mock/data/block789629.json';
import { events789629 } from '../test-helpers/mock/data/events789629Hex';
import { events5831776 } from '../test-helpers/mock/data/events5831776Hex';
import { events18207445 } from '../test-helpers/mock/data/events18207445Hex';
import { events18468942 } from '../test-helpers/mock/data/events18468942Hex';
import { validators789629Hex } from '../test-helpers/mock/data/validators789629Hex';
import { validators5831776Hex } from '../test-helpers/mock/data/validators5831776Hex';
import { validators18207445Hex } from '../test-helpers/mock/data/validators18207445Hex';
import { validators18468942Hex } from '../test-helpers/mock/data/validators18468942Hex';
import { parseNumberOrThrow } from '../test-helpers/mock/parseNumberOrThrow';
import block789629Extrinsic from '../test-helpers/responses/blocks/block789629Extrinsic.json';
import block5831776Response from '../test-helpers/responses/blocks/block5831776.json';
import block18207445Response from '../test-helpers/responses/blocks/block18207445.json';
import block18468942Response from '../test-helpers/responses/blocks/block18468942.json';
import block18468942pId2000Response from '../test-helpers/responses/blocks/block18468942paraId2000.json';
import blocks789629Response from '../test-helpers/responses/blocks/blocks789629.json';
import blocks789629Raw from '../test-helpers/responses/blocks/blocks789629Raw.json';
import { BlocksService } from './BlocksService';
Expand Down Expand Up @@ -504,74 +505,91 @@ describe('BlocksService', () => {
noFees: false,
};

it('Should give back the decoded upward XCM message for Polkadot block 18207445', async () => {
// Reset LRU cache
cache.clear();
// Reset LRU cache
cache.clear();

const validatorsAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Vec<ValidatorId>', validators18207445Hex));
const validatorsAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Vec<ValidatorId>', validators18468942Hex));

const eventsAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Vec<EventRecord>', events18207445));
const eventsAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Vec<EventRecord>', events18468942));

const nextFeeMultiplierAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Fixed128', 1000000000));
const nextFeeMultiplierAt = (_hash: Hash) =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Fixed128', 1000000000));

const mockHistoricApiXCM = {
registry: polkadotRegistryV1000001,
call: {
transactionPaymentApi: {},
const mockHistoricApiXCM = {
registry: polkadotRegistryV1000001,
call: {
transactionPaymentApi: {},
},
consts: {
transactionPayment: {
transactionByteFee: polkadotRegistryV1000001.createType('Balance', 1000000),
weightToFee: [
{
coeffFrac: polkadotRegistryV1000001.createType('Perbill', 80000000),
coeffInteger: polkadotRegistryV1000001.createType('Balance', 0),
degree: polkadotRegistryV1000001.createType('u8', 1),
negative: false,
},
],
},
consts: {
transactionPayment: {
transactionByteFee: polkadotRegistryV1000001.createType('Balance', 1000000),
weightToFee: [
{
coeffFrac: polkadotRegistryV1000001.createType('Perbill', 80000000),
coeffInteger: polkadotRegistryV1000001.createType('Balance', 0),
degree: polkadotRegistryV1000001.createType('u8', 1),
negative: false,
},
],
},
system: {
extrinsicBaseWeight: polkadotRegistryV1000001.createType('u64', 125000000),
},
system: {
extrinsicBaseWeight: polkadotRegistryV1000001.createType('u64', 125000000),
},
query: {
session: {
validators: validatorsAt,
},
system: {
events: eventsAt,
},
transactionPayment: {
nextFeeMultiplier: nextFeeMultiplierAt,
},
},
query: {
session: {
validators: validatorsAt,
},
} as unknown as ApiDecoration<'promise'>;
system: {
events: eventsAt,
},
transactionPayment: {
nextFeeMultiplier: nextFeeMultiplierAt,
},
},
} as unknown as ApiDecoration<'promise'>;

const mockApiXCM = {
...defaultMockApiBlock18207445,
query: {
transactionPayment: {
nextFeeMultiplier: { at: nextFeeMultiplierAt },
},
const mockApiXCM = {
...mockApiBlock18468942,
query: {
transactionPayment: {
nextFeeMultiplier: { at: nextFeeMultiplierAt },
},
at: (_hash: Hash) => mockHistoricApiXCM,
} as unknown as ApiPromise;
},
at: (_hash: Hash) => mockHistoricApiXCM,
} as unknown as ApiPromise;

// Block Service
const blocksServiceXCM = new BlocksService(mockApiXCM, 0, cache, new QueryFeeDetailsCache(null, null));
const decodedXcmMsgsArg = true;
// Block Service
const blocksServiceXCM = new BlocksService(mockApiXCM, 0, cache, new QueryFeeDetailsCache(null, null));
const decodedXcmMsgsArg = true;

it('Should give back two decoded upward XCM messages for Polkadot block 18468942, one for paraId=2000 and one for paraId=2012', async () => {
const block = await blocksServiceXCM.fetchBlock(
blockHash18468942,
mockHistoricApiXCM,
options,
decodedXcmMsgsArg,
);

expect(sanitizeNumbers(block)).toMatchObject(block18468942Response);
});

it('Should give back one decoded upward XCM message for Polkadot block 18468942 only for paraId=2000', async () => {
// Reset LRU cache
cache.clear();

const paraId = '2000';
const block = await blocksServiceXCM.fetchBlock(
blockHash18207445,
blockHash18468942,
mockHistoricApiXCM,
options,
decodedXcmMsgsArg,
paraId,
);

expect(sanitizeNumbers(block)).toMatchObject(block18207445Response);
expect(sanitizeNumbers(block)).toMatchObject(block18468942pId2000Response);
});

it('Should give back the decoded horizontal XCM message for Kusama Asset Hub block 5831776', async () => {
Expand Down
28 changes: 0 additions & 28 deletions src/services/test-helpers/mock/data/block18207445.json

This file was deleted.

30 changes: 30 additions & 0 deletions src/services/test-helpers/mock/data/block18468942.json

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions src/services/test-helpers/mock/data/events18207445Hex.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/services/test-helpers/mock/data/events18468942Hex.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/services/test-helpers/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

export * from './addresses';
export * from './mockApi';
export * from './mockApiBlock18207445';
export * from './mockApiBlock18468942';
export * from './mockAssetHubKusamaApi';
export * from './mockAssetHubKusamaApiBlock5831776';
export * from './mockAssetHubWestendApi';
Expand All @@ -25,6 +25,6 @@ export * from './mockBlock789629';
export * from './mockBlock5236177';
export * from './mockBlock5831776';
export * from './mockBlock13641102';
export * from './mockBlock18207445';
export * from './mockBlock18468942';
export * from './mockBlockHashes';
export * from './transactions';
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import BN from 'bn.js';

import { polkadotMetadataRpcV1000001 } from '../../../test-helpers/metadata/polkadotV1000001Metadata';
import { polkadotRegistryV1000001 } from '../../../test-helpers/registries';
import { balancesTransferValid, blockHash18207445, mockBlock18207445, testAddressController } from '.';
import { balancesTransferValid, blockHash18468942, mockBlock18468942, testAddressController } from '.';
import { localListenAddressesHex } from './data/localListenAddresses';
import { getPalletDispatchables } from './data/mockDispatchablesData';
import { getMetadata as mockMetaData } from './data/mockNonimationPoolResponseData';
Expand All @@ -46,19 +46,19 @@ const chain = () =>
export const getBlockXCM = (_hash: Hash): Promise<{ block: Block }> =>
Promise.resolve().then(() => {
return {
block: mockBlock18207445,
block: mockBlock18468942,
};
});

export const deriveGetBlockXCM = (_hash: Hash): Promise<{ block: Block; author: AccountId }> =>
Promise.resolve().then(() => {
return {
author: polkadotRegistryV1000001.createType('AccountId', '1VzLR7pDbcSsJqXHaRZFzwCtSgjNWEcLddSfWij7Jx3p8FK'),
block: mockBlock18207445,
author: polkadotRegistryV1000001.createType('AccountId', '16A1zLQ3KjMnxch1NAU44hoijFK3fHUjqb11bVgcHCfoj9z3'),
block: mockBlock18468942,
};
});

const getHeader = (_hash: Hash) => Promise.resolve().then(() => mockBlock18207445.header);
const getHeader = (_hash: Hash) => Promise.resolve().then(() => mockBlock18468942.header);

const runtimeVersion = {
specName: polkadotRegistryV1000001.createType('Text', 'polkadot'),
Expand All @@ -79,7 +79,7 @@ const getMetadata = () => Promise.resolve().then(() => polkadotMetadataRpcV10000
const deriveGetHeader = () =>
Promise.resolve().then(() => {
return {
author: polkadotRegistryV1000001.createType('AccountId', '1VzLR7pDbcSsJqXHaRZFzwCtSgjNWEcLddSfWij7Jx3p8FK'),
author: polkadotRegistryV1000001.createType('AccountId', '16A1zLQ3KjMnxch1NAU44hoijFK3fHUjqb11bVgcHCfoj9z3'),
};
});

Expand Down Expand Up @@ -162,7 +162,7 @@ const properties = () =>
}),
);

const getFinalizedHead = () => Promise.resolve().then(() => blockHash18207445);
const getFinalizedHead = () => Promise.resolve().then(() => blockHash18468942);

const health = () =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('Health', '0x7a000000000000000001'));
Expand All @@ -189,10 +189,10 @@ const traceBlock = () =>
Promise.resolve().then(() => polkadotRegistryV1000001.createType('TraceBlockResponse', traceBlockRPC.result));

/**
* Deafult Mock polkadot-js ApiPromise. Values are largely meant to be accurate for block
* #18207445, which is what the XCM test in BlockService use.
* Mock polkadot-js ApiPromise. Values are largely meant to be accurate for block
* #18468942, which is what the XCM test in BlockService use.
*/
export const defaultMockApiBlock18207445 = {
export const mockApiBlock18468942 = {
runtimeVersion,
call: {
transactionPaymentApi: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { polkadotRegistryV1000001 } from '../../../test-helpers/registries';
import block18207445 from './data/block18207445.json';
import block18468942 from './data/block18468942.json';

/**
* Mock for Polkadot Block #18207445.
* Mock for Polkadot Block #18468942.
*/
export const mockBlock18207445 = polkadotRegistryV1000001.createType('Block', block18207445);
export const mockBlock18468942 = polkadotRegistryV1000001.createType('Block', block18468942);

/**
* BlockHash for Polkadot Block #18207445.
* BlockHash for Polkadot Block #18468942.
*/
export const blockHash18207445 = polkadotRegistryV1000001.createType(
export const blockHash18468942 = polkadotRegistryV1000001.createType(
'BlockHash',
'0xc759aa0846fb1d608f8ac36d7f66b202dbe1424bd6b36ff7b0d2bb7b79cce055',
'0x1ffece02b91e52c4923827843774f705911905c0a66980f7037bed643b746d1d',
);
Loading

0 comments on commit 3e9982d

Please sign in to comment.