diff --git a/core/state/dump.go b/core/state/dump.go index 116e238908..c378282e86 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -44,7 +44,9 @@ type Dump struct { } // iterativeDump is a 'collector'-implementation which dump output line-by-line iteratively -type iterativeDump json.Encoder +type iterativeDump struct { + *json.Encoder +} // Collector interface which the state trie calls during iteration type collector interface { @@ -74,11 +76,11 @@ func (d iterativeDump) onAccount(addr common.Address, account DumpAccount) { if addr != (common.Address{}) { dumpAccount.Address = &addr } - (*json.Encoder)(&d).Encode(dumpAccount) + d.Encode(dumpAccount) } func (d iterativeDump) onRoot(root common.Hash) { - (*json.Encoder)(&d).Encode(struct { + d.Encode(struct { Root common.Hash `json:"root"` }{root}) } @@ -152,5 +154,5 @@ func (s *StateDB) Dump(excludeCode, excludeStorage, excludeMissingPreimages bool // IterativeDump dumps out accounts as json-objects, delimited by linebreaks on stdout func (s *StateDB) IterativeDump(excludeCode, excludeStorage, excludeMissingPreimages bool, output *json.Encoder) { - s.dump(iterativeDump(*output), excludeCode, excludeStorage, excludeMissingPreimages) + s.dump(iterativeDump{output}, excludeCode, excludeStorage, excludeMissingPreimages) } diff --git a/core/state/journal.go b/core/state/journal.go index 128cbb7fb2..bcade2f456 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -127,9 +127,7 @@ type ( hash common.Hash } touchChange struct { - account *common.Address - prev bool - prevDirty bool + account *common.Address } // Changes to the access list accessListAddAccountChange struct { diff --git a/core/state/main_test.go b/core/state/main_test.go deleted file mode 100644 index cd9661031f..0000000000 --- a/core/state/main_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package state - -import ( - "testing" - - checker "gopkg.in/check.v1" -) - -func Test(t *testing.T) { checker.TestingT(t) } diff --git a/core/state/state_test.go b/core/state/state_test.go index eedd5931bf..4b312619d7 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -26,17 +26,24 @@ import ( "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/ethdb" - checker "gopkg.in/check.v1" ) -type StateSuite struct { +var toAddr = common.BytesToAddress + +type stateTest struct { db ethdb.Database state *StateDB } -var _ = checker.Suite(&StateSuite{}) +func newStateTest() *stateTest { + db := rawdb.NewMemoryDatabase() + sdb, _ := New(common.Hash{}, NewDatabase(db)) + return &stateTest{db: db, state: sdb} +} + +func TestDump(t *testing.T) { + s := newStateTest() -func (s *StateSuite) TestDump(c *checker.C) { // generate a few entries obj1 := s.state.GetOrNewStateObject(common.BytesToAddress([]byte{0x01})) obj1.AddBalance(big.NewInt(22)) @@ -77,16 +84,12 @@ func (s *StateSuite) TestDump(c *checker.C) { } }` if got != want { - c.Errorf("dump mismatch:\ngot: %s\nwant: %s\n", got, want) + t.Errorf("dump mismatch:\ngot: %s\nwant: %s\n", got, want) } } -func (s *StateSuite) SetUpTest(c *checker.C) { - s.db = rawdb.NewMemoryDatabase() - s.state, _ = New(types.EmptyRootHash, NewDatabase(s.db)) -} - -func (s *StateSuite) TestNull(c *checker.C) { +func TestNull(t *testing.T) { + s := newStateTest() address := common.HexToAddress("0x823140710bf13990e4500136726d8b55") s.state.CreateAccount(address) //value := common.FromHex("0x823140710bf13990e4500136726d8b55") @@ -96,18 +99,19 @@ func (s *StateSuite) TestNull(c *checker.C) { s.state.Commit(false) if value := s.state.GetState(address, common.Hash{}); value != (common.Hash{}) { - c.Errorf("expected empty current value, got %x", value) + t.Errorf("expected empty current value, got %x", value) } if value := s.state.GetCommittedState(address, common.Hash{}); value != (common.Hash{}) { - c.Errorf("expected empty committed value, got %x", value) + t.Errorf("expected empty committed value, got %x", value) } } -func (s *StateSuite) TestSnapshot(c *checker.C) { - stateobjaddr := common.BytesToAddress([]byte("aa")) +func TestSnapshot(t *testing.T) { + stateobjaddr := toAddr([]byte("aa")) var storageaddr common.Hash data1 := common.BytesToHash([]byte{42}) data2 := common.BytesToHash([]byte{43}) + s := newStateTest() // snapshot the genesis state genesis := s.state.Snapshot() @@ -120,21 +124,28 @@ func (s *StateSuite) TestSnapshot(c *checker.C) { s.state.SetState(stateobjaddr, storageaddr, data2) s.state.RevertToSnapshot(snapshot) - c.Assert(s.state.GetState(stateobjaddr, storageaddr), checker.DeepEquals, data1) - c.Assert(s.state.GetCommittedState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) + if v := s.state.GetState(stateobjaddr, storageaddr); v != data1 { + t.Errorf("wrong storage value %v, want %v", v, data1) + } + if v := s.state.GetCommittedState(stateobjaddr, storageaddr); v != (common.Hash{}) { + t.Errorf("wrong committed storage value %v, want %v", v, common.Hash{}) + } // revert up to the genesis state and ensure correct content s.state.RevertToSnapshot(genesis) - c.Assert(s.state.GetState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) - c.Assert(s.state.GetCommittedState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) + if v := s.state.GetState(stateobjaddr, storageaddr); v != (common.Hash{}) { + t.Errorf("wrong storage value %v, want %v", v, common.Hash{}) + } + if v := s.state.GetCommittedState(stateobjaddr, storageaddr); v != (common.Hash{}) { + t.Errorf("wrong committed storage value %v, want %v", v, common.Hash{}) + } } -func (s *StateSuite) TestSnapshotEmpty(c *checker.C) { +func TestSnapshotEmpty(t *testing.T) { + s := newStateTest() s.state.RevertToSnapshot(s.state.Snapshot()) } -// use testing instead of checker because checker does not support -// printing/logging in tests (-check.vv does not work) func TestSnapshot2(t *testing.T) { db := rawdb.NewMemoryDatabase() state, _ := New(types.EmptyRootHash, NewDatabase(db)) diff --git a/core/state/statedb.go b/core/state/statedb.go index d3f436acf9..ad3d32aeac 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -521,7 +521,7 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject { // getDeletedStateObject is similar to getStateObject, but instead of returning // nil for a deleted state object, it returns the actual object with the deleted -// flag set. This is needed by the state journal to revert to the correct self- +// flag set. This is needed by the state journal to revert to the correct s- // destructed object instead of wiping all knowledge about the state object. func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { // Prefer live objects if any is available diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index f762e31d47..dd47c76180 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -32,7 +32,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/types" - "gopkg.in/check.v1" ) // Tests that updating a state trie does not leak any database writes prior to @@ -481,7 +480,8 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error { return nil } -func (s *StateSuite) TestTouchDelete(c *check.C) { +func TestTouchDelete(t *testing.T) { + s := newStateTest() s.state.GetOrNewStateObject(common.Address{}) root, _ := s.state.Commit(false) s.state.Reset(root) @@ -490,11 +490,11 @@ func (s *StateSuite) TestTouchDelete(c *check.C) { s.state.AddBalance(common.Address{}, new(big.Int)) if len(s.state.journal.dirties) != 1 { - c.Fatal("expected one dirty state object") + t.Fatal("expected one dirty state object") } s.state.RevertToSnapshot(snapshot) if len(s.state.journal.dirties) != 0 { - c.Fatal("expected no dirty state object") + t.Fatal("expected no dirty state object") } } diff --git a/go.mod b/go.mod index 677a966c87..3337b85658 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( golang.org/x/sync v0.9.0 golang.org/x/sys v0.27.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 ) @@ -77,13 +77,11 @@ require ( github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect github.com/kilic/bls12-381 v0.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.8.0 // indirect