Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expandMetadata for historic runtimes #692

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
polkadotRegistry,
polkadotRegistryV29,
} from '../../test-helpers/registries';
import { createApiWithAugmentations } from '../../test-helpers/typeFactory';
import { ExtBaseWeightValue, PerClassValue } from '../../types/chains-config';
import { IBlock, IExtrinsic } from '../../types/responses/';
import {
apiAt,
blockHash20000,
blockHash100000,
blockHash789629,
Expand Down Expand Up @@ -251,7 +253,13 @@ describe('BlocksService', () => {
Promise.resolve().then(() => polkadotMetadataV29);
const revertedMetadata = () =>
Promise.resolve().then(() => polkadotMetadata);
// Set this historic At to the tests current runtime
const historicAt = () =>
Promise.resolve().then(() =>
createApiWithAugmentations(polkadotMetadataV29.toHex())
);

(mockApi.at as unknown) = historicAt;
(mockApi.registry as unknown) = polkadotRegistryV29;
(mockApi.rpc.state.getMetadata as unknown) = changeMetadataToV29;

Expand All @@ -269,6 +277,7 @@ describe('BlocksService', () => {
.baseExtrinsic
).toBe(BigInt(512000000000001));

(mockApi.at as unknown) = apiAt;
(mockApi.registry as unknown) = polkadotRegistry;
(mockApi.rpc.state.getMetadata as unknown) = revertedMetadata;
});
Expand Down
3 changes: 2 additions & 1 deletion src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,10 @@ export class BlocksService extends AbstractService {
blockHash: BlockHash
): Promise<WeightValue> {
const metadata = await api.rpc.state.getMetadata(blockHash);
const historicApi = (await api.at(blockHash)) as ApiPromise;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TarikGul I suppose the registry contains metadata, chain info and other stuff that is required for that data to match for historical blocks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup exactly!

Example: The specific error that brought up this issue too was a type error where Westend has a Lookup36 type in its Metadata, but it didnt match the registry. So when trying to expand the metadata, types didn't align.

const {
consts: { system },
} = expandMetadata(api.registry, metadata);
} = expandMetadata(historicApi.registry, metadata);

let weightValue;
if ((system.blockWeights as unknown as BlockWeights)?.perClass) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/test-helpers/mock/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ const assetApprovals = () =>
return rococoRegistry.createType('Option<AssetApproval>', assetObj);
});

const apiAt = () =>
export const apiAt = (): Promise<ApiPromise> =>
Promise.resolve().then(() => {
return createApiWithAugmentations(polkadotMetadata.toHex());
});
Expand Down