|
1 | 1 | import { SignableENR } from '@chainsafe/enr'
|
2 | 2 | import type { BlockHeader, JsonRpcBlock } from '@ethereumjs/block'
|
3 | 3 | import { Block } from '@ethereumjs/block'
|
4 |
| -import { hexToBytes } from '@ethereumjs/util' |
| 4 | +import { hexToBytes, randomBytes } from '@ethereumjs/util' |
5 | 5 | import { keys } from '@libp2p/crypto'
|
6 | 6 | import { multiaddr } from '@multiformats/multiaddr'
|
7 | 7 | import { assert, beforeAll, describe, it } from 'vitest'
|
@@ -86,5 +86,35 @@ describe('should be able to retrieve ephemeral headers from a peer', () => {
|
86 | 86 | } else {
|
87 | 87 | assert.fail('Expected content in response')
|
88 | 88 | }
|
89 |
| - }) |
| 89 | + |
| 90 | + const contentKeyForOneAncestor = getContentKey(HistoryNetworkContentType.EphemeralHeader, { |
| 91 | + blockHash: headers[0].hash(), |
| 92 | + ancestorCount: 1, |
| 93 | + }) |
| 94 | + |
| 95 | + const res2 = await network2!.sendFindContent(node1.discv5.enr.toENR(), contentKeyForOneAncestor) |
| 96 | + assert.exists(res2) |
| 97 | + if ('content' in res2!) { |
| 98 | + const payload = EphemeralHeaderPayload.deserialize(res2.content) |
| 99 | + assert.equal(payload.length, 1, 'should only get a single ancestor') |
| 100 | + } else { |
| 101 | + assert.fail('Expected content in response') |
| 102 | + } |
| 103 | + |
| 104 | + // Verify that we get an empty ephemeral headers payload for a random blockhash |
| 105 | + const res3 = await network2!.sendFindContent( |
| 106 | + node1.discv5.enr.toENR(), |
| 107 | + getContentKey(HistoryNetworkContentType.EphemeralHeader, { |
| 108 | + blockHash: randomBytes(32), |
| 109 | + ancestorCount: 255, |
| 110 | + }), |
| 111 | + ) |
| 112 | + assert.exists(res3) |
| 113 | + if ('content' in res3!) { |
| 114 | + const payload = EphemeralHeaderPayload.deserialize(res3.content) |
| 115 | + assert.equal(payload.length, 0, 'should not get any headers for a random blockhash') |
| 116 | + } else { |
| 117 | + assert.fail('Expected content in response') |
| 118 | + } |
| 119 | + }, 10000) |
90 | 120 | })
|
0 commit comments