mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
fix import cycle in tests
This commit is contained in:
parent
0b778b9422
commit
688f3838b8
@ -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")
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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,23 +352,19 @@ 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()
|
||||
err = blockWriter.WriteChangeSets()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = casted.WriteHistory()
|
||||
err = blockWriter.WriteHistory()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// check that dump contains the state objects that are in trie
|
||||
historyV3, err := kvcfg.HistoryV3.Enabled(tx)
|
||||
|
Loading…
Reference in New Issue
Block a user