Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed May 26, 2023
1 parent f244975 commit 6d61c4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function beaconBlocksMaybeBlobsByRoot(

for (const block of allBlocks) {
const blockRoot = config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message);
const blobKzgCommitmentsLen = (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments.length ?? 0;
const blobKzgCommitmentsLen = (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments?.length ?? 0;
for (let index = 0; index < blobKzgCommitmentsLen; index++) {
blobIdentifiers.push({blockRoot, index});
}
Expand Down
33 changes: 20 additions & 13 deletions packages/beacon-node/test/unit/util/kzg.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {expect} from "chai";
import {bellatrix, deneb, ssz} from "@lodestar/types";
import {BLOB_TX_TYPE, BYTES_PER_FIELD_ELEMENT} from "@lodestar/params";
import {config} from "@lodestar/config/default";
import {createBeaconConfig} from "@lodestar/config";
import {
kzgCommitmentToVersionedHash,
OPAQUE_TX_BLOB_VERSIONED_HASHES_OFFSET,
Expand All @@ -9,7 +11,8 @@ import {

import {loadEthereumTrustedSetup, initCKZG, ckzg, FIELD_ELEMENTS_PER_BLOB_MAINNET} from "../../../src/util/kzg.js";
import {validateBlobSidecars, validateGossipBlobSidecar} from "../../../src/chain/validation/blobSidecar.js";
import {getDevBeaconNode} from "../../utils/node/beacon.js";
import {generateState} from "../../utils/state.js";
import {MockBeaconChain} from "../../utils/mocks/chain/chain.js";

describe("C-KZG", async () => {
const afterEachCallbacks: (() => Promise<unknown> | void)[] = [];
Expand Down Expand Up @@ -37,20 +40,24 @@ describe("C-KZG", async () => {
});

it("BlobSidecars", async () => {
const bn = await getDevBeaconNode({
params: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ALTAIR_FORK_EPOCH: 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
BELLATRIX_FORK_EPOCH: 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
CAPELLA_FORK_EPOCH: 0,
// eslint-disable-next-line @typescript-eslint/naming-convention
DENEB_FORK_EPOCH: 0,
const block = ssz.phase0.SignedBeaconBlock.defaultValue();
const state = generateState({
finalizedCheckpoint: {
epoch: 0,
root: ssz.phase0.BeaconBlock.hashTreeRoot(block.message),
},
});

afterEachCallbacks.push(() => bn.close());
const beaconConfig = createBeaconConfig(config, state.genesisValidatorsRoot);
const chain = new MockBeaconChain({
genesisTime: 0,
chainId: 0,
networkId: BigInt(0),
state,
config: beaconConfig,
});

afterEachCallbacks.push(() => chain.close());

const slot = 0;
const blobs = [generateRandomBlob(), generateRandomBlob()];
Expand Down Expand Up @@ -93,7 +100,7 @@ describe("C-KZG", async () => {
);

signedBlobSidecars.forEach(async (signedBlobSidecar) => {
await validateGossipBlobSidecar(bn.config, bn.chain, signedBlobSidecar, signedBlobSidecar.message.index);
await validateGossipBlobSidecar(chain.config, chain, signedBlobSidecar, signedBlobSidecar.message.index);
});
});
});
Expand Down

0 comments on commit 6d61c4c

Please sign in to comment.