-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_test.go
61 lines (51 loc) · 1.09 KB
/
rest_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
51
52
53
54
55
56
57
58
59
60
61
package restgo
import (
"testing"
)
func Test_Get(t *testing.T) {
type Data struct {
HeadSlot string `json:"head_slot"`
}
type Response struct {
Data Data `json:"data"`
}
var res Response
err := Get("http://35.87.169.9:5052/eth/v1/node/syncing", &res)
if err != nil {
t.Errorf("%v", err)
}
t.Logf("res: %+v\n", res)
}
/*
request:
curl https://docs-demo.quiknode.pro/ \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}'
response:
{"jsonrpc":"2.0","id":1,"result":"0x1"}
*/
func Test_Post(t *testing.T) {
type Request struct {
Method string `json:"method"`
Params []string `json:"params"`
Id int `json:"id"`
Jsonrpc string `json:"jsonrpc"`
}
type Response struct {
Id int `json:"id"`
Jsonrpc string `json:"jsonrpc"`
Result string `json:"result"`
}
var res Response
err := Post("https://docs-demo.quiknode.pro", &Request{
Method: "eth_chainId",
Params: nil,
Id: 1,
Jsonrpc: "2.0",
}, &res)
if err != nil {
t.Errorf("%v", err)
}
t.Logf("res: %+v\n", res)
}