From e573b7e8cea5d280176a6761d09ab45bf38d70a3 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Sun, 8 Feb 2026 01:42:26 +0200 Subject: [PATCH] core/state: add test --- core/state/statedb_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 661d17bb7b..7fbbf87ebd 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -717,6 +717,31 @@ func TestCopyOfCopy(t *testing.T) { } } +// TestCopyWithBinaryTrie tests that Copy works correctly when the underlying +// trie is a BinaryTrie (verkle mode). This is a regression test to ensure +// mustCopyTrie handles *bintrie.BinaryTrie. +func TestCopyWithBinaryTrie(t *testing.T) { + disk := rawdb.NewMemoryDatabase() + db := triedb.NewDatabase(disk, triedb.VerkleDefaults) + sdb := NewDatabase(db, nil) + + state, err := New(types.EmptyRootHash, sdb) + if err != nil { + t.Fatalf("failed to initialize state: %v", err) + } + addr := common.HexToAddress("0x01") + state.SetBalance(addr, uint256.NewInt(42), tracing.BalanceChangeUnspecified) + + // IntermediateRoot sets s.trie to *bintrie.BinaryTrie in verkle mode + state.IntermediateRoot(true) + + // Copy must not panic with BinaryTrie + cpy := state.Copy() + if got := cpy.GetBalance(addr); got.Cmp(uint256.NewInt(42)) != 0 { + t.Fatalf("balance mismatch: have %v, want 42", got) + } +} + // Tests a regression where committing a copy lost some internal meta information, // leading to corrupted subsequent copies. //