Skip to content

Commit

Permalink
Fix createStubBlock bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Jan 12, 2025
1 parent be1e986 commit 934d940
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-forks-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/drift": patch
---

Fixed bigint parsing bug in `createStubBlock`
30 changes: 30 additions & 0 deletions packages/drift/src/adapter/utils/testing/createStubBlock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Block } from "src/adapter/types/Block";
import { createStubBlock } from "src/exports/testing";
import { describe, expect, it } from "vitest";

describe("createStubBlock", () => {
const hexRegex = /^0x[a-f0-9]*$/;

it("creates a stub block", () => {
const block = createStubBlock();
expect(block).toMatchObject({
extraData: expect.stringMatching(hexRegex),
gasLimit: expect.any(BigInt),
gasUsed: expect.any(BigInt),
hash: expect.stringMatching(hexRegex),
logsBloom: expect.stringMatching(hexRegex),
miner: expect.stringMatching(hexRegex),
mixHash: expect.stringMatching(hexRegex),
nonce: expect.any(BigInt),
number: expect.any(BigInt),
parentHash: expect.stringMatching(hexRegex),
receiptsRoot: expect.stringMatching(hexRegex),
sha3Uncles: expect.stringMatching(hexRegex),
size: expect.any(BigInt),
stateRoot: expect.stringMatching(hexRegex),
timestamp: expect.any(BigInt),
transactions: expect.any(Array),
transactionsRoot: expect.stringMatching(hexRegex),
} as Block);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createStubBlock(override: Partial<Block> = {}): Block {
sha3Uncles: getRandomHex(),
size: 100_000n,
stateRoot: getRandomHex(),
timestamp: BigInt(Date.now() / 1000),
timestamp: BigInt(Date.now()) / 1000n,
transactions: [],
transactionsRoot: getRandomHex(),
...override,
Expand Down

0 comments on commit 934d940

Please sign in to comment.