forked from forta-network/go-multicall
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchain_test.go
220 lines (199 loc) · 4.74 KB
/
chain_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package multicall
import (
"context"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type chainERC20TestCase struct {
chain string
rpcURL string
contract string
address string
multicallAddr string
}
const deadAddr = "0x000000000000000000000000000000000000dEaD"
var ttCall = []chainERC20TestCase{
{
chain: "MANTLE",
rpcURL: "https://5000.rpc.thirdweb.com",
address: deadAddr,
contract: "0x371c7ec6D8039ff7933a2AA28EB827Ffe1F52f07",
},
{
chain: "ONTOLOGY",
rpcURL: "https://dappnode3.ont.io:10339",
// rpcURL: "https://dappnode4.ont.io:10339",
address: "0x3c1edbff210cb10311359ca2fce711d6b8c74073",
contract: "0xae834526aa3b70de9b34f81c4bf51bc2c80a5473",
multicallAddr: "0x381e7fb9671aad4b48d02dbee167b1e4cbf597ae",
},
}
func TestCall_ChainERC20(t *testing.T) {
ctx := context.Background()
abiERC20, err := ParseABI(ERC20ABI)
if err != nil {
t.Fatal(err)
}
for _, tt := range ttCall {
t.Run(tt.chain, func(t *testing.T) {
var multicallAddresses []string
if tt.multicallAddr != "" {
multicallAddresses = []string{tt.multicallAddr}
}
caller, err := Dial(ctx, tt.rpcURL, multicallAddresses...)
if err != nil {
t.Fatal(err)
}
var calls []*Call
notContract := &Contract{
ABI: abiERC20,
Address: common.HexToAddress(tt.contract),
}
notContractBalance := new(BalanceOutput)
decimals := new(DecimalsOutput)
calls = append(calls, notContract.NewCall(
notContractBalance,
"balanceOf",
common.HexToAddress(tt.address),
).AllowFailure())
calls = append(calls, notContract.NewCall(
decimals,
"decimals",
).AllowFailure())
res, err := caller.Call(nil, calls...)
if err != nil {
t.Error(err)
return
}
if len(res) == 0 {
t.Error("no results")
return
}
require.False(t, res[0].Failed)
assert.True(t, res[0].Outputs.(*BalanceOutput).Balance.Cmp(big.NewInt(0)) > 0)
t.Log(notContractBalance.Balance)
t.Log(res[0].Failed)
t.Log(decimals.Decimals)
})
}
}
const MulticallABI = `[
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "getEthBalance",
"outputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]`
func TestCall_ChainEthBalance(t *testing.T) {
ctx := context.Background()
abiERC20, err := ParseABI(MulticallABI)
if err != nil {
t.Fatal(err)
}
for _, tt := range ttCall {
t.Run(tt.chain, func(t *testing.T) {
var multicallAddresses []string
if tt.multicallAddr != "" {
multicallAddresses = []string{tt.multicallAddr}
}
caller, err := Dial(ctx, tt.rpcURL, multicallAddresses...)
if err != nil {
t.Fatal(err)
}
var calls []*Call
var maddr string
if tt.multicallAddr != "" {
maddr = tt.multicallAddr
} else {
maddr = DefaultAddress
}
mcontract := &Contract{
ABI: abiERC20,
Address: common.HexToAddress(maddr),
}
mbalance := new(BalanceOutput)
calls = append(calls, mcontract.NewCall(
mbalance,
"getEthBalance",
common.HexToAddress(tt.address),
).AllowFailure())
res, err := caller.Call(nil, calls...)
if err != nil {
t.Error(err)
return
}
if len(res) == 0 {
t.Error("no results")
return
}
assert.False(t, res[0].Failed)
assert.True(t, res[0].Outputs.(*BalanceOutput).Balance.Cmp(big.NewInt(0)) > 0)
t.Log(mbalance.Balance)
t.Log(res[0].Failed)
})
}
}
func TestOntology(t *testing.T) {
ctx := context.Background()
rpcURL := "https://dappnode3.ont.io:10339"
multicallAddress := "0x381e7fb9671aad4b48d02dbee167b1e4cbf597ae"
contractAddress := "0xae834526aa3b70de9b34f81c4bf51bc2c80a5473"
address := deadAddr
abiERC20, err := ParseABI(ERC20ABI)
if err != nil {
t.Fatal(err)
}
caller, err := Dial(ctx, rpcURL, multicallAddress)
if err != nil {
t.Fatal(err)
}
var calls []*Call
erc20Contract := &Contract{
ABI: abiERC20,
Address: common.HexToAddress(contractAddress),
}
rBalance := new(BalanceOutput)
rDecimals := new(DecimalsOutput)
calls = append(calls, erc20Contract.NewCall(
rBalance,
"balanceOf",
common.HexToAddress(address),
).AllowFailure())
calls = append(calls, erc20Contract.NewCall(
rDecimals,
"decimals",
).AllowFailure())
t.Log(rpcURL)
t.Log(multicallAddress)
t.Log(contractAddress)
t.Log(address)
res, err := caller.Call(nil, calls...)
if err != nil {
t.Error(err)
return
}
if len(res) == 0 {
t.Error("no results")
return
}
t.Log(rBalance.Balance)
t.Log(res[0].Failed)
t.Log(rDecimals.Decimals)
}