mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
more
This commit is contained in:
parent
d680d1453a
commit
33c0e7eede
1 changed files with 33 additions and 19 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -30,6 +31,25 @@ import (
|
||||||
|
|
||||||
var dumper = spew.ConfigState{Indent: " "}
|
var dumper = spew.ConfigState{Indent: " "}
|
||||||
|
|
||||||
|
func accountRangeExpect(t *testing.T, trie *state.Trie, statedb *state.StateDB, start *common.Address, requestedNum int, expectedNum int) AccountRangeResult {
|
||||||
|
result, err := accountRange(*trie, start, requestedNum)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result.Addresses) != expectedNum {
|
||||||
|
t.Fatalf("expected %d results. Got %d", expectedNum, len(result.Addresses))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range result.Addresses {
|
||||||
|
if !statedb.Exist(result.Addresses[i]) {
|
||||||
|
t.Fatalf("account not found in state %s", result.Addresses[i].String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccountRangeAt(t *testing.T) {
|
func TestAccountRangeAt(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
statedb = state.NewDatabase(ethdb.NewMemDatabase())
|
statedb = state.NewDatabase(ethdb.NewMemDatabase())
|
||||||
|
|
@ -53,30 +73,24 @@ func TestAccountRangeAt(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test getting number of results less than max
|
// test getting number of results less than max
|
||||||
|
accountRangeExpect(t, &trie, state, &common.Address{0x0}, 128, 128)
|
||||||
result, err := accountRange(trie, &common.Address{0x0}, 128)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Addresses) != 128 {
|
|
||||||
t.Fatalf("expected 128 results. Got %d", len(result.Addresses))
|
|
||||||
}
|
|
||||||
|
|
||||||
// test getting number of results greater than max
|
// test getting number of results greater than max
|
||||||
|
accountRangeExpect(t, &trie, state, &common.Address{0x0}, 512, 256)
|
||||||
|
|
||||||
result, err = accountRange(trie, &common.Address{0x0}, 512)
|
// test pagination
|
||||||
if err != nil {
|
firstResult := accountRangeExpect(t, &trie, state, &common.Address{0x0}, 128, 128)
|
||||||
t.Fatal(err)
|
secondResult := accountRangeExpect(t, &trie, state, &firstResult.Next, 128, 128)
|
||||||
|
|
||||||
|
for i := range firstResult.Addresses {
|
||||||
|
for j := range secondResult.Addresses {
|
||||||
|
if bytes.Equal(firstResult.Addresses[i].Bytes(), secondResult.Addresses[j].Bytes()) {
|
||||||
|
t.Fatalf("pagination test failed: results should not overlap")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(result.Addresses) != 256 {
|
|
||||||
t.Fatalf("expected 256 results. Got %d", len(result.Addresses))
|
|
||||||
}
|
|
||||||
|
|
||||||
// test pagination TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageRangeAt(t *testing.T) {
|
func TestStorageRangeAt(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue