This repository was archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_decode_test.go
235 lines (225 loc) · 5.72 KB
/
client_decode_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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package seth_test
import (
"math/big"
"testing"
"github.com/smartcontractkit/seth"
"github.com/stretchr/testify/require"
)
func TestSmokeDebugReverts(t *testing.T) {
c := newClient(t)
type test struct {
name string
method string
output map[string]string
}
tests := []test{
{
name: "revert with require",
method: "alwaysRevertsRequire",
output: map[string]string{
seth.GETH: "execution reverted: always revert error",
seth.ANVIL: "execution reverted: revert: always revert error",
},
},
{
name: "revert with assert(panic)",
method: "alwaysRevertsAssert",
output: map[string]string{
seth.GETH: "execution reverted: assert(false)",
seth.ANVIL: "execution reverted: panic: assertion failed (0x01)",
},
},
{
name: "revert with a custom err",
method: "alwaysRevertsCustomError",
output: map[string]string{
seth.GETH: "error type: CustomErr, error values: [12 21]",
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.name == "revert with a custom err" && (c.Cfg.Network.Name == "Mumbai" || c.Cfg.Network.Name == "Fuji") {
t.Skip("typed errors are not supported\nnodes payload of rpc.DataError is empty and tx fails on send, not on execution")
}
_, err := c.Decode(TestEnv.DebugContractRaw.Transact(c.NewTXOpts(), tc.method))
require.Error(t, err)
var expectedOutput = tc.output[seth.GETH]
if c.Cfg.Network.Name != seth.GETH {
if eo, ok := tc.output[c.Cfg.Network.Name]; ok {
expectedOutput = eo
}
}
require.Equal(t, expectedOutput, err.Error())
})
}
}
func TestSmokeDebugData(t *testing.T) {
c := newClient(t)
c.Cfg.TracingLevel = seth.TracingLevel_All
type test struct {
name string
method string
params []interface{}
output seth.DecodedTransaction
write bool
}
tests := []test{
{
name: "test named inputs/outputs",
method: "emitNamedInputsOutputs",
params: []interface{}{big.NewInt(1337), "test"},
write: true,
output: seth.DecodedTransaction{
CommonData: seth.CommonData{
Input: map[string]interface{}{
"inputVal1": big.NewInt(1337),
"inputVal2": "test",
},
},
},
},
// TODO: https://docs.soliditylang.org/en/v0.8.19/control-structures.html read and figure out if
// decoding anynymous + named is heavily used and needed, usually people name params and omit output names
{
name: "test anonymous inputs/outputs",
method: "emitInputsOutputs",
params: []interface{}{big.NewInt(1337), "test"},
write: true,
output: seth.DecodedTransaction{
CommonData: seth.CommonData{
Input: map[string]interface{}{
"inputVal1": big.NewInt(1337),
"inputVal2": "test",
},
},
},
},
{
name: "test one log no index",
method: "emitNoIndexEvent",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"sender": c.Addresses[0],
},
},
},
},
},
},
{
name: "test one log index",
method: "emitOneIndexEvent",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"a": big.NewInt(83),
},
},
},
},
},
},
{
name: "test two log index",
method: "emitTwoIndexEvent",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"roundId": big.NewInt(1),
"startedBy": c.Addresses[0],
},
},
},
},
},
},
{
name: "test three log index",
method: "emitThreeIndexEvent",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"roundId": big.NewInt(1),
"startedAt": big.NewInt(3),
"startedBy": c.Addresses[0],
},
},
},
},
},
},
{
name: "test log no index string",
method: "emitNoIndexEventString",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"str": "myString",
},
},
},
},
},
},
// emitNoIndexStructEvent
{
name: "test log struct",
method: "emitNoIndexStructEvent",
write: true,
output: seth.DecodedTransaction{
Events: []seth.DecodedTransactionLog{
{
DecodedCommonLog: seth.DecodedCommonLog{
EventData: map[string]interface{}{
"a": struct {
Name string `json:"name"`
Balance uint64 `json:"balance"`
DailyLimit *big.Int `json:"dailyLimit"`
}{
Name: "John",
Balance: 5,
DailyLimit: big.NewInt(10),
},
},
},
},
},
},
},
// TODO: another case - figure out if indexed strings are used by anyone in events
// https://ethereum.stackexchange.com/questions/6840/indexed-event-with-string-not-getting-logged
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.write {
dtx, err := c.Decode(
TestEnv.DebugContractRaw.Transact(c.NewTXOpts(), tc.method, tc.params...),
)
require.NoError(t, err)
require.Equal(t, dtx.Input, tc.output.Input)
require.Equal(t, dtx.Output, tc.output.Output)
for i, e := range tc.output.Events {
require.NotNil(t, dtx.Events[i])
require.Equal(t, dtx.Events[i].EventData, e.EventData)
}
}
})
}
}