-
Notifications
You must be signed in to change notification settings - Fork 2
/
handlers_rpc_test.go
98 lines (89 loc) · 2.34 KB
/
handlers_rpc_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package hypersyncgo
import (
"context"
"github.com/enviodev/hypersync-client-go/options"
"github.com/enviodev/hypersync-client-go/utils"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"math/big"
"testing"
)
func TestHeaderByNumber(t *testing.T) {
testCases := []struct {
name string
opts options.Options
blockNumbers []*big.Int
}{{
name: "Test Ethereum Client",
opts: options.Options{
LogLevel: zap.DebugLevel,
Blockchains: []options.Node{
{
Type: utils.EthereumNetwork,
NetworkId: utils.EthereumNetworkID,
Endpoint: "https://eth.hypersync.xyz",
RpcEndpoint: "https://eth.rpc.hypersync.xyz",
},
},
},
blockNumbers: []*big.Int{
big.NewInt(10000000),
},
}}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Fetch the first node out of the blockchain definitions
nodeOpts := testCase.opts.Blockchains[0]
client, err := NewClient(ctx, nodeOpts)
require.NoError(t, err)
require.NotNil(t, client)
for _, q := range testCase.blockNumbers {
resp, rErr := client.HeaderByNumber(ctx, q)
require.NoError(t, rErr)
require.NotNil(t, resp)
require.Equal(t, resp.Number, q)
}
})
}
}
func TestBlockByNumber(t *testing.T) {
testCases := []struct {
name string
opts options.Options
blockNumbers []*big.Int
}{{
name: "Test Ethereum Client",
opts: options.Options{
LogLevel: zap.DebugLevel,
Blockchains: []options.Node{
{
Type: utils.EthereumNetwork,
NetworkId: utils.EthereumNetworkID,
Endpoint: "https://eth.hypersync.xyz",
RpcEndpoint: "https://eth.rpc.hypersync.xyz",
},
},
},
blockNumbers: []*big.Int{
big.NewInt(10000000),
},
}}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Fetch the first node out of the blockchain definitions
nodeOpts := testCase.opts.Blockchains[0]
client, err := NewClient(ctx, nodeOpts)
require.NoError(t, err)
require.NotNil(t, client)
for _, q := range testCase.blockNumbers {
resp, rErr := client.BlockByNumber(ctx, q)
require.NoError(t, rErr)
require.NotNil(t, resp)
}
})
}
}