mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
feat: add TestGetLogsRange (#990)
This commit is contained in:
parent
f883ca89cb
commit
68713c4264
1 changed files with 58 additions and 0 deletions
|
|
@ -35,12 +35,14 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/core/rawdb"
|
"github.com/scroll-tech/go-ethereum/core/rawdb"
|
||||||
"github.com/scroll-tech/go-ethereum/core/state"
|
"github.com/scroll-tech/go-ethereum/core/state"
|
||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
|
"github.com/scroll-tech/go-ethereum/core/vm"
|
||||||
"github.com/scroll-tech/go-ethereum/crypto"
|
"github.com/scroll-tech/go-ethereum/crypto"
|
||||||
"github.com/scroll-tech/go-ethereum/ethdb"
|
"github.com/scroll-tech/go-ethereum/ethdb"
|
||||||
"github.com/scroll-tech/go-ethereum/event"
|
"github.com/scroll-tech/go-ethereum/event"
|
||||||
"github.com/scroll-tech/go-ethereum/internal/ethapi"
|
"github.com/scroll-tech/go-ethereum/internal/ethapi"
|
||||||
"github.com/scroll-tech/go-ethereum/params"
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
"github.com/scroll-tech/go-ethereum/rpc"
|
"github.com/scroll-tech/go-ethereum/rpc"
|
||||||
|
"github.com/scroll-tech/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testBackend struct {
|
type testBackend struct {
|
||||||
|
|
@ -456,6 +458,62 @@ func TestInvalidGetLogsRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetLogsRange(t *testing.T) {
|
||||||
|
var (
|
||||||
|
db = rawdb.NewMemoryDatabase()
|
||||||
|
_, sys = newTestFilterSystem(t, db, Config{})
|
||||||
|
api = NewFilterAPI(sys, false, 2)
|
||||||
|
)
|
||||||
|
|
||||||
|
gspec := &core.Genesis{
|
||||||
|
Config: params.TestChainConfig,
|
||||||
|
}
|
||||||
|
_, err := gspec.Commit(db, trie.NewDatabase(db, &trie.Config{IsUsingZktrie: true}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var l uint64
|
||||||
|
chain, err := core.NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, &l)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bs, _ := core.GenerateChain(params.TestChainConfig, chain.Genesis(), ethash.NewFaker(), db, 10, nil)
|
||||||
|
if _, err := chain.InsertChain(bs); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// those test cases should fail because block range is greater then limit
|
||||||
|
failTestCases := []FilterCriteria{
|
||||||
|
// from 0 to 2 block
|
||||||
|
0: {FromBlock: big.NewInt(0), ToBlock: big.NewInt(2)},
|
||||||
|
// from 8 to latest block (10)
|
||||||
|
1: {FromBlock: big.NewInt(8)},
|
||||||
|
// from 0 to latest block (10)
|
||||||
|
2: {FromBlock: big.NewInt(0)},
|
||||||
|
}
|
||||||
|
for i, test := range failTestCases {
|
||||||
|
if _, err := api.GetLogs(context.Background(), test); err == nil {
|
||||||
|
t.Errorf("Expected Logs for failing case #%d to fail", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
okTestCases := []FilterCriteria{
|
||||||
|
// from latest to latest block
|
||||||
|
0: {},
|
||||||
|
// from 9 to last block (10)
|
||||||
|
1: {FromBlock: big.NewInt(9)},
|
||||||
|
// from 3 to 4 block
|
||||||
|
2: {FromBlock: big.NewInt(3), ToBlock: big.NewInt(4)},
|
||||||
|
}
|
||||||
|
for i, test := range okTestCases {
|
||||||
|
if _, err := api.GetLogs(context.Background(), test); err != nil {
|
||||||
|
t.Errorf("Expected Logs for ok case #%d not to fail", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestLogFilter tests whether log filters match the correct logs that are posted to the event feed.
|
// TestLogFilter tests whether log filters match the correct logs that are posted to the event feed.
|
||||||
func TestLogFilter(t *testing.T) {
|
func TestLogFilter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue