Skip to content

Commit e6c2f37

Browse files
committed
Fix broken test
1 parent 51a4a6e commit e6c2f37

2 files changed

Lines changed: 112 additions & 99 deletions

File tree

Lines changed: 111 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { readFileSync } from 'fs'
22
import { ssz } from '@lodestar/types'
3-
import { concatBytes, hexToBytes } from '@ethereumjs/util'
3+
import { bytesToHex, concatBytes, hexToBytes } from '@ethereumjs/util'
44
import {
5-
BeaconLightClientNetworkContentType,
6-
HistoricalSummariesKey,
7-
HistoricalSummariesWithProof,
8-
HistoryNetworkContentType,
9-
LightClientBootstrapKey,
10-
NetworkId,
11-
PortalNetwork,
12-
getBeaconContentKey,
13-
getContentKey
5+
BeaconLightClientNetworkContentType,
6+
BlockHeaderWithProof,
7+
HistoricalSummariesKey,
8+
HistoricalSummariesWithProof,
9+
HistoryNetworkContentType,
10+
LightClientBootstrapKey,
11+
NetworkId,
12+
PortalNetwork,
13+
getBeaconContentKey,
14+
getContentKey,
1415
} from '../../src/index.js'
1516
import { createBeaconConfig } from '@lodestar/config'
1617
import { mainnetChainConfig } from '@lodestar/config/configs'
@@ -20,93 +21,105 @@ import { assert, describe, it, vi } from 'vitest'
2021
import { multiaddr } from '@multiformats/multiaddr'
2122
import { SignableENR } from '@chainsafe/enr'
2223
import { keys } from '@libp2p/crypto'
23-
24+
import { BlockHeader } from '@ethereumjs/block'
2425

2526
describe('Block Bridge Data Test', () => {
26-
it('should store and retrieve block header data', async () => {
27-
vi.useFakeTimers({ shouldAdvanceTime: true, shouldClearNativeTimers: true })
28-
vi.setSystemTime(1737151319000)
29-
const privateKeys = [
30-
'0x0a2700250802122102273097673a2948af93317235d2f02ad9cf3b79a34eeb37720c5f19e09f11783c12250802122102273097673a2948af93317235d2f02ad9cf3b79a34eeb37720c5f19e09f11783c1a2408021220aae0fff4ac28fdcdf14ee8ecb591c7f1bc78651206d86afe16479a63d9cb73bd',
31-
'0x0a27002508021221039909a8a7e81dbdc867480f0eeb7468189d1e7a1dd7ee8a13ee486c8cbd743764122508021221039909a8a7e81dbdc867480f0eeb7468189d1e7a1dd7ee8a13ee486c8cbd7437641a2408021220c6eb3ae347433e8cfe7a0a195cc17fc8afcd478b9fb74be56d13bccc67813130',
32-
]
33-
const pk1 = keys.privateKeyFromProtobuf(hexToBytes(privateKeys[0]).slice(-36))
34-
const enr1 = SignableENR.createFromPrivateKey(pk1)
35-
const initMa: any = multiaddr(`/ip4/127.0.0.1/udp/5033`)
36-
37-
const client = await PortalNetwork.create({
38-
supportedNetworks: [{ networkId: NetworkId.HistoryNetwork }, { networkId: NetworkId.BeaconChainNetwork }], config: { enr: enr1, bindAddrs: { ip4: initMa }, privateKey: pk1 }
39-
})
40-
await client.start()
41-
42-
const bootstrapHex = JSON.parse(readFileSync('./test/integration/testdata/postCapellaData/bootstrap.json', 'utf8'))
43-
const historicalSummariesJson = JSON.parse(readFileSync('./test/integration/testdata/postCapellaData/historical_summaries.json', 'utf8'))
44-
const fullBlock = JSON.parse(readFileSync('./test/integration/testdata/postCapellaData/full_block.json', 'utf8'))
45-
const headerWithProof = JSON.parse(readFileSync('./test/integration/testdata/postCapellaData/header_with_proof.json', 'utf8'))
46-
47-
const bootstrap = ssz.deneb.LightClientBootstrap.deserialize(hexToBytes(bootstrapHex.bootstrap))
48-
const bootstrapRoot = '0x47a956b9cd45c73a60dac4c89dc869a5faa46a9d5d802486f31025c74d41ef39'
49-
50-
// Get fork info
51-
const forkConfig = getChainForkConfigFromNetwork('mainnet')
52-
const bootstrapSlot = bootstrap.header.beacon.slot
53-
const forkName = forkConfig.getForkName(bootstrapSlot)
54-
const forkDigest = createBeaconConfig(
55-
mainnetChainConfig,
56-
hexToBytes(genesisData.mainnet.genesisValidatorsRoot)
57-
).forkName2ForkDigest(forkName)
58-
59-
// Store bootstrap
60-
61-
const bootstrapKey = getBeaconContentKey(
62-
BeaconLightClientNetworkContentType.LightClientBootstrap,
63-
LightClientBootstrapKey.serialize({ blockHash: hexToBytes(bootstrapRoot) })
64-
)
65-
const bootstrapValue = concatBytes(
66-
forkDigest,
67-
ssz.deneb.LightClientBootstrap.serialize(bootstrap)
68-
)
69-
70-
71-
const beacon = client.network()['0x500c']
72-
const history = client.network()['0x500b']
73-
74-
await beacon?.store(bootstrapKey, bootstrapValue)
75-
76-
// Start light client
77-
await beacon?.initializeLightClient(bootstrapRoot)
78-
79-
const historicalSummariesEpoch = computeEpochAtSlot(bootstrapSlot)
80-
81-
// Store historical summaries
82-
const historicalSummariesObj = HistoricalSummariesWithProof.fromJson({
83-
epoch: historicalSummariesEpoch,
84-
historical_summaries: historicalSummariesJson.historical_summaries,
85-
proof: historicalSummariesJson.proof
86-
})
87-
const summariesKey = getBeaconContentKey(
88-
BeaconLightClientNetworkContentType.HistoricalSummaries,
89-
HistoricalSummariesKey.serialize({ epoch: BigInt(historicalSummariesEpoch) })
90-
)
91-
const summariesValue = concatBytes(
92-
forkDigest,
93-
HistoricalSummariesWithProof.serialize(historicalSummariesObj)
94-
)
95-
await beacon?.store(summariesKey, summariesValue)
96-
97-
// Store header with proof
98-
const blockHash = fullBlock.data.message.body.execution_payload.block_hash
99-
100-
const headerKey = getContentKey(
101-
HistoryNetworkContentType.BlockHeader,
102-
hexToBytes(blockHash)
103-
)
104-
await history?.store(headerKey, hexToBytes(headerWithProof))
105-
106-
// Verify block header can be retrieved
107-
const retrievedHeader = await client.ETH.getBlockByHash(hexToBytes(blockHash), false)
108-
assert.equal(retrievedHeader!.header.number, fullBlock.data.message.body.execution_payload.block_number)
109-
110-
await client.stop()
111-
}, 10000)
112-
})
27+
it('should store and retrieve block header data', async () => {
28+
vi.useFakeTimers({ shouldAdvanceTime: true, shouldClearNativeTimers: true })
29+
vi.setSystemTime(1737151319000)
30+
const privateKeys = [
31+
'0x0a2700250802122102273097673a2948af93317235d2f02ad9cf3b79a34eeb37720c5f19e09f11783c12250802122102273097673a2948af93317235d2f02ad9cf3b79a34eeb37720c5f19e09f11783c1a2408021220aae0fff4ac28fdcdf14ee8ecb591c7f1bc78651206d86afe16479a63d9cb73bd',
32+
'0x0a27002508021221039909a8a7e81dbdc867480f0eeb7468189d1e7a1dd7ee8a13ee486c8cbd743764122508021221039909a8a7e81dbdc867480f0eeb7468189d1e7a1dd7ee8a13ee486c8cbd7437641a2408021220c6eb3ae347433e8cfe7a0a195cc17fc8afcd478b9fb74be56d13bccc67813130',
33+
]
34+
const pk1 = keys.privateKeyFromProtobuf(hexToBytes(privateKeys[0]).slice(-36))
35+
const enr1 = SignableENR.createFromPrivateKey(pk1)
36+
const initMa: any = multiaddr(`/ip4/127.0.0.1/udp/5033`)
37+
38+
const client = await PortalNetwork.create({
39+
supportedNetworks: [
40+
{ networkId: NetworkId.HistoryNetwork },
41+
{ networkId: NetworkId.BeaconChainNetwork },
42+
],
43+
config: { enr: enr1, bindAddrs: { ip4: initMa }, privateKey: pk1 },
44+
})
45+
await client.start()
46+
47+
const bootstrapHex = JSON.parse(
48+
readFileSync('./test/integration/testdata/postCapellaData/bootstrap.json', 'utf8'),
49+
)
50+
const historicalSummariesJson = JSON.parse(
51+
readFileSync('./test/integration/testdata/postCapellaData/historical_summaries.json', 'utf8'),
52+
)
53+
const fullBlock = JSON.parse(
54+
readFileSync('./test/integration/testdata/postCapellaData/full_block.json', 'utf8'),
55+
)
56+
const headerWithProof = JSON.parse(
57+
readFileSync('./test/integration/testdata/postCapellaData/header_with_proof.json', 'utf8'),
58+
)
59+
60+
const bootstrap = ssz.deneb.LightClientBootstrap.deserialize(hexToBytes(bootstrapHex.bootstrap))
61+
const bootstrapRoot = '0x47a956b9cd45c73a60dac4c89dc869a5faa46a9d5d802486f31025c74d41ef39'
62+
63+
// Get fork info
64+
const forkConfig = getChainForkConfigFromNetwork('mainnet')
65+
const bootstrapSlot = bootstrap.header.beacon.slot
66+
const forkName = forkConfig.getForkName(bootstrapSlot)
67+
const forkDigest = createBeaconConfig(
68+
mainnetChainConfig,
69+
hexToBytes(genesisData.mainnet.genesisValidatorsRoot),
70+
).forkName2ForkDigest(forkName)
71+
72+
// Store bootstrap
73+
74+
const bootstrapKey = getBeaconContentKey(
75+
BeaconLightClientNetworkContentType.LightClientBootstrap,
76+
LightClientBootstrapKey.serialize({ blockHash: hexToBytes(bootstrapRoot) }),
77+
)
78+
const bootstrapValue = concatBytes(
79+
forkDigest,
80+
ssz.deneb.LightClientBootstrap.serialize(bootstrap),
81+
)
82+
83+
const beacon = client.network()['0x500c']
84+
const history = client.network()['0x500b']
85+
86+
await beacon?.store(bootstrapKey, bootstrapValue)
87+
88+
// Start light client
89+
await beacon?.initializeLightClient(bootstrapRoot)
90+
91+
const historicalSummariesEpoch = computeEpochAtSlot(bootstrapSlot)
92+
93+
// Store historical summaries
94+
const historicalSummariesObj = HistoricalSummariesWithProof.fromJson({
95+
epoch: historicalSummariesEpoch,
96+
historical_summaries: historicalSummariesJson.historical_summaries,
97+
proof: historicalSummariesJson.proof,
98+
})
99+
const summariesKey = getBeaconContentKey(
100+
BeaconLightClientNetworkContentType.HistoricalSummaries,
101+
HistoricalSummariesKey.serialize({ epoch: BigInt(historicalSummariesEpoch) }),
102+
)
103+
const summariesValue = concatBytes(
104+
forkDigest,
105+
HistoricalSummariesWithProof.serialize(historicalSummariesObj),
106+
)
107+
await beacon?.store(summariesKey, summariesValue)
108+
109+
// Store header with proof
110+
const blockHash = fullBlock.data.message.body.execution_payload.block_hash
111+
112+
const headerKey = getContentKey(HistoryNetworkContentType.BlockHeader, hexToBytes(blockHash))
113+
console.log(bytesToHex(BlockHeaderWithProof.deserialize(hexToBytes(headerWithProof)).header))
114+
await history?.store(headerKey, hexToBytes(headerWithProof))
115+
116+
// Verify block header can be retrieved
117+
const retrievedHeader = await client.ETH.getBlockByHash(hexToBytes(blockHash), false)
118+
assert.equal(
119+
retrievedHeader!.header.number,
120+
fullBlock.data.message.body.execution_payload.block_number,
121+
)
122+
123+
await client.stop()
124+
}, 10000)
125+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"0x080000006f020000f90264a01624e3d62872568e41233178997c38dd75fa3baccc89351026beff7026179bfba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347944838b106fce9647bdf1e7877bf73ce8b0bad5f97a02e065520386645261b7a6153924904a31c07bf6d37bca90fe35b21d864499c05a0eaa4d1ba5182915e8732ddd43e557a6ec713732e72964593275124fddf28a2aba0a9f528fe24151b34969ceb581a59f107d7bf38d8f364072dd50908f326226e71b90100f5bbd9423d137076afdb9b31d2f1db9239cff06e951d0dee6e2d8a302cfb14632d9c2725ed7a08043a5f6e97df7dc311867ba9749f08ed735fbb6a03802ce196f5eed77c97d3bd3dc81ce76fdd61b3ec55cc71d511567e685d0c2cec8c24ffee35856338dae6da75f20f9c8efe338fcffb7d515fde9d7fe7f5305bb4da1a3585a3be7e0e378581692dd9bbfa95b1c7565419eed5eff471ff29296fdd7d733efddfec7f62e4e3fa9eb3f159c609c7dd5f23bdd1b4baff8e283f65ea3d24680bd4cb36f61f00dd5b56ff49bdb77a3d98ee56a7b6438c48dfba4aa5034e6ad3e2e63ff7fccb69b5b492c5ed93cffd71a92e5dddf6ff5161ace6da24c0bb9d00ec5f8084014977bd8401c9c38083f94439846780b05798546974616e2028746974616e6275696c6465722e78797a29a07737f9743d49ab14e32b78a4989729b13bfd28f09c7729669d14c35a3e265d5288000000000000000084bc232c85a01fd1ee2a1b4008ac9f8749a3a5980645510788ccbf0922b77efd67224f8a2234830200008403cc0000a0e1c45ed325063d2380fb27927e7dd5024dada52070c9af2889ee51a105040bcf03cc0100003a317faa00ffbca7c1fc9464025ada6aa0db71fd9c050ed433bab104834f0f26c2c38585972af1a49f5358e96748e08f62d9e06883d6d3bbc285f5bbdc3fdde7b87b8f3009f2311f723310e9600cd62f3a0ba54257645d03dbb94700997c2ff1bea5a1dbb8434febb2338912ebd94cfb183cc76b79a1449374aca82445a60e1641d6c37404381727480db4e3e124c9ce9345eb3761882ba31a2444e19f7f4be6446d9460a465986305984f731af89318ee7a965c33d5f6e293bd7c77050a7275d50d2f96d67ae9ec187ef09d1c19c8688ad0a9c00675a55bf61e5e412d5b0b309b9b4a4f9baaa4e6d6cd518eb62f41a133594cab49cf290ffa3570b65376b9dab2632457193d929218ee57d4d2dc8df537f9e2929746d934595d00ff258485173737414bac51a48ca8e03d442cca16a9d9d485ff0447a52427aada4c790ac75fdb8c75ab9503bd1eb67bfb5e2f8f403654b57a1e206aac23546088f1d7284b27d0fc56523cfafc7fb5d233f5faee241365fa4cb0c1d90792d8b558a3d0d5a63121993447a9a5d26cda2d9ad060c8d13f66d84623cc800e3dbb00097ce81a4debe6e5bf0ec7b02915aefabb6e7b1fb8468f228ab04e8e789a26ad9d727ac8430400e0a40000000000f5a23c1219f35dd7d4dc73e816727b6062b26168d5de32a8c44a5e91eeca9f1e04a8748db8fd9595375edfe16660a66ca721079109bd18775eeb54ce07b1400f37d1c9f9c839443ae1aff0d273f1801ffe724770a23d81a63f22f7babe39715d5b5687af2260ef0ed892a68d169c580b03ccb5bc59b0596a4221568de8bf1c7091e37807ec7706f1534c3c24b6664110fa6cf57c3512bb58d4ae666eb8aaed347bdd0fcc693ae5642a10264eb24e1274823f434d66307d9c1cd3c15be194a462b19dea48b339562bd54eac0517d81d7c1d6897ccbf3df258cb75677a235768dfdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d7134fd95b5494fd350c63f8bff9d7be30f0bfb3a78daae9f2a0f1ef38f358fd6010000000000000000000000000000000000000000000000000000000000000000f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b6e1e55e9e4793d44338f52522fd838eb70bd3ac0bb6492923efa3cabf6f5cae3"
1+
"0x080000006f020000f90264a01624e3d62872568e41233178997c38dd75fa3baccc89351026beff7026179bfba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347944838b106fce9647bdf1e7877bf73ce8b0bad5f97a02e065520386645261b7a6153924904a31c07bf6d37bca90fe35b21d864499c05a0eaa4d1ba5182915e8732ddd43e557a6ec713732e72964593275124fddf28a2aba0a9f528fe24151b34969ceb581a59f107d7bf38d8f364072dd50908f326226e71b90100f5bbd9423d137076afdb9b31d2f1db9239cff06e951d0dee6e2d8a302cfb14632d9c2725ed7a08043a5f6e97df7dc311867ba9749f08ed735fbb6a03802ce196f5eed77c97d3bd3dc81ce76fdd61b3ec55cc71d511567e685d0c2cec8c24ffee35856338dae6da75f20f9c8efe338fcffb7d515fde9d7fe7f5305bb4da1a3585a3be7e0e378581692dd9bbfa95b1c7565419eed5eff471ff29296fdd7d733efddfec7f62e4e3fa9eb3f159c609c7dd5f23bdd1b4baff8e283f65ea3d24680bd4cb36f61f00dd5b56ff49bdb77a3d98ee56a7b6438c48dfba4aa5034e6ad3e2e63ff7fccb69b5b492c5ed93cffd71a92e5dddf6ff5161ace6da24c0bb9d00ec5f8084014977bd8401c9c38083f94439846780b05798546974616e2028746974616e6275696c6465722e78797a29a07737f9743d49ab14e32b78a4989729b13bfd28f09c7729669d14c35a3e265d5288000000000000000084bc232c85a01fd1ee2a1b4008ac9f8749a3a5980645510788ccbf0922b77efd67224f8a2234830200008403cc0000a0e1c45ed325063d2380fb27927e7dd5024dada52070c9af2889ee51a105040bcfcc0100003a317faa00ffbca7c1fc9464025ada6aa0db71fd9c050ed433bab104834f0f26c2c38585972af1a49f5358e96748e08f62d9e06883d6d3bbc285f5bbdc3fdde7b87b8f3009f2311f723310e9600cd62f3a0ba54257645d03dbb94700997c2ff1bea5a1dbb8434febb2338912ebd94cfb183cc76b79a1449374aca82445a60e1641d6c37404381727480db4e3e124c9ce9345eb3761882ba31a2444e19f7f4be6446d9460a465986305984f731af89318ee7a965c33d5f6e293bd7c77050a7275d50d2f96d67ae9ec187ef09d1c19c8688ad0a9c00675a55bf61e5e412d5b0b309b9b4a4f9baaa4e6d6cd518eb62f41a133594cab49cf290ffa3570b65376b9dab2632457193d929218ee57d4d2dc8df537f9e2929746d934595d00ff258485173737414bac51a48ca8e03d442cca16a9d9d485ff0447a52427aada4c790ac75fdb8c75ab9503bd1eb67bfb5e2f8f403654b57a1e206aac23546088f1d7284b27d0fc56523cfafc7fb5d233f5faee241365fa4cb0c1d90792d8b558a3d0d5a63121993447a9a5d26cda2d9ad060c8d13f66d84623cc800e3dbb00097ce81a4debe6e5bf0ec7b02915aefabb6e7b1fb8468f228ab04e8e789a26ad9d727ac8430400e0a40000000000f5a23c1219f35dd7d4dc73e816727b6062b26168d5de32a8c44a5e91eeca9f1e04a8748db8fd9595375edfe16660a66ca721079109bd18775eeb54ce07b1400f37d1c9f9c839443ae1aff0d273f1801ffe724770a23d81a63f22f7babe39715d5b5687af2260ef0ed892a68d169c580b03ccb5bc59b0596a4221568de8bf1c7091e37807ec7706f1534c3c24b6664110fa6cf57c3512bb58d4ae666eb8aaed347bdd0fcc693ae5642a10264eb24e1274823f434d66307d9c1cd3c15be194a462b19dea48b339562bd54eac0517d81d7c1d6897ccbf3df258cb75677a235768dfdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d7134fd95b5494fd350c63f8bff9d7be30f0bfb3a78daae9f2a0f1ef38f358fd6010000000000000000000000000000000000000000000000000000000000000000f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b6e1e55e9e4793d44338f52522fd838eb70bd3ac0bb6492923efa3cabf6f5cae3"

0 commit comments

Comments
 (0)