-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
946 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/portalnetwork/test/networks/history/ephemeralHeader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { assert, describe, it } from 'vitest' | ||
import { blockHeaderFromRpc } from '@ethereumjs/block/header-from-rpc' | ||
import type { BlockHeader, JsonRpcBlock } from '@ethereumjs/block' | ||
import latestBlocks from './testData/latest3Blocks.json' | ||
import { | ||
EphemeralHeaderPayload, | ||
HistoryNetworkContentType, | ||
PortalNetwork, | ||
getContentKey, | ||
getEphemeralHeaderDbKey, | ||
} from '../../../src/index.js' | ||
import { hexToBytes } from '@ethereumjs/util' | ||
describe('ephemeral header handling', () => { | ||
it('should be able to store a valid ephemeral header payload', async () => { | ||
const node = await PortalNetwork.create({}) | ||
const network = node.network()['0x500b'] | ||
const headers: BlockHeader[] = [] | ||
headers.push(blockHeaderFromRpc(latestBlocks[0] as JsonRpcBlock, { setHardfork: true })) | ||
headers.push(blockHeaderFromRpc(latestBlocks[1] as JsonRpcBlock, { setHardfork: true })) | ||
headers.push(blockHeaderFromRpc(latestBlocks[2] as JsonRpcBlock, { setHardfork: true })) | ||
const headerPayload = EphemeralHeaderPayload.serialize(headers.map((h) => h.serialize())) | ||
const contentKey = getContentKey(HistoryNetworkContentType.EphemeralHeader, { | ||
blockHash: headers[0].hash(), | ||
ancestorCount: headers.length, | ||
}) | ||
await network?.store(contentKey, headerPayload) | ||
const storedHeaderPayload = await network?.get(getEphemeralHeaderDbKey(headers[0].hash())) | ||
assert.deepEqual(hexToBytes(storedHeaderPayload!), headers[0].serialize()) | ||
}) | ||
}) |
Oops, something went wrong.