mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
eth/filters: more testcase
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
a374b1b6ea
commit
223f05ff76
1 changed files with 40 additions and 15 deletions
|
|
@ -781,35 +781,60 @@ func TestLogsSubscription(t *testing.T) {
|
||||||
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), i2h(4)}, Data: i2h(14).Bytes(), BlockNumber: 4},
|
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), i2h(4)}, Data: i2h(14).Bytes(), BlockNumber: 4},
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingBlockNumber := big.NewInt(rpc.PendingBlockNumber.Int64())
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
crit FilterCriteria
|
crit FilterCriteria
|
||||||
expected []*types.Log
|
expected []*types.Log
|
||||||
notifier *mockNotifier
|
notifier *mockNotifier
|
||||||
sub *rpc.Subscription
|
sub *rpc.Subscription
|
||||||
err chan error
|
expectErr error
|
||||||
|
err chan error
|
||||||
}{
|
}{
|
||||||
// from 0 to latest
|
// from 0 to latest
|
||||||
{
|
{
|
||||||
FilterCriteria{FromBlock: big.NewInt(0), ToBlock: big.NewInt(5)},
|
FilterCriteria{FromBlock: big.NewInt(0)},
|
||||||
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil,
|
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||||
},
|
},
|
||||||
// from 1 to latest
|
// from 1 to latest
|
||||||
{
|
{
|
||||||
FilterCriteria{FromBlock: big.NewInt(1), ToBlock: pendingBlockNumber},
|
FilterCriteria{FromBlock: big.NewInt(1), ToBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
|
||||||
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil,
|
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||||
|
},
|
||||||
|
// from 2 to latest
|
||||||
|
{
|
||||||
|
FilterCriteria{FromBlock: big.NewInt(2)},
|
||||||
|
allLogs[1:], newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||||
|
},
|
||||||
|
// from latest to latest
|
||||||
|
{
|
||||||
|
FilterCriteria{},
|
||||||
|
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||||
|
},
|
||||||
|
// from 1 to 3
|
||||||
|
{
|
||||||
|
FilterCriteria{FromBlock: big.NewInt(1), ToBlock: big.NewInt(3)},
|
||||||
|
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, errInvalidToBlock, nil,
|
||||||
|
},
|
||||||
|
// from -101 to latest
|
||||||
|
{
|
||||||
|
FilterCriteria{FromBlock: big.NewInt(-101)},
|
||||||
|
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, errInvalidFromBlock, nil,
|
||||||
},
|
},
|
||||||
// // from 1 to 3
|
|
||||||
// {
|
|
||||||
// FilterCriteria{FromBlock: big.NewInt(1), ToBlock: big.NewInt(3)},
|
|
||||||
// allLogs[0:3], newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil,
|
|
||||||
// },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscribe logs
|
// subscribe logs
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
testCases[i].err = make(chan error)
|
testCases[i].err = make(chan error)
|
||||||
err := api.logs(context.Background(), tc.notifier, tc.sub, tc.crit)
|
err := api.logs(context.Background(), tc.notifier, tc.sub, tc.crit)
|
||||||
|
if tc.expectErr != nil {
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("test %d: want error %v, have nothing", i, tc.expectErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !errors.Is(err, tc.expectErr) {
|
||||||
|
t.Errorf("test %d: error mismatch, want %v, have %v", i, tc.expectErr, err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("SubscribeLogs %d failed: %v\n", i, err)
|
t.Fatalf("SubscribeLogs %d failed: %v\n", i, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue