-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonrpc_test.go
50 lines (38 loc) · 868 Bytes
/
jsonrpc_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
47
48
49
50
package jsonrpc
import (
"testing"
log "github.com/fangdingjun/go-log/v5"
)
func TestCall(t *testing.T) {
log.Default.Level = log.DEBUG
url := "http://192.168.56.101:8545/"
c, _ := NewClient(url)
var ret string
err := c.Call("eth_getBalance", []string{"0x00CB25f6fD16a52e24eDd2c8fd62071dc29A035c", "latest"}, &ret)
if err != nil {
t.Error(err)
return
}
log.Printf("result: %+v", ret)
c1, err := NewClient("ws://192.168.56.101:8546")
if err != nil {
t.Error(err)
return
}
var gas string
err = c1.Call("eth_gasPrice", []string{}, &gas)
if err != nil {
t.Error(err)
return
}
log.Println("gas", gas)
var r string
ch, errch, err := c1.Subscribe("eth_subscribe", "eth_subscription", []interface{}{"newHeads"}, &r)
log.Println("subid", r)
select {
case d := <-ch:
log.Printf("%s", d)
case e := <-errch:
log.Println(e)
}
}