Skip to content
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
45 changes: 45 additions & 0 deletions core/genesis_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,48 @@ func TestEmbeddedGenesisConfigMatchesParams(t *testing.T) {
})
}
}

// TestEmbeddedGenesisHashMatchesParams verifies that the genesis block hash
// derived from each network's embedded JSON equals the canonical hash constant
// in params. A mismatch means `XDC init <network>` and `XDC --<network>`
// would produce different block-0 headers, making nodes on each path unable to
// peer with one another.
//
// Historical note: this divergence occurred for devnet when
// core/genesis_alloc_devnet.go was updated by the May-2026 network reset
// (#2347) without a corresponding update to genesis/devnet.json, causing the
// two startup paths to silently generate different genesis hashes until the
// alloc was re-synchronised in a follow-up fix.
func TestEmbeddedGenesisHashMatchesParams(t *testing.T) {
cases := []struct {
name string
raw []byte
wantHash common.Hash
}{
{"mainnet", xdcgenesis.MainnetGenesis, params.MainnetGenesisHash},
{"testnet", xdcgenesis.TestnetGenesis, params.TestnetGenesisHash},
{"devnet", xdcgenesis.DevnetGenesis, params.DevnetGenesisHash},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
g := new(Genesis)
if err := json.Unmarshal(c.raw, g); err != nil {
t.Fatalf("unmarshal embedded %s genesis: %v", c.name, err)
}
got := g.ToBlock().Hash()
if got != c.wantHash {
t.Errorf("embedded %s genesis hash mismatch:\n got %s\n want %s\nAlloc or header fields in the embedded JSON diverge from the Go-side genesis used to derive params.%sGenesisHash.",
c.name, got.Hex(), c.wantHash.Hex(), capitalize(c.name))
}
})
}
}

// capitalize upper-cases the first ASCII character of s.
func capitalize(s string) string {
if s == "" {
return s
}
return strings.ToUpper(s[:1]) + s[1:]
}
9 changes: 9 additions & 0 deletions genesis/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,15 @@
},
"b25193378f1ac1f13353a894b77292588f724490": {
"balance": "0x115eec47f6cf7e35000000"
},
"4b1a14a10cb48e4cfddd17c379dfcaa358b011bc": {
"balance": "0xc9f2c9cd04674edea40000000"
},
"d16c20329d391104029d0a850dcdf9ed6e259b60": {
"balance": "0xc9f2c9cd04674edea40000000"
},
"cc08002e7e4baec892785887a74d35557e8d2c15": {
"balance": "0xc9f2c9cd04674edea40000000"
}
},
"number": "0x0",
Expand Down
Loading