diff --git a/core/state/database_test.go b/core/state/database_test.go index ddd2e0e7d..b172aa3e7 100644 --- a/core/state/database_test.go +++ b/core/state/database_test.go @@ -1223,12 +1223,8 @@ func TestWrongIncarnation2(t *testing.T) { func TestChangeAccountCodeBetweenBlocks(t *testing.T) { contract := libcommon.HexToAddress("0x71dd1027069078091B3ca48093B00E4735B20624") - m := stages.Mock(t) - tx, err := m.DB.BeginRw(m.Ctx) - require.NoError(t, err) - defer tx.Rollback() - - r, tsw := m.NewStateReader(tx), m.NewStateWriter(tx, 0) + _, tx := memdb.NewTestTx(t) + r, tsw := state.NewPlainStateReader(tx), state.NewPlainStateWriter(tx, nil, 0) intraBlockState := state.New(r) // Start the 1st transaction intraBlockState.CreateAccount(contract, true) @@ -1240,7 +1236,8 @@ func TestChangeAccountCodeBetweenBlocks(t *testing.T) { if err := intraBlockState.FinalizeTx(&chain.Rules{}, tsw); err != nil { t.Errorf("error finalising 1st tx: %v", err) } - _ = m.CalcStateRoot(tx) + _, err := trie.CalcRoot("test", tx) + require.NoError(t, err) oldCodeHash := libcommon.BytesToHash(crypto.Keccak256(oldCode)) trieCode, tcErr := r.ReadAccountCode(contract, 1, oldCodeHash) assert.NoError(t, tcErr, "you can receive the new code") diff --git a/core/state/plain_state_reader.go b/core/state/plain_state_reader.go index ffbd8731d..0b43033f2 100644 --- a/core/state/plain_state_reader.go +++ b/core/state/plain_state_reader.go @@ -6,7 +6,6 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/kv" - "github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/common/dbutils" "github.com/ledgerwatch/erigon/core/types/accounts" @@ -22,9 +21,6 @@ type PlainStateReader struct { } func NewPlainStateReader(db kv.Getter) *PlainStateReader { - if ethconfig.EnableHistoryV4InTest { - panic("historyV4 require use StateReaderV4 instead of PlainStateReader") - } return &PlainStateReader{ db: db, } diff --git a/core/state/state_test.go b/core/state/state_test.go index 858f28037..ba9fa3244 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -27,8 +27,6 @@ import ( "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/kvcfg" "github.com/ledgerwatch/erigon-lib/kv/memdb" - "github.com/ledgerwatch/erigon/turbo/stages" - "github.com/stretchr/testify/require" checker "gopkg.in/check.v1" "github.com/ledgerwatch/erigon/core/types/accounts" @@ -326,12 +324,9 @@ func compareStateObjects(so0, so1 *stateObject, t *testing.T) { } func TestDump(t *testing.T) { - m := stages.Mock(t) - tx, err := m.DB.BeginRw(m.Ctx) - require.NoError(t, err) - defer tx.Rollback() - w := m.NewStateWriter(tx, 0) - state := New(m.NewStateReader(tx)) + _, tx := memdb.NewTestTx(t) + w := NewPlainStateWriter(tx, tx, 0) + state := New(NewPlainStateReader(tx)) // generate a few entries obj1 := state.GetOrNewStateObject(toAddr([]byte{0x01})) @@ -343,7 +338,7 @@ func TestDump(t *testing.T) { obj3.SetBalance(uint256.NewInt(44)) // write some of them to the trie - err = w.UpdateAccountData(obj1.address, &obj1.data, new(accounts.Account)) + err := w.UpdateAccountData(obj1.address, &obj1.data, new(accounts.Account)) if err != nil { t.Fatal(err) } @@ -357,22 +352,18 @@ func TestDump(t *testing.T) { t.Fatal(err) } - blockWriter := m.NewStateWriter(tx, 1) + blockWriter := NewPlainStateWriter(tx, tx, 1) err = state.CommitBlock(&chain.Rules{}, blockWriter) if err != nil { t.Fatal(err) } - if casted, ok := blockWriter.(WriterWithChangeSets); ok { - err = casted.WriteChangeSets() - if err != nil { - t.Fatal(err) - } - err = casted.WriteHistory() - if err != nil { - t.Fatal(err) - } - } else { - panic("implement me") + err = blockWriter.WriteChangeSets() + if err != nil { + t.Fatal(err) + } + err = blockWriter.WriteHistory() + if err != nil { + t.Fatal(err) } // check that dump contains the state objects that are in trie