Skip to content

Commit

Permalink
fix: align BeaconBlockBody and BlindedBeaconBlockBody (ChainSafe#6782)
Browse files Browse the repository at this point in the history
* fix: align BeaconBlockBody and BlindedBeaconBlockBody

* Remove type hacks in test

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
  • Loading branch information
2 people authored and g11tech committed Jun 19, 2024
1 parent 81b993a commit e78ee55
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/types/src/electra/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const BlindedBeaconBlockBody = new ContainerType(
executionPayloadHeader: ExecutionPayloadHeader, // Modified in ELECTRA
blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges,
blobKzgCommitments: denebSsz.BeaconBlockBody.fields.blobKzgCommitments,
consolidations: new ListCompositeType(SignedConsolidation, MAX_CONSOLIDATIONS), // [New in Electra]
},
{typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true}
);
Expand Down
35 changes: 35 additions & 0 deletions packages/types/test/unit/blinded.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {describe, it, expect} from "vitest";
import {ForkName, isForkExecution} from "@lodestar/params";
import {ssz} from "../../src/index.js";

describe("blinded data structures", function () {
it("should have the same number of fields as non-blinded", () => {
const blindedTypes = [
{a: "BlindedBeaconBlockBody" as const, b: "BeaconBlockBody" as const},
{a: "ExecutionPayloadHeader" as const, b: "ExecutionPayload" as const},
];

for (const {a, b} of blindedTypes) {
for (const fork of Object.keys(ssz.allForks) as ForkName[]) {
if (!isForkExecution(fork)) {
continue;
}

const blindedType = ssz[fork][a];
if (blindedType === undefined) {
expect.fail(`fork: ${fork}, type ${a} is undefined`);
}

const type = ssz[fork][b];
if (type === undefined) {
expect.fail(`fork: ${fork}, type ${b} is undefined`);
}

expect(Object.keys(blindedType.fields).length).toBeWithMessage(
Object.keys(type.fields).length,
`fork: ${fork}, types ${a} and ${b} have different number of fields`
);
}
}
});
});

0 comments on commit e78ee55

Please sign in to comment.