From fbd9690251f2e79824f4a0b10fa7a45619c60c04 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Fri, 2 Apr 2021 12:14:43 +0700 Subject: [PATCH] Remove tds in few tests (#1657) --- core/state/history_test.go | 141 ++----------------------------------- tests/state_test.go | 2 +- tests/state_test_util.go | 11 +-- 3 files changed, 13 insertions(+), 141 deletions(-) diff --git a/core/state/history_test.go b/core/state/history_test.go index fc96055d5..30f5de0a4 100644 --- a/core/state/history_test.go +++ b/core/state/history_test.go @@ -3,7 +3,6 @@ package state import ( "context" "fmt" - "math/big" "math/rand" "reflect" "sort" @@ -283,129 +282,6 @@ func randomAccount(t *testing.T) (*accounts.Account, common.Address, common.Hash return &acc, addr, addrHash } -func TestUnwindTruncateHistory(t *testing.T) { - t.Skip("tds.Unwind is not supported") - db := ethdb.NewMemDatabase() - defer db.Close() - mutDB := db.NewBatch() - tds := NewTrieDbState(common.Hash{}, db, 1) - ctx := context.Background() - acc1 := accounts.NewAccount() - acc := &acc1 - acc.Initialised = true - var addr common.Address = common.HexToAddress("0x1234567890") - acc.Balance.SetUint64(0) - // We will so that balance (in wei) always matches the block number - // We will also insert a extra storage item every block - for blockNumber := uint64(1); blockNumber < uint64(100); blockNumber++ { - tds.StartNewBuffer() - newAcc := acc.SelfCopy() - newAcc.Balance.SetUint64(blockNumber) - tds.SetBlockNr(blockNumber) - txWriter := tds.TrieStateWriter() - blockWriter := tds.DbStateWriter() - if blockNumber == 1 { - err := txWriter.CreateContract(addr) - if err != nil { - t.Fatal(err) - } - newAcc.Incarnation = FirstContractIncarnation - } - var oldValue uint256.Int - var newValue uint256.Int - newValue[0] = 1 - var location common.Hash - location.SetBytes(big.NewInt(int64(blockNumber)).Bytes()) - if err := txWriter.WriteAccountStorage(ctx, addr, newAcc.Incarnation, &location, &oldValue, &newValue); err != nil { - t.Fatal(err) - } - if err := txWriter.UpdateAccountData(ctx, addr, acc /* original */, newAcc /* new account */); err != nil { - t.Fatal(err) - } - if _, err := tds.ComputeTrieRoots(); err != nil { - t.Fatal(err) - } - if blockNumber == 1 { - err := blockWriter.CreateContract(addr) - if err != nil { - t.Fatal(err) - } - } - if err := blockWriter.WriteAccountStorage(ctx, addr, newAcc.Incarnation, &location, &oldValue, &newValue); err != nil { - t.Fatal(err) - } - if err := blockWriter.UpdateAccountData(ctx, addr, acc /* original */, newAcc /* new account */); err != nil { - t.Fatal(err) - } - if err := blockWriter.WriteChangeSets(); err != nil { - t.Fatal(err) - } - if err := blockWriter.WriteHistory(); err != nil { - t.Fatal(err) - } - acc = newAcc - } - // Recreate tds not to rely on the trie - tds = NewTrieDbState(tds.LastRoot(), mutDB, tds.blockNr) - a, err := tds.ReadAccountData(addr) - if err != nil { - t.Fatal(err) - } - if a.Balance.Uint64() != 99 { - t.Errorf("wrong balance on the account, expected %d, got %d", 99, a.Balance.Uint64()) - } - // Check 100 storage locations - for l := 0; l <= 100; l++ { - var location common.Hash - location.SetBytes(big.NewInt(int64(l)).Bytes()) - enc, err1 := tds.ReadAccountStorage(addr, a.Incarnation, &location) - if err1 != nil { - t.Fatal(err1) - } - if l > 0 && l < 100 { - if len(enc) == 0 { - t.Errorf("expected non-empty storage at location %d, got empty", l) - } - } else { - if len(enc) > 0 { - t.Errorf("expected empty storage at location %d, got non-empty", l) - } - } - } - // New we are goint to unwind 50 blocks back and check the balance - if err = tds.UnwindTo(50); err != nil { - t.Fatal(err) - } - if err = mutDB.Commit(); err != nil { - t.Fatal(err) - } - a, err = tds.ReadAccountData(addr) - if err != nil { - t.Fatal(err) - } - if a.Balance.Uint64() != 50 { - t.Errorf("wrong balance on the account, expected %d, got %d", 50, a.Balance.Uint64()) - } - // Check 100 storage locations - for l := 0; l <= 100; l++ { - var location common.Hash - location.SetBytes(big.NewInt(int64(l)).Bytes()) - enc, err1 := tds.ReadAccountStorage(addr, a.Incarnation, &location) - if err1 != nil { - t.Fatal(err1) - } - if l > 0 && l <= 50 { - if len(enc) == 0 { - t.Errorf("expected non-empty storage at location %d, got empty", l) - } - } else { - if len(enc) > 0 { - t.Errorf("expected empty storage at location %d, got non-empty", l) - } - } - } -} - /* before 3: addr1(f22b):"" @@ -808,7 +684,6 @@ func TestWalkAsOfUsingFixedBytesStatePlain(t *testing.T) { func TestWalkAsOfAccountPlain(t *testing.T) { db := ethdb.NewMemDatabase() defer db.Close() - tds := NewTrieDbState(common.Hash{}, db, 1) emptyValAcc := accounts.NewAccount() emptyVal := make([]byte, emptyValAcc.EncodingLengthForStorage()) emptyValAcc.EncodeForStorage(emptyVal) @@ -842,7 +717,7 @@ func TestWalkAsOfAccountPlain(t *testing.T) { Changes: make([]changeset.Change, 0), } - writeBlockData(t, tds, 3, []accData{ + writeBlockData(t, NewPlainStateWriter(db, db, 3), []accData{ { addr: addrs[0], oldVal: &emptyValAcc, @@ -860,7 +735,7 @@ func TestWalkAsOfAccountPlain(t *testing.T) { }, }) - writeBlockData(t, tds, 5, []accData{ + writeBlockData(t, NewPlainStateWriter(db, db, 5), []accData{ { addr: addrs[0], oldVal: block3ValAcc, @@ -962,7 +837,6 @@ func TestWalkAsOfAccountPlain(t *testing.T) { func TestWalkAsOfAccountPlain_WithChunks(t *testing.T) { db := ethdb.NewMemDatabase() defer db.Close() - tds := NewTrieDbState(common.Hash{}, db, 1) emptyValAcc := accounts.NewAccount() emptyVal := make([]byte, emptyValAcc.EncodingLengthForStorage()) emptyValAcc.EncodeForStorage(emptyVal) @@ -1000,7 +874,7 @@ func TestWalkAsOfAccountPlain_WithChunks(t *testing.T) { var addr1New, addr2New, addr3New *accounts.Account - writeBlockData(t, tds, 1, []accData{ + writeBlockData(t, NewPlainStateWriter(db, db, 1), []accData{ { addr: addrs[0], oldVal: &emptyValAcc, @@ -1025,7 +899,7 @@ func TestWalkAsOfAccountPlain_WithChunks(t *testing.T) { addr2New.Nonce = uint64(i) addr3New = addr3Old.SelfCopy() addr3New.Nonce = uint64(i) - writeBlockData(t, tds, uint64(i), []accData{ + writeBlockData(t, NewPlainStateWriter(db, db, uint64(i)), []accData{ { addr: addrs[0], oldVal: addr1Old, @@ -1054,7 +928,7 @@ func TestWalkAsOfAccountPlain_WithChunks(t *testing.T) { addr3New = addr3Old.SelfCopy() addr3New.Nonce = 1100 - writeBlockData(t, tds, 1100, []accData{ + writeBlockData(t, NewPlainStateWriter(db, db, 1100), []accData{ { addr: addrs[0], oldVal: addr1Old, @@ -1258,10 +1132,7 @@ type accData struct { newVal *accounts.Account } -func writeBlockData(t *testing.T, tds *TrieDbState, blockNum uint64, data []accData) { - tds.SetBlockNr(blockNum) - var blockWriter = tds.PlainStateWriter() - +func writeBlockData(t *testing.T, blockWriter *PlainStateWriter, data []accData) { for i := range data { if data[i].newVal != nil { if err := blockWriter.UpdateAccountData(context.Background(), data[i].addr, data[i].oldVal, data[i].newVal); err != nil { diff --git a/tests/state_test.go b/tests/state_test.go index 7fb41a38b..37260d1b5 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -93,7 +93,7 @@ func TestState(t *testing.T) { } // Transactions with gasLimit above this value will not get a VM trace on failure. -const traceErrorLimit = 400000 +const traceErrorLimit = 4000000000 func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { // Use config from command line arguments. diff --git a/tests/state_test_util.go b/tests/state_test_util.go index b0d71ee26..7ad96b196 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -185,11 +185,13 @@ func (t *StateTest) RunNoVerify(ctx context.Context, tx ethdb.Database, subtest ctx = config.WithEIPsFlags(ctx, big.NewInt(int64(writeBlockNr))) _, tds, err := MakePreState(context.Background(), tx, t.json.Pre, readBlockNr) + //_, err = MakePreState2(context.Background(), tx, t.json.Pre, readBlockNr) if err != nil { return nil, common.Hash{}, UnsupportedForkError{subtest.Fork} } statedb := state.New(state.NewDbStateReader(tx)) tds.StartNewBuffer() + w := state.NewDbStateWriter(tx, readBlockNr+1) post := t.json.Post[subtest.Fork][subtest.Index] msg, err := t.json.Tx.toMessage(post) @@ -211,7 +213,6 @@ func (t *StateTest) RunNoVerify(ctx context.Context, tx ethdb.Database, subtest statedb.RevertToSnapshot(snapshot) } - w := state.NewDbStateWriter(tx, block.NumberU64()) // Commit block if err = statedb.FinalizeTx(ctx, tds.TrieStateWriter()); err != nil { return nil, common.Hash{}, err @@ -273,7 +274,7 @@ func MakePreState(ctx context.Context, db ethdb.Database, accounts core.GenesisA } func MakePreState2(ctx context.Context, db ethdb.Database, accounts core.GenesisAlloc, blockNr uint64) (*state.IntraBlockState, error) { - r, w := state.NewDbStateReader(db), state.NewDbStateWriter(db, blockNr) + r, _ := state.NewDbStateReader(db), state.NewDbStateWriter(db, blockNr) statedb := state.New(r) for addr, a := range accounts { statedb.SetCode(addr, a.Code) @@ -287,9 +288,9 @@ func MakePreState2(ctx context.Context, db ethdb.Database, accounts core.Genesis } } // Commit and re-open to start with a clean state. - if err := statedb.FinalizeTx(ctx, w); err != nil { - return nil, err - } + //if err := statedb.FinalizeTx(ctx, state.NewNoopWriter()); err != nil { + // return nil, err + //} if err := statedb.CommitBlock(ctx, state.NewDbStateWriter(db, blockNr+1)); err != nil { return nil, err }