Skip to content

Commit

Permalink
added test to check if query param paraId works correctly also in hor…
Browse files Browse the repository at this point in the history
…izontal msgs
  • Loading branch information
Imod7 committed Jan 15, 2024
1 parent bd35e99 commit 3b037d4
Show file tree
Hide file tree
Showing 10 changed files with 1,092 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { createCall } from '../../test-helpers/createCall';
import {
assetHubKusamaRegistryV1000000,
assetHubKusamaRegistryV1000000b,
kusamaRegistry,
polkadotRegistry,
polkadotRegistryV1000001,
Expand All @@ -39,21 +40,26 @@ import {
blockHash789629,
blockHash3356195,
blockHash18468942,
blockHash6202603,
defaultMockApi,
mockApiBlock18468942,
mockAssetHubKusamaApiBlock3356195,
mockAssetHubKusamaApiBlock6202603,
mockForkedBlock789629,
} from '../test-helpers/mock';
import block789629 from '../test-helpers/mock/data/block789629.json';
import { events789629 } from '../test-helpers/mock/data/events789629Hex';
import { events3356195 } from '../test-helpers/mock/data/events3356195Hex';
import { events6202603 } from '../test-helpers/mock/data/events6202603Hex';
import { events18468942 } from '../test-helpers/mock/data/events18468942Hex';
import { validators789629Hex } from '../test-helpers/mock/data/validators789629Hex';
import { validators3356195Hex } from '../test-helpers/mock/data/validators3356195Hex';
import { validators6202603Hex } from '../test-helpers/mock/data/validators6202603Hex';
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 block3356195Response from '../test-helpers/responses/blocks/block3356195.json';
import block6202603pId2087Response from '../test-helpers/responses/blocks/block6202603paraId2087.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';
Expand Down Expand Up @@ -658,5 +664,73 @@ describe('BlocksService', () => {

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

it('Should give back one of the two available horizontal messages, the one for paraId 2087 for Kusama Asset Hub block 6202603', async () => {
// Reset LRU cache
cache.clear();

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

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

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

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

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

// Block Service
const blocksServiceXCM = new BlocksService(mockApiXCM, 0, cache, new QueryFeeDetailsCache(null, null));
const decodedXcmMsgsArg = true;
const paraId = '2087';
const block = await blocksServiceXCM.fetchBlock(blockHash6202603, mockHistoricApiXCM, options, decodedXcmMsgsArg, paraId);

Check failure on line 731 in src/services/blocks/BlocksService.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `blockHash6202603,·mockHistoricApiXCM,·options,·decodedXcmMsgsArg,·paraId` with `⏎↹↹↹↹blockHash6202603,⏎↹↹↹↹mockHistoricApiXCM,⏎↹↹↹↹options,⏎↹↹↹↹decodedXcmMsgsArg,⏎↹↹↹↹paraId,⏎↹↹↹`

expect(sanitizeNumbers(block)).toMatchObject(block6202603pId2087Response);
});
});
});
35 changes: 35 additions & 0 deletions src/services/test-helpers/mock/data/block6202603.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/services/test-helpers/mock/data/events6202603Hex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export const events6202603 =
'0x48020a026d6f646c506f745374616b65000000000000000000000000000000000000000056495460066a5fab4be4b0634c41f0e550f4f3e4d3436924364ce98d8678372d950200000000000000000000000000000000000000003203c00700007369626c2708000000000000000000000000000000000000000000000000000000a3e1110000000000000000000000000000000000003201c00700003ad7d92add30a4e4c7623b5c4731d11366e485a70b132b1678528b555de34e1ef794e1110000000000000000000000000000000000003201c007000056495460066a5fab4be4b0634c41f0e550f4f3e4d3436924364ce98d8678372d090e00000000000000000000000000000000000000001e00a8aa72a4ff80948a406bced0602be649bd10cf247d63642e4d16a635a26c5cbba8aa72a4ff80948a406bced0602be649bd10cf247d63642e4d16a635a26c5cbba23f304a25380000000000003203c00700007369626c3e080000000000000000000000000000000000000000000000000000806676070000000000000000000000000000000000003201c00700003ad7d92add30a4e4c7623b5c4731d11366e485a70b132b1678528b555de34e1e775876070000000000000000000000000000000000003201c007000056495460066a5fab4be4b0634c41f0e550f4f3e4d3436924364ce98d8678372d090e00000000000000000000000000000000000000001e00f91c8586b44b0f94146b25fb378b44c3f9978aca96797b3e7cafcc74f126b032f91c8586b44b0f94146b25fb378b44c3f9978aca96797b3e7cafcc74f126b032a23f304a253800000000000000000265cd1d00020100000100000000002220bd43551702000000020000000a0814c8e8b6a677a898ec5eb3ff2af5af089227112fc963884b9fd54f24937f5b4d1288d5030000000000000000000000000000020000000003252da31449ccb01825acfd81e9aec77529f833febb6a34865c4e47369290bab70000020000000a00252da31449ccb01825acfd81e9aec77529f833febb6a34865c4e47369290bab700f2052a0100000000000000000000000000020000000a0214c8e8b6a677a898ec5eb3ff2af5af089227112fc963884b9fd54f24937f5b4d252da31449ccb01825acfd81e9aec77529f833febb6a34865c4e47369290bab700f2052a0100000000000000000000000000020000000a076d6f646c506f745374616b6500000000000000000000000000000000000000001288d5030000000000000000000000000000020000000b0014c8e8b6a677a898ec5eb3ff2af5af089227112fc963884b9fd54f24937f5b4d1288d503000000000000000000000000000000000000000000000000000000000000020000000000a25ea5472538000000';
18 changes: 18 additions & 0 deletions src/services/test-helpers/mock/data/validators6202603Hex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export const validators6202603Hex =
'0x38424ecaa1e5d069bb89c743c3ddb44d9cb023aff0ad78e3c502bd39b0abbf77155009e192ec169788c9c1f0202fe7c2bc79405ff8b6e1d1ac78fd6152006e606d50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d3497305ecc1b0043fe1fc18950cef3726fa74151bc41f77438ce924c11a9b43823ff43c46ff658221e07564fde2764017590264f9dfced3538e283856c43e0ee456e51d4e6d6256f56677bcdbc0543f1a2c40aa82497b33af1748fc10113b1e2a1b460f00168a3d082a8ccf93945b1f173fdaecc1ce76fc09bbde18423640194be7212fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a00c703a1cde92ffaf1f8312c1fdb3a81140f7e76789d55ae1f0683025c4286493a6a0745688c52b4709f65fa2e4508dfa0940ccc0d282cd16be9bc043b2f4a04e5c49f7bc76b9e1b91566945e2eb539d960da57ca8e9ccd0e6030e4b11b60099da9f7fd3d9612a68d2ead69dde53297b172b7db514d0d261e7c5be987df7f32a56495460066a5fab4be4b0634c41f0e550f4f3e4d3436924364ce98d8678372d6610a5024c2a5db3d02056d4344d120ec7be283100d71a6715f09275167e4f38';
2 changes: 2 additions & 0 deletions src/services/test-helpers/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export * from './mockApi';
export * from './mockApiBlock18468942';
export * from './mockAssetHubKusamaApi';
export * from './mockAssetHubKusamaApiBlock3356195';
export * from './mockAssetHubKusamaApiBlock6202603';
export * from './mockAssetHubWestendApi';
export * from './mockBlock523510';
export * from './mockBlock789629';
export * from './mockBlock3356195';
export * from './mockBlock5236177';
export * from './mockBlock6202603';
export * from './mockBlock13641102';
export * from './mockBlock18468942';
export * from './mockBlockHashes';
Expand Down
Loading

0 comments on commit 3b037d4

Please sign in to comment.