diff --git a/e2e/helper.ts b/e2e/helper.ts index 59bed94d..8f0357da 100644 --- a/e2e/helper.ts +++ b/e2e/helper.ts @@ -58,7 +58,7 @@ const setupAll = async ({ endpoint, blockHash, mockSignatureHost, allowUnresolve now += 20000 return now }) - const inherents = new InherentProviders(setTimestamp, [new SetValidationData(tasks, 1)]) + const inherents = new InherentProviders(setTimestamp, [new SetValidationData(tasks)]) const chain = new Blockchain({ api, diff --git a/src/blockchain/inherents.ts b/src/blockchain/inherents.ts index c70bcc02..6fcf6b29 100644 --- a/src/blockchain/inherents.ts +++ b/src/blockchain/inherents.ts @@ -81,11 +81,9 @@ export class InherentProviders implements InherentProvider { export class SetValidationData implements CreateInherents { readonly #tasks: TaskManager - readonly #expectedIndex: number - constructor(tasks: TaskManager, expectedIndex: number) { + constructor(tasks: TaskManager) { this.#tasks = tasks - this.#expectedIndex = expectedIndex } async createInherents(meta: DecoratedMeta, _timestamp: number, parent: Block): Promise { @@ -106,8 +104,16 @@ export class SetValidationData implements CreateInherents { // chain started with genesis, mock 1st validationData newData = MOCK_VALIDATION_DATA } else { - const method = meta.registry.createType('GenericExtrinsic', extrinsics[this.#expectedIndex]) - const extrinsic = method.args[0].toJSON() as typeof MOCK_VALIDATION_DATA + const validationDataExtrinsic = extrinsics.find((extrinsic) => { + const firstArg = meta.registry.createType('GenericExtrinsic', extrinsic)?.args?.[0] + return firstArg && 'validationData' in firstArg + }) + if (!validationDataExtrinsic) { + throw new Error('Missing validation data from block') + } + const extrinsic = meta.registry + .createType('GenericExtrinsic', validationDataExtrinsic) + .args[0].toJSON() as typeof MOCK_VALIDATION_DATA const newEntries: [HexString, HexString][] = [] const upgrade = await parentBlock.get(compactHex(meta.query.parachainSystem.pendingValidationCode())) diff --git a/src/index.ts b/src/index.ts index 87e03523..5e9dea87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,7 +62,7 @@ export const setup = async (argv: Config) => { const setTimestamp = new SetTimestamp((newBlockNumber) => { return timestamp + (newBlockNumber - blockNumber) * 12000 // TODO: make this more flexible }) - const inherents = new InherentProviders(setTimestamp, [new SetValidationData(tasks, 1)]) + const inherents = new InherentProviders(setTimestamp, [new SetValidationData(tasks)]) const chain = new Blockchain({ api,