diff options
author | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2016-10-14 11:47:09 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-11-09 09:12:53 +0800 |
commit | 760fd65487614b7a61443cd9371015925795f40f (patch) | |
tree | a2b122f03b7782e729be85b136f4c5304a164c9e /light/state_test.go | |
parent | 8b1df1a259fe6dc4c15e391e9c0762c9621d9d72 (diff) | |
download | go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.gz go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.bz2 go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.lz go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.xz go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.zst go-tangerine-760fd65487614b7a61443cd9371015925795f40f.zip |
light: light chain, VM env and tx pool
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") } } |