diff options
author | Felix Lange <fjl@twurst.com> | 2016-11-09 10:09:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-09 10:09:05 +0800 |
commit | 355f4b0c15fadec683877b5de1361bd678fee28e (patch) | |
tree | ef1c3a915af7f07c049c08318fe450b2ecf46654 /light/state_test.go | |
parent | 8b1df1a259fe6dc4c15e391e9c0762c9621d9d72 (diff) | |
parent | bbb5e5d56a51d9430aec934c76a0bd02f1f2427d (diff) | |
download | go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar.gz go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar.bz2 go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar.lz go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar.xz go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.tar.zst go-tangerine-355f4b0c15fadec683877b5de1361bd678fee28e.zip |
Merge pull request #3232 from zsfelfoldi/light-topic3
Diffstat (limited to 'light/state_test.go')
-rw-r--r-- | light/state_test.go | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/light/state_test.go b/light/state_test.go index a6b115786..89a64483d 100644 --- a/light/state_test.go +++ b/light/state_test.go @@ -22,33 +22,13 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/trie" "golang.org/x/net/context" ) -type testOdr struct { - OdrBackend - sdb, ldb ethdb.Database -} - -func (odr *testOdr) Database() ethdb.Database { - return odr.ldb -} - -func (odr *testOdr) Retrieve(ctx context.Context, req OdrRequest) error { - switch req := req.(type) { - case *TrieRequest: - t, _ := trie.New(req.root, odr.sdb) - req.proof = t.Prove(req.key) - case *NodeDataRequest: - req.data, _ = odr.sdb.Get(req.hash[:]) - } - req.StoreResult(odr.ldb) - return nil -} - func makeTestState() (common.Hash, ethdb.Database) { sdb, _ := ethdb.NewMemDatabase() st, _ := state.New(common.Hash{}, sdb) @@ -67,9 +47,11 @@ func makeTestState() (common.Hash, ethdb.Database) { func TestLightStateOdr(t *testing.T) { root, sdb := makeTestState() + header := &types.Header{Root: root, Number: big.NewInt(0)} + core.WriteHeader(sdb, header) ldb, _ := ethdb.NewMemDatabase() odr := &testOdr{sdb: sdb, ldb: ldb} - ls := NewLightState(root, odr) + ls := NewLightState(StateTrieID(header), odr) ctx := context.Background() for i := byte(0); i < 100; i++ { @@ -151,9 +133,11 @@ func TestLightStateOdr(t *testing.T) { func TestLightStateSetCopy(t *testing.T) { root, sdb := makeTestState() + header := &types.Header{Root: root, Number: big.NewInt(0)} + core.WriteHeader(sdb, header) ldb, _ := ethdb.NewMemDatabase() odr := &testOdr{sdb: sdb, ldb: ldb} - ls := NewLightState(root, odr) + ls := NewLightState(StateTrieID(header), odr) ctx := context.Background() for i := byte(0); i < 100; i++ { @@ -227,9 +211,11 @@ func TestLightStateSetCopy(t *testing.T) { func TestLightStateDelete(t *testing.T) { root, sdb := makeTestState() + header := &types.Header{Root: root, Number: big.NewInt(0)} + core.WriteHeader(sdb, header) ldb, _ := ethdb.NewMemDatabase() odr := &testOdr{sdb: sdb, ldb: ldb} - ls := NewLightState(root, odr) + ls := NewLightState(StateTrieID(header), odr) ctx := context.Background() addr := common.Address{42} @@ -242,21 +228,21 @@ func TestLightStateDelete(t *testing.T) { t.Fatalf("HasAccount returned false, expected true") } - b, err = ls.IsDeleted(ctx, addr) + b, err = ls.HasSuicided(ctx, addr) if err != nil { - t.Fatalf("IsDeleted error: %v", err) + t.Fatalf("HasSuicided error: %v", err) } if b { - t.Fatalf("IsDeleted returned true, expected false") + t.Fatalf("HasSuicided returned true, expected false") } - ls.Delete(ctx, addr) + ls.Suicide(ctx, addr) - b, err = ls.IsDeleted(ctx, addr) + b, err = ls.HasSuicided(ctx, addr) if err != nil { - t.Fatalf("IsDeleted error: %v", err) + t.Fatalf("HasSuicided error: %v", err) } if !b { - t.Fatalf("IsDeleted returned false, expected true") + t.Fatalf("HasSuicided returned false, expected true") } } |