core: store genesis allocation and recommit them if necessary (#24460)
* core: store genesis allocation and recommit them if necessary * core: recover predefined genesis allocation if possible
This commit is contained in:
@@ -213,3 +213,33 @@ func TestGenesis_Commit(t *testing.T) {
|
||||
t.Errorf("inequal difficulty; stored: %v, genesisBlock: %v", stored, genesisBlock.Difficulty())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadWriteGenesisAlloc(t *testing.T) {
|
||||
var (
|
||||
db = rawdb.NewMemoryDatabase()
|
||||
alloc = &GenesisAlloc{
|
||||
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
|
||||
{2}: {Balance: big.NewInt(2), Storage: map[common.Hash]common.Hash{{2}: {2}}},
|
||||
}
|
||||
hash = common.HexToHash("0xdeadbeef")
|
||||
)
|
||||
alloc.write(db, hash)
|
||||
|
||||
var reload GenesisAlloc
|
||||
err := reload.UnmarshalJSON(rawdb.ReadGenesisState(db, hash))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load genesis state %v", err)
|
||||
}
|
||||
if len(reload) != len(*alloc) {
|
||||
t.Fatal("Unexpected genesis allocation")
|
||||
}
|
||||
for addr, account := range reload {
|
||||
want, ok := (*alloc)[addr]
|
||||
if !ok {
|
||||
t.Fatal("Account is not found")
|
||||
}
|
||||
if !reflect.DeepEqual(want, account) {
|
||||
t.Fatal("Unexpected account")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user