Skip to content

Commit 33bb344

Browse files
committed
Merge branch 'main' into arr4n/state-hash-override
2 parents 975a00e + 99f0d0b commit 33bb344

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/state/statedb.libevm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import (
2525
"github.com/ava-labs/libevm/libevm/stateconf"
2626
)
2727

28+
// TxHash returns the current transaction hash set by [StateDB.SetTxContext].
29+
func (s *StateDB) TxHash() common.Hash {
30+
return s.thash
31+
}
32+
2833
// SnapshotTree mirrors the functionality of a [snapshot.Tree], allowing for
2934
// drop-in replacements. This is intended as a temporary feature as a workaround
3035
// until a standard Tree can be used.

core/state/statedb.libevm_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ import (
3636
"github.com/ava-labs/libevm/triedb/hashdb"
3737
)
3838

39+
func TestTxHash(t *testing.T) {
40+
db := NewDatabase(rawdb.NewMemoryDatabase())
41+
state, err := New(types.EmptyRootHash, db, nil)
42+
require.NoError(t, err)
43+
44+
assert.Zero(t, state.TxHash(), "Tx hash should initially be uninitialized")
45+
46+
hash := common.Hash{1}
47+
state.SetTxContext(hash, 3)
48+
assert.Equal(t, hash, state.TxHash(), "Tx hash should have been updated")
49+
}
50+
3951
func TestStateDBCommitPropagatesOptions(t *testing.T) {
4052
memdb := rawdb.NewMemoryDatabase()
4153
trieRec := &triedbRecorder{Database: hashdb.New(memdb, nil, &trie.MerkleResolver{})}

0 commit comments

Comments
 (0)