-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethclient_context_test.go
46 lines (40 loc) · 1.21 KB
/
ethclient_context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package chainclient
import (
"context"
"github.com/ethereum/go-ethereum/common"
"math/big"
"testing"
"time"
)
func Test_GetLog(t *testing.T) {
ethcontext := NewEthClientContext("ws://8.219.126.197:6790", "lat", MockWalletInstance())
logs, _ := ethcontext.GetLog(context.Background(), common.HexToAddress("0xfd67957F61F9cC7A85da7657ED0B54b0A5867223"), new(big.Int).SetUint64(26301099))
for _, log := range logs {
t.Logf("log:%+v", log)
}
}
func Test_GetLogTimeout(t *testing.T) {
// 遍历区块日志,查询document其它数据
timeout := time.Duration(3000) * time.Millisecond
timeoutCtx, cancelFn := context.WithTimeout(context.Background(), timeout)
defer cancelFn()
ethcontext := NewEthClientContext("ws://8.219.126.197:6790", "lat", MockWalletInstance())
prevBlock := new(big.Int).SetUint64(26301099)
breakFor := false
go func() {
for prevBlock.Uint64() > 0 && !breakFor {
logs, _ := ethcontext.GetLog(timeoutCtx, common.HexToAddress("0xfd67957F61F9cC7A85da7657ED0B54b0A5867223"), new(big.Int).SetUint64(26301099))
for _, log := range logs {
t.Logf("log:%+v", log)
}
cancelFn()
return
}
cancelFn()
}()
select {
case <-timeoutCtx.Done():
t.Log("timeout done")
breakFor = true
}
}