Skip to content

Commit

Permalink
Adds support for validation data different indexes (#94)
Browse files Browse the repository at this point in the history
* Adds support for validation data different indexes

* Optimize find to reduce type creations

* linted
  • Loading branch information
crystalin authored Dec 18, 2022
1 parent 9f34888 commit 4386ee5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions src/blockchain/inherents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
Expand All @@ -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>('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>('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>('GenericExtrinsic', validationDataExtrinsic)
.args[0].toJSON() as typeof MOCK_VALIDATION_DATA

const newEntries: [HexString, HexString][] = []
const upgrade = await parentBlock.get(compactHex(meta.query.parachainSystem.pendingValidationCode()))
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4386ee5

Please sign in to comment.