Skip to content

Commit

Permalink
added a test for decoding upward msg in polkadot block
Browse files Browse the repository at this point in the history
  • Loading branch information
Imod7 committed Jan 3, 2024
1 parent 7339cab commit 23cad30
Show file tree
Hide file tree
Showing 12 changed files with 4,190 additions and 6 deletions.
91 changes: 89 additions & 2 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 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 Expand Up @@ -26,20 +26,25 @@ import LRU from 'lru-cache';
import { QueryFeeDetailsCache } from '../../chains-config/cache';
import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { createCall } from '../../test-helpers/createCall';
import { kusamaRegistry, polkadotRegistry } from '../../test-helpers/registries';
import { kusamaRegistry, polkadotRegistry, polkadotRegistryV1000001 } from '../../test-helpers/registries';
import { IBlock } from '../../types/responses/';
import {
blockHash20000,
blockHash100000,
blockHash789629,
blockHash18207445,
defaultMockApi,
defaultMockApiXCM,
mockForkedBlock789629,
} from '../test-helpers/mock';
import block789629 from '../test-helpers/mock/data/block789629.json';
import { events789629 } from '../test-helpers/mock/data/events789629Hex';
import { events18207445 } from '../test-helpers/mock/data/events18207445Hex';
import { validators789629Hex } from '../test-helpers/mock/data/validators789629Hex';
import { validators18207445Hex } from '../test-helpers/mock/data/validators18207445Hex';
import { parseNumberOrThrow } from '../test-helpers/mock/parseNumberOrThrow';
import block789629Extrinsic from '../test-helpers/responses/blocks/block789629Extrinsic.json';
import block18207445Response from '../test-helpers/responses/blocks/block18207445.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 @@ -477,4 +482,86 @@ describe('BlocksService', () => {
expect(sanitizeNumbers(await blocksService.fetchBlockRaw(blockHash789629))).toMatchObject(blocks789629Raw);
});
});

describe('fetch XCM Decoded Msgs in polkadot blocks 18207445', () => {
it('Should give back XCM', async () => {
// Reset LRU cache
cache.clear();

// fetchBlock options
const options = {
eventDocs: true,
extrinsicDocs: true,
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: false,
noFees: false,
};

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

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

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

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,
},
],
},
system: {
extrinsicBaseWeight: polkadotRegistryV1000001.createType('u64', 125000000),
},
},
query: {
session: {
validators: validatorsAt,
},
system: {
events: eventsAt,
},
transactionPayment: {
nextFeeMultiplier: nextFeeMultiplierAt,
},
},
} as unknown as ApiDecoration<'promise'>;

const mockApiXCM = {
...defaultMockApiXCM,
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 block = await blocksServiceXCM.fetchBlock(
blockHash18207445,
mockHistoricApiXCM,
options,
decodedXcmMsgsArg,
);

expect(sanitizeNumbers(block)).toMatchObject(block18207445Response);
});
});
});
2 changes: 1 addition & 1 deletion src/services/blocks/BlocksService.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
2 changes: 1 addition & 1 deletion src/services/blocks/XCMDecoder.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
28 changes: 28 additions & 0 deletions src/services/test-helpers/mock/data/block18207445.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/services/test-helpers/mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 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 All @@ -16,11 +16,13 @@

export * from './addresses';
export * from './mockApi';
export * from './mockApiBlockXCM';
export * from './mockAssetHubKusamaApi';
export * from './mockAssetHubWestendApi';
export * from './mockBlock523510';
export * from './mockBlock789629';
export * from './mockBlock5236177';
export * from './mockBlock13641102';
export * from './mockBlock18207445';
export * from './mockBlockHashes';
export * from './transactions';
Loading

0 comments on commit 23cad30

Please sign in to comment.