Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Header not found timestamp field #366

Merged
merged 5 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- `timestamp` field missing on `Header`

### Changed
- Update header year to 2025 (#362)

Expand Down
1 change: 1 addition & 0 deletions packages/node/src/ethereum/utils.ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@ export function ethereumBlockToHeader(block: BlockContent | Block): Header {
blockHeight: block.number,
blockHash: block.hash,
parentHash: block.parentHash,
timestamp: new Date(Number(block.timestamp) * 1000),
};
}
9 changes: 9 additions & 0 deletions packages/node/src/indexer/unfinalizedBlocks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
// Adds 0 padding so we can convert to POI block
const hexify = (input: string) => hexZeroPad(input, 4);

// Mock 1740100000 is the timestamp of the genesis block
const genBlockTimestamp = (height: number) => (1740100000 + height) * 1000;
const genBlockDate = (height: number) => new Date(genBlockTimestamp(height));

const makeHeader = (height: number, finalized?: boolean): Header => ({
blockHeight: height,
blockHash: hexify(`0xABC${height}${finalized ? 'f' : ''}`),
parentHash: hexify(`0xABC${height - 1}${finalized ? 'f' : ''}`),
timestamp: genBlockDate(height),
});

const getMockApi = (): ApiService => {
Expand All @@ -42,12 +47,14 @@ const getMockApi = (): ApiService => {
number: num,
hash: typeof hash === 'number' ? hexify(`0xABC${hash}f`) : hash,
parentHash: hexify(`0xABC${num - 1}f`),
timestamp: genBlockTimestamp(num) / 1000,
});
},
getFinalizedBlock: jest.fn(() => ({
number: 110,
hash: '0xABC110f',
parentHash: '0xABC109f',
timestamp: genBlockTimestamp(110) / 1000,
})),
},
} as any;
Expand Down Expand Up @@ -164,6 +171,7 @@ describe('UnfinalizedBlockService', () => {
blockHash: '0x00ABC99f',
blockHeight: 99,
parentHash: '0x00ABC98f',
timestamp: genBlockDate(99),
});
});

Expand All @@ -188,6 +196,7 @@ describe('UnfinalizedBlockService', () => {
blockHash: '0x00ABC99f',
blockHeight: 99,
parentHash: '0x00ABC98f',
timestamp: genBlockDate(99),
});
});

Expand Down
Loading