You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
865 B
Go

6 years ago
package jsonrpc
import (
"testing"
log "github.com/fangdingjun/go-log"
6 years ago
)
func TestCall(t *testing.T) {
log.Default.Level = log.DEBUG
url := "http://192.168.56.101:8545/"
6 years ago
c, _ := NewClient(url)
var ret string
6 years ago
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")
6 years ago
if err != nil {
t.Error(err)
return
}
var gas string
err = c1.Call("eth_gasPrice", []string{}, &gas)
if err != nil {
t.Error(err)
6 years ago
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)
6 years ago
}
}