mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
eth/filters: testing pending with latest
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
7f3b72fe10
commit
69a14cb0ae
2 changed files with 37 additions and 1 deletions
|
|
@ -39,6 +39,10 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidFromTo = errors.New("invalid from and to block combination: from > to")
|
||||
)
|
||||
|
||||
// Config represents the configuration of the filter system.
|
||||
type Config struct {
|
||||
LogCacheSize int // maximum number of cached blocks (default: 32)
|
||||
|
|
@ -335,7 +339,24 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
|
|||
if from >= 0 && to == rpc.LatestBlockNumber {
|
||||
return es.subscribeLogs(crit, logs), nil
|
||||
}
|
||||
return nil, errInvalidBlockRange
|
||||
return nil, errInvalidFromTo
|
||||
}
|
||||
|
||||
// subscribeMinedPendingLogs creates a subscription that returned mined and
|
||||
// pending logs that match the given criteria.
|
||||
func (es *EventSystem) subscribeMinedPendingLogs(crit ethereum.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
sub := &subscription{
|
||||
id: rpc.NewID(),
|
||||
typ: MinedAndPendingLogsSubscription,
|
||||
logsCrit: crit,
|
||||
created: time.Now(),
|
||||
logs: logs,
|
||||
txs: make(chan []*types.Transaction),
|
||||
headers: make(chan *types.Header),
|
||||
installed: make(chan struct{}),
|
||||
err: make(chan error),
|
||||
}
|
||||
return es.subscribe(sub)
|
||||
}
|
||||
|
||||
// subscribeLogs creates a subscription that will write all logs matching the
|
||||
|
|
|
|||
|
|
@ -809,6 +809,21 @@ func TestLogsSubscription(t *testing.T) {
|
|||
FilterCriteria{},
|
||||
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||
},
|
||||
// from pending to pending
|
||||
{
|
||||
FilterCriteria{FromBlock: big.NewInt(rpc.PendingBlockNumber.Int64()), ToBlock: big.NewInt(rpc.PendingBlockNumber.Int64())},
|
||||
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||
},
|
||||
// from latest to pending
|
||||
{
|
||||
FilterCriteria{FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64()), ToBlock: big.NewInt(rpc.PendingBlockNumber.Int64())},
|
||||
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||
},
|
||||
// from pending to latest
|
||||
{
|
||||
FilterCriteria{FromBlock: big.NewInt(rpc.PendingBlockNumber.Int64()), ToBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
|
||||
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, errInvalidFromTo, nil,
|
||||
},
|
||||
// from 1 to 3
|
||||
{
|
||||
FilterCriteria{FromBlock: big.NewInt(1), ToBlock: big.NewInt(3)},
|
||||
|
|
|
|||
Loading…
Reference in a new issue