Skip to content

Commit aa28927

Browse files
authored
refactor: align genesis construction with Ethereum's decodePrealloc pattern (#69)
* refactor: use decodePrealloc for StableNet genesis block construction Replace JSON-based genesis decoding with Ethereum's decodePrealloc pattern for mainnet and testnet genesis blocks. Regenerate devp2p ethtest testdata to reflect the updated genesis configuration. * test: add genesis alloc consistency test for JSON vs decodePrealloc Add TestStableNetGenesisAllocConsistency to verify that the decodePrealloc-based genesis construction (with InjectContracts) produces the same alloc as the canonical JSON literals in stablenet_genesis.go. This keeps the JSON reference in use and prevents unused variable lint errors. * refactor: extract genesis JSON from Go source into standalone files Move stableNetMainnetGenesisJson and stableNetTestnetGenesisJson from core/stablenet_genesis.go into core/genesis_mainnet.json and core/genesis_testnet.json. This allows direct use with mkalloc.go and removes large string literals from the compiled binary. Update TestStableNetGenesisAllocConsistency to read from the JSON files via os.ReadFile. * chore: use decimal literal for mainnet genesis gas limit * chore: remove claude setting in gitignore
1 parent 88fe521 commit aa28927

File tree

10 files changed

+381
-316
lines changed

10 files changed

+381
-316
lines changed

cmd/devp2p/internal/ethtest/snap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (s *Suite) TestSnapGetAccountRange(t *utesting.T) {
100100
limitHash: ffHash,
101101
expAccounts: 50,
102102
expFirst: firstKey,
103-
expLast: common.HexToHash("0x420a83d9891f19593cdda9b31bb3b450e960fa87042dd428a7fa5ee69db02c75"),
103+
expLast: common.HexToHash("0x4363d332a0d4df8582a84932729892387c623fe1ec42e2cfcbe85c183ed98e0e"),
104104
desc: "In this test, we request the entire state range, but limit the response to 3000 bytes.",
105105
},
106106
{
0 Bytes
Binary file not shown.

cmd/devp2p/internal/ethtest/testdata/genesis.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
},
2727
"init": {
2828
"validators": [
29-
"0x19d8eb1dcdb615acb94c9287d02cd1da84148175"
29+
"0x2bd4c135f35a4aa58db00ccf08f3a8cded846554"
3030
],
3131
"blsPublicKeys": [
32-
"0xb84d9b11385f96b8f086ad86ab0e74ae37ce7781a5cc843a4c24656769f56fb1dc8e4846eac20eb14a2650c7ace130b7"
32+
"0xa14609bac26529cdcbf2b223ef468b1de248828e9166f8ebac4776352a0bdb257612918aac553d6e0f14ce33c4c43370"
3333
]
3434
},
3535
"systemContracts": {
3636
"govValidator": {
3737
"address": "0x0000000000000000000000000000000000001001",
3838
"version": "v1",
3939
"params": {
40-
"blsPublicKeys": "0xb84d9b11385f96b8f086ad86ab0e74ae37ce7781a5cc843a4c24656769f56fb1dc8e4846eac20eb14a2650c7ace130b7",
40+
"blsPublicKeys": "0xa14609bac26529cdcbf2b223ef468b1de248828e9166f8ebac4776352a0bdb257612918aac553d6e0f14ce33c4c43370",
4141
"expiry": "604800",
4242
"maxProposals": "3",
4343
"memberVersion": "1",
44-
"members": "0x19d8EB1dCDB615AcB94c9287D02cD1DA84148175",
44+
"members": "0x2bD4C135f35a4aA58db00CCf08f3A8cDEd846554",
4545
"quorum": "1",
46-
"validators": "0x19d8EB1dCDB615AcB94c9287D02cD1DA84148175"
46+
"validators": "0x2bD4C135f35a4aA58db00CCf08f3A8cDEd846554"
4747
}
4848
},
4949
"nativeCoinAdapter": {
@@ -92,7 +92,7 @@
9292
"expiry": "604800",
9393
"maxProposals": "3",
9494
"memberVersion": "1",
95-
"members": "0x19d8EB1dCDB615AcB94c9287D02cD1DA84148175",
95+
"members": "0x2bD4C135f35a4aA58db00CCf08f3A8cDEd846554",
9696
"quorum": "1"
9797
}
9898
}
@@ -101,7 +101,7 @@
101101
},
102102
"nonce": "0x0",
103103
"timestamp": "0x0",
104-
"extraData": "0xf860808080c0c080c0c086191a20322000f84fdad99419d8eb1dcdb615acb94c9287d02cd1da84148175831cfde0c180f1b0b84d9b11385f96b8f086ad86ab0e74ae37ce7781a5cc843a4c24656769f56fb1dc8e4846eac20eb14a2650c7ace130b7",
104+
"extraData": "0xf860808080c0c080c0c086191a20322000f84fdad9942bd4c135f35a4aa58db00ccf08f3a8cded846554831cfde0c180f1b0a14609bac26529cdcbf2b223ef468b1de248828e9166f8ebac4776352a0bdb257612918aac553d6e0f14ce33c4c43370",
105105
"gasLimit": "0x23f3e20",
106106
"difficulty": "0x1",
107107
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
@@ -133,19 +133,19 @@
133133
"0x0000000000000000000000000000000000000000000000000000000000000032": "0x0000000000000000000000000000000000000000000000000000000000b00001",
134134
"0x0000000000000000000000000000000000000000000000000000000000000033": "0x0000000000000000000000000000000000000000000000000000000000000001",
135135
"0x0000000000000000000000000000000000000000000000000000000000000039": "0x0000000000000000000000000000000000000000000000000000191a20322000",
136-
"0x0f8213bf6a797a47e7c672160ab65cb4deb9cbeef873f701db7ad91e1d929f49": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175",
137-
"0x34a9afc1cdd4e4875799a4c08bc8ecf3ac32900df850eddfc398e3215b19c47b": "0x0000000000000000000000000000000000000000000000000000000000000061",
138-
"0x37deb9dafeb1dd0dc21cd5a43d66f5922a912ecc684fca7d660c469bb165c064": "0x0000000000000000000000000000000000000000000000000000000000000001",
136+
"0x3889fd1cedbf74f8fb2cb48a20da2b3d30bbb81aaf54bfcda6a063c89c7c5dc5": "0x0000000000000000000000000000000000000000000000000000000000000001",
139137
"0x3e5fec24aa4dc4e5aee2e025e51e1392c72a2500577559fae9665c6d52bd6a31": "0x0000000000000000000000000000000000000000000000000000000000000001",
140-
"0x6ebd6d16a9fc2c1f4c38ca115f668dc343133d746b169ec2b361ecd2fe4f0971": "0xb84d9b11385f96b8f086ad86ab0e74ae37ce7781a5cc843a4c24656769f56fb1",
141-
"0x6ebd6d16a9fc2c1f4c38ca115f668dc343133d746b169ec2b361ecd2fe4f0972": "0xdc8e4846eac20eb14a2650c7ace130b700000000000000000000000000000000",
142-
"0x7cfee3704246efb5215f769d70926659015411fb1bf0da912c05b82206a674d3": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175",
143-
"0x80497882cf9008f7f796a89e5514a7b55bd96eab88ecb66aee4fb0a6fd34811c": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175",
144-
"0x82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a82": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175",
138+
"0x4d7a42d07f9c6e9b2d35372529e30ffa6c22631e46480f8bc0bb90de1d69a084": "0x0000000000000000000000000000000000000000000000000000000000000001",
139+
"0x51a386758785594f07a088221d43895a9977f5434960d877da125f3fc4a80c89": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554",
140+
"0x5f0cec574457ac88bfe0739b4f52da8fd12a010b75e2cbf20eecbbfcace2536a": "0xa14609bac26529cdcbf2b223ef468b1de248828e9166f8ebac4776352a0bdb25",
141+
"0x5f0cec574457ac88bfe0739b4f52da8fd12a010b75e2cbf20eecbbfcace2536b": "0x7612918aac553d6e0f14ce33c4c4337000000000000000000000000000000000",
142+
"0x80497882cf9008f7f796a89e5514a7b55bd96eab88ecb66aee4fb0a6fd34811c": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554",
143+
"0x82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a82": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554",
145144
"0x92e85d02570a8092d09a6e3a57665bc3815a2699a4074001bf1ccabf660f5a36": "0x0000000000000000000000000000000000000000000000000000000000000001",
146-
"0x9379279c027818cec98a5dc783e30a5b84b32e8d0441bd748898f7dde92abc14": "0x0000000000000000000000000000000000000000000000000000000000000001",
147-
"0xa7a6bf2f94ce9f8d5fbc48cc32dc5c53c3e206a7133ddb017b967aa04c91ceda": "0x0000000000000000000000000000000000000000000000000000000000000001",
148-
"0xe16989fa9c2624145e5a9a08f13bbc6dce11085d7748c016bf5563274e66a5b2": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175"
145+
"0xb991595e1287fef4caacb0dd0613c17b74b97703addc37cc81f4f78747b6fedd": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554",
146+
"0xc5ea86f7e96798f3c8c7d9ef588d5d596da2bd3a900baadfe4f0db82cfc9cca6": "0x0000000000000000000000000000000000000000000000000000000000000061",
147+
"0xd8cd8c391844850ec4b18e463c85f5e995e6512602db0074ba9b35ffd2d3b252": "0x0000000000000000000000000000000000000000000000000000000000000001",
148+
"0xf2df0fc2c7b056d2f2ad0d3ee0f4ac1d9de9e5326ed3e5b9b5f5b26f94fd985d": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554"
149149
},
150150
"balance": "0x0"
151151
},
@@ -194,11 +194,11 @@
194194
"0x0000000000000000000000000000000000000000000000000000000000000004": "0x0000000000000000000000000000000000000000000000000000000000000001",
195195
"0x000000000000000000000000000000000000000000000000000000000000000c": "0x0000000000000000000000000000000000000000000000000000000000000003",
196196
"0x0000000000000000000000000000000000000000000000000000000000000036": "0x0000000000000000000000000000000000000000000000000000000000b00003",
197-
"0x37deb9dafeb1dd0dc21cd5a43d66f5922a912ecc684fca7d660c469bb165c064": "0x0000000000000000000000000000000000000000000000000000000000000001",
198197
"0x3e5fec24aa4dc4e5aee2e025e51e1392c72a2500577559fae9665c6d52bd6a31": "0x0000000000000000000000000000000000000000000000000000000000000001",
199-
"0x80497882cf9008f7f796a89e5514a7b55bd96eab88ecb66aee4fb0a6fd34811c": "0x00000000000000000000000019d8eb1dcdb615acb94c9287d02cd1da84148175",
198+
"0x4d7a42d07f9c6e9b2d35372529e30ffa6c22631e46480f8bc0bb90de1d69a084": "0x0000000000000000000000000000000000000000000000000000000000000001",
199+
"0x80497882cf9008f7f796a89e5514a7b55bd96eab88ecb66aee4fb0a6fd34811c": "0x0000000000000000000000002bd4c135f35a4aa58db00ccf08f3a8cded846554",
200200
"0x92e85d02570a8092d09a6e3a57665bc3815a2699a4074001bf1ccabf660f5a36": "0x0000000000000000000000000000000000000000000000000000000000000001",
201-
"0xa7a6bf2f94ce9f8d5fbc48cc32dc5c53c3e206a7133ddb017b967aa04c91ceda": "0x0000000000000000000000000000000000000000000000000000000000000001"
201+
"0xd8cd8c391844850ec4b18e463c85f5e995e6512602db0074ba9b35ffd2d3b252": "0x0000000000000000000000000000000000000000000000000000000000000001"
202202
},
203203
"balance": "0x0"
204204
},
@@ -215,15 +215,15 @@
215215
"16c57edf7fa9d9525378b0b81bf8a3ced0620c1c": {
216216
"balance": "0xc097ce7bc90715b34b9f1000000000"
217217
},
218-
"19d8eb1dcdb615acb94c9287d02cd1da84148175": {
219-
"balance": "0xc097ce7bc90715b34b9f1000000000"
220-
},
221218
"1f4924b14f34e24159387c0a4cdbaa32f3ddb0cf": {
222219
"balance": "0xc097ce7bc90715b34b9f1000000000"
223220
},
224221
"1f5bde34b4afc686f136c7a3cb6ec376f7357759": {
225222
"balance": "0xc097ce7bc90715b34b9f1000000000"
226223
},
224+
"2bd4c135f35a4aa58db00ccf08f3a8cded846554": {
225+
"balance": "0xc097ce7bc90715b34b9f1000000000"
226+
},
227227
"2d389075be5be9f2246ad654ce152cf05990b209": {
228228
"balance": "0xc097ce7bc90715b34b9f1000000000"
229229
},
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"parentHash": "0xba47a31bc79501450c08e3909695ac85d8db505ed7ba62d7e3df6ea3d69b474a",
2+
"parentHash": "0x3887749c5a09bf3fc72d44f5ceb75dc68d33f054c1fd76da81fb0227d6f1cba3",
33
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
4-
"miner": "0x19d8eb1dcdb615acb94c9287d02cd1da84148175",
5-
"stateRoot": "0x44a67dcfedcdb6f859d641f3a37adf8e2182662b96e80c0ebfff5ad63ec2ad39",
4+
"miner": "0x2bd4c135f35a4aa58db00ccf08f3a8cded846554",
5+
"stateRoot": "0xd0f9b10c2e965c66f8939be7d06ef630a9b8d57420247319671f84e6e1f24ec7",
66
"transactionsRoot": "0x26f47dfbf4ce4ac70395918b8edda9cdc0628150fb752709aaede08bfebd1d0a",
77
"receiptsRoot": "0x5fef357ed75d21a3ea1849a1f568009d03b1933a967bf053ec200b28d3da99ed",
88
"logsBloom": "0x00000200002000010000010000000000000000000000000000000004000000900000400000000000000000000000000044000000000000000000000000000000000000000000000000004000400000000000000000000000000100840000000000000400000000020001100000040000000000000000000200040000000000000000000000000000000001801000000000000000000000000000000000000400000000000000000040000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000001400004001000000000000000000000000000000000",
@@ -11,13 +11,13 @@
1111
"gasLimit": "0x23f3e20",
1212
"gasUsed": "0xfc61",
1313
"timestamp": "0x1388",
14-
"extraData": "0xf90252a00000000000000000000000000000000000000000000000000000000000000000b8414c32f90e79de1fef83035bd577fd5d4f6894a58bba3d2afcdb803b06adfaef377ef0d62af640d33bb1811a86c71de59621faf2ffed56d56d8d9226ba8d6785210180f86301b860a537f3a70a942137d8911082f446cc76f6bb4c1ee213f91579827d0db7c9a7e7f3eb5f2c63d2c73b4e2577fa6d0ece170f50e313cd80dbb5cbebf9e199720de646db064b735aaea2fa5ebc0de314d51e02ce00064b8a0eec6c4dad55086da11bf86301b860865e38404ccd6bf9b29907e076ab8811a380e6aa130d0dfef1ff52202ad5491444c0ff4e2b000b063cd10eb6a2c213ed0ddd6f312cc48315a8e55ff3ab9f7aba7ab09e76a927639ce13dc8807378cb12d070cdaabaeeb8f2e9d98aad5fa3668980f86301b860b65334f3e88b17954938955090f432692979c7e0c46414aa70a8aa40a5f88436fcb8684816968d2f4cdf09f1003b999f1273386187ee165f43fd5f7ea0c11b53620e4031b11ba5e889e80a0a2758088e831e2cdc6b51667bc9f1759c5d03a803f86301b860a44fca5248ff652ae373b74dd51069367ee11f84cd7db06853ceee1ce8569a6c7c1cedbd5fe2381f0db51df88b5ff7d0136a7c1e8308d81d8ddb322fbe53f1bea78ea0fc8ea8966eb191bf5842a548921dd4d94457fe83cdb8993f2dec53cdbe86191a20322000f84fdad99419d8eb1dcdb615acb94c9287d02cd1da84148175831e8272c180f1b0b84d9b11385f96b8f086ad86ab0e74ae37ce7781a5cc843a4c24656769f56fb1dc8e4846eac20eb14a2650c7ace130b7",
15-
"mixHash": "0xe572f0eb8985b441c31f66f809a71864197ef7b1b1c790afa5bfc716cd7d99e7",
14+
"extraData": "0xf90252a00000000000000000000000000000000000000000000000000000000000000000b841d6504b2cc833beb274e745708d5d5837fbc5ff4aa370654c4f5a928b9a4081fe29d54496378e28bf2d95f4584e407e0d4aaa3907076ef1711ad05f4b01403a1f0080f86301b86083c7fec667caead97972ee1a4ca7f704aa6cdac5fa032e239584f878861de06ede5ea1dc93e2882ea35e53dea28b23e005624d2c59d2ff9644537a0c1d9d5371d193bf9b7d5370f2a4a6b4f8384a2205baa04b801c0465e73b3b51b779b06933f86301b860af64693cec6eeb2dff72902d00f7a5582cb49e36df0364b94c568d58e99addbb6c0714dc7407488db2cbfbfdabdd09bb182fe0447a23579a289fe9e06959fadee1dda6e5d8e48fdc409d401109d7fb5e943acaac57284a72679a7579e3bb94f980f86301b86086feb11a433f123feb5bf5967314ee637db08c2b1bf631241d728539f2797fc32ff803a26ab0a7b595d4a238bc7e503d11d081db89a801256c2ba738367a657ce9addc7cd2c7cc4a53eed92f29fec825baa8757a7c5aab537796786815f5d53af86301b8608620eeca02dd877f7f1aa2339bed5659041ddcc100249c6f28945292d0e30a3adaf48c67fdfd259fb7d42e1201ae308618fb784c07d8161590cf0802fe2ef61c01f74b242084f9df26c343eff54e5d9c1b6d526dcf58a1f5112fd3a9d68ddfa586191a20322000f84fdad9942bd4c135f35a4aa58db00ccf08f3a8cded846554831e8272c180f1b0a14609bac26529cdcbf2b223ef468b1de248828e9166f8ebac4776352a0bdb257612918aac553d6e0f14ce33c4c43370",
15+
"mixHash": "0x0e40eddfbd6bedbf949a9537fc7bb2ea34ac02ad0972f4689c38f6e3cee0c64a",
1616
"nonce": "0x0000000000000000",
1717
"baseFeePerGas": "0x12309ce54000",
1818
"withdrawalsRoot": null,
1919
"blobGasUsed": null,
2020
"excessBlobGas": null,
2121
"parentBeaconBlockRoot": null,
22-
"hash": "0x828b52fdff36e3c68f95d1f94763d1cdd3830b88986af048463a30cad04a1fd3"
22+
"hash": "0x2a2794d209b278550d2fdb9ce8938066e726292c0366eabb52bae4da42f005d4"
2323
}

cmd/devp2p/internal/ethtest/testdata/headfcu.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"method": "engine_forkchoiceUpdatedV1",
55
"params": [
66
{
7-
"headBlockHash": "0x828b52fdff36e3c68f95d1f94763d1cdd3830b88986af048463a30cad04a1fd3",
8-
"safeBlockHash": "0x828b52fdff36e3c68f95d1f94763d1cdd3830b88986af048463a30cad04a1fd3",
9-
"finalizedBlockHash": "0x828b52fdff36e3c68f95d1f94763d1cdd3830b88986af048463a30cad04a1fd3"
7+
"headBlockHash": "0x2a2794d209b278550d2fdb9ce8938066e726292c0366eabb52bae4da42f005d4",
8+
"safeBlockHash": "0x2a2794d209b278550d2fdb9ce8938066e726292c0366eabb52bae4da42f005d4",
9+
"finalizedBlockHash": "0x2a2794d209b278550d2fdb9ce8938066e726292c0366eabb52bae4da42f005d4"
1010
},
1111
null
1212
]

cmd/devp2p/internal/ethtest/testdata/headstate.json

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

core/genesis.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,20 @@ func (g *Genesis) MustCommit(db ethdb.Database, triedb *triedb.Database) *types.
602602
}
603603

604604
func DefaultStableNetMainnetGenesisBlock() *Genesis {
605-
genesis := new(Genesis)
606-
if err := json.NewDecoder(strings.NewReader(stableNetMainnetGenesisJson)).Decode(genesis); err != nil {
607-
panic("Cannot parse default StableNet mainnet genesis.")
605+
return &Genesis{
606+
Config: params.StableNetMainnetChainConfig,
607+
GasLimit: 105_000_000, //0x6422c40
608+
Difficulty: big.NewInt(1),
609+
Alloc: decodePrealloc(stablenetMainnetAllocData),
608610
}
609-
genesis.Config = params.StableNetMainnetChainConfig
610-
return genesis
611611
}
612612

613613
func DefaultStableNetTestnetGenesisBlock() *Genesis {
614-
genesis := new(Genesis)
615-
if err := json.NewDecoder(strings.NewReader(stableNetTestnetGenesisJson)).Decode(genesis); err != nil {
616-
panic("Cannot parse default StableNet testnet genesis.")
614+
return &Genesis{
615+
Config: params.StableNetTestnetChainConfig,
616+
Difficulty: big.NewInt(0),
617+
Alloc: decodePrealloc(stablenetTestnetAllocData),
617618
}
618-
genesis.Config = params.StableNetTestnetChainConfig
619-
return genesis
620619
}
621620

622621
// DefaultGenesisBlock returns the Ethereum main net genesis block.

core/genesis_mainnet.json

Lines changed: 219 additions & 0 deletions
Large diffs are not rendered by default.

core/genesis_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"math/big"
23+
"os"
2324
"reflect"
2425
"testing"
2526

@@ -773,3 +774,95 @@ func TestSetupGenesis_MainnetWithAnzeonInit(t *testing.T) {
773774
})
774775
}
775776
}
777+
778+
// TestStableNetGenesisAllocConsistency verifies that the decodePrealloc-based
779+
// genesis construction (with InjectContracts applied) produces the same alloc
780+
// as the canonical JSON files (genesis_mainnet.json, genesis_testnet.json).
781+
func TestStableNetGenesisAllocConsistency(t *testing.T) {
782+
tests := []struct {
783+
name string
784+
jsonFile string
785+
genesis func() *Genesis
786+
}{
787+
{
788+
name: "mainnet",
789+
jsonFile: "genesis_mainnet.json",
790+
genesis: DefaultStableNetMainnetGenesisBlock,
791+
},
792+
{
793+
name: "testnet",
794+
jsonFile: "genesis_testnet.json",
795+
genesis: DefaultStableNetTestnetGenesisBlock,
796+
},
797+
}
798+
799+
for _, tt := range tests {
800+
t.Run(tt.name, func(t *testing.T) {
801+
// Decode alloc from the canonical JSON file
802+
data, err := os.ReadFile(tt.jsonFile)
803+
if err != nil {
804+
t.Fatalf("failed to read %s: %v", tt.jsonFile, err)
805+
}
806+
var jsonGenesis Genesis
807+
if err := json.Unmarshal(data, &jsonGenesis); err != nil {
808+
t.Fatalf("failed to decode genesis JSON: %v", err)
809+
}
810+
811+
// Build alloc via decodePrealloc + InjectContracts (same path as SetupGenesisBlock)
812+
genesis := tt.genesis()
813+
if err := initializeAnzeonGenesis(genesis); err != nil {
814+
t.Fatalf("initializeAnzeonGenesis failed: %v", err)
815+
}
816+
builtAlloc := genesis.Alloc
817+
818+
// Compare address sets
819+
if len(jsonGenesis.Alloc) != len(builtAlloc) {
820+
t.Errorf("alloc length mismatch: json=%d, built=%d", len(jsonGenesis.Alloc), len(builtAlloc))
821+
for addr := range jsonGenesis.Alloc {
822+
if _, ok := builtAlloc[addr]; !ok {
823+
t.Errorf(" json-only address: %s", addr.Hex())
824+
}
825+
}
826+
for addr := range builtAlloc {
827+
if _, ok := jsonGenesis.Alloc[addr]; !ok {
828+
t.Errorf(" built-only address: %s", addr.Hex())
829+
}
830+
}
831+
t.FailNow()
832+
}
833+
834+
for addr, jsonAccount := range jsonGenesis.Alloc {
835+
builtAccount, ok := builtAlloc[addr]
836+
if !ok {
837+
t.Errorf("address %s present in JSON but missing from built alloc", addr.Hex())
838+
continue
839+
}
840+
841+
if jsonAccount.Balance.Cmp(builtAccount.Balance) != 0 {
842+
t.Errorf("address %s balance mismatch: json=%s, built=%s",
843+
addr.Hex(), jsonAccount.Balance, builtAccount.Balance)
844+
}
845+
846+
if !bytes.Equal(jsonAccount.Code, builtAccount.Code) {
847+
t.Errorf("address %s code mismatch: json=%d bytes, built=%d bytes",
848+
addr.Hex(), len(jsonAccount.Code), len(builtAccount.Code))
849+
}
850+
851+
if len(jsonAccount.Storage) != len(builtAccount.Storage) {
852+
t.Errorf("address %s storage length mismatch: json=%d, built=%d",
853+
addr.Hex(), len(jsonAccount.Storage), len(builtAccount.Storage))
854+
continue
855+
}
856+
for key, jsonVal := range jsonAccount.Storage {
857+
if builtVal, exists := builtAccount.Storage[key]; !exists {
858+
t.Errorf("address %s storage key %s present in JSON but missing from built alloc",
859+
addr.Hex(), key.Hex())
860+
} else if jsonVal != builtVal {
861+
t.Errorf("address %s storage key %s value mismatch: json=%s, built=%s",
862+
addr.Hex(), key.Hex(), jsonVal.Hex(), builtVal.Hex())
863+
}
864+
}
865+
}
866+
})
867+
}
868+
}

0 commit comments

Comments
 (0)