-
Notifications
You must be signed in to change notification settings - Fork 1
/
ethrpc_test.go
107 lines (84 loc) · 2.23 KB
/
ethrpc_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
99
100
101
102
103
104
105
106
107
package ethrpc
import (
"context"
"fmt"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"
)
type RPCTestSuite struct {
suite.Suite
client *Client
}
func (ts *RPCTestSuite) SetupTest() {
// Setup RPC server
rpcClient := New("https://eth.llamarpc.com")
rpcClient.SetMulticallContract(common.HexToAddress("0x5ba1e12693dc8f9c48aad8770482f4739beed696"))
ts.client = rpcClient
}
func (ts *RPCTestSuite) TestGetBlockNumber() {
blockNumber, err := ts.client.GetBlockNumber(context.Background())
ts.Require().NoError(err)
ts.Require().NotEqual(0, blockNumber)
}
func (ts *RPCTestSuite) TestTryAggregate() {
type TradeInfo struct {
Reserve0 *big.Int
Reserve1 *big.Int
VReserve0 *big.Int
VReserve1 *big.Int
FeeInPrecision *big.Int
}
pools := []string{
"0x9a56f30ff04884cb06da80cb3aef09c6132f5e77",
"0x5ba740fcc020d5b9e39760cbd2fe236586b9dc0a",
"0x1cf68bbc2b6d3c6cfe1bd3590cf0e10b06a05f17",
}
reserves := make([]TradeInfo, len(pools))
req := ts.client.NewRequest()
for i, p := range pools {
req.AddCall(&Call{
ABI: dmmPoolABI,
Target: p,
Method: "getTradeInfo",
Params: nil,
}, []interface{}{&reserves[i]})
}
res, err := req.TryAggregate()
fmt.Printf("%+v\n", reserves)
ts.Require().NoError(err)
ts.Require().Len(res.Result, len(req.Calls))
}
func (ts *RPCTestSuite) TestTryBlockAggregate() {
type TradeInfo struct {
Reserve0 *big.Int
Reserve1 *big.Int
VReserve0 *big.Int
VReserve1 *big.Int
FeeInPrecision *big.Int
}
pools := []string{
"0x9a56f30ff04884cb06da80cb3aef09c6132f5e77",
"0x5ba740fcc020d5b9e39760cbd2fe236586b9dc0a",
"0x1cf68bbc2b6d3c6cfe1bd3590cf0e10b06a05f17",
}
reserves := make([]TradeInfo, len(pools))
req := ts.client.NewRequest()
for i, p := range pools {
req.AddCall(&Call{
ABI: dmmPoolABI,
Target: p,
Method: "getTradeInfo",
Params: nil,
}, []interface{}{&reserves[i]})
}
res, err := req.TryBlockAndAggregate()
fmt.Printf("%+v\n", reserves)
fmt.Printf("Block Number: %+v\n", res.BlockNumber.Int64())
ts.Require().NoError(err)
//ts.Require().Len(res.Result, len(req.Calls))
}
func TestRPCTestSuite(t *testing.T) {
suite.Run(t, new(RPCTestSuite))
}