mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
eth/filters: more testcase
Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
parent
6f672fa997
commit
88ac691d01
1 changed files with 18 additions and 6 deletions
|
|
@ -772,14 +772,16 @@ func TestLogsSubscription(t *testing.T) {
|
||||||
topic = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
|
topic = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
i2h := func(i int) common.Hash { return common.BigToHash(big.NewInt(int64(i))) }
|
||||||
|
|
||||||
allLogs := []*types.Log{
|
allLogs := []*types.Log{
|
||||||
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), common.BigToHash(big.NewInt(1))}, Data: common.BigToHash(big.NewInt(11)).Bytes(), BlockNumber: 1},
|
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), i2h(1)}, Data: i2h(11).Bytes(), BlockNumber: 1},
|
||||||
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), common.BigToHash(big.NewInt(2))}, Data: common.BigToHash(big.NewInt(12)).Bytes(), BlockNumber: 2},
|
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), i2h(2)}, Data: i2h(12).Bytes(), BlockNumber: 2},
|
||||||
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), common.BigToHash(big.NewInt(3))}, Data: common.BigToHash(big.NewInt(13)).Bytes(), BlockNumber: 3},
|
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), i2h(3)}, Data: i2h(13).Bytes(), BlockNumber: 3},
|
||||||
{Topics: []common.Hash{topic, common.HexToHash(addr.Hex()), common.BigToHash(big.NewInt(4))}, Data: common.BigToHash(big.NewInt(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())
|
pendingBlockNumber := big.NewInt(rpc.PendingBlockNumber.Int64())
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
crit FilterCriteria
|
crit FilterCriteria
|
||||||
expected []*types.Log
|
expected []*types.Log
|
||||||
|
|
@ -787,11 +789,21 @@ func TestLogsSubscription(t *testing.T) {
|
||||||
sub *rpc.Subscription
|
sub *rpc.Subscription
|
||||||
err chan error
|
err chan error
|
||||||
}{
|
}{
|
||||||
// from 1 to latest
|
// from 0 to latest
|
||||||
{
|
{
|
||||||
FilterCriteria{FromBlock: big.NewInt(0), ToBlock: big.NewInt(5)},
|
FilterCriteria{FromBlock: big.NewInt(0), ToBlock: big.NewInt(5)},
|
||||||
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil,
|
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil,
|
||||||
},
|
},
|
||||||
|
// from 1 to latest
|
||||||
|
{
|
||||||
|
FilterCriteria{FromBlock: big.NewInt(1), ToBlock: pendingBlockNumber},
|
||||||
|
allLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, 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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue