-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincorrect_bond_balance_test.go
334 lines (287 loc) · 12.5 KB
/
incorrect_bond_balance_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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package tests
import (
"fmt"
"testing"
)
var (
monitorEighteenFile = "incorrect_bond_balance.gate"
)
func TestIncorrectBondBalanceIncorrectFutureETHUnlocked(t *testing.T) {
// We expect an alert to be fired when the FutureETHUnlocked is not the expected value
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"addressesInTrace": []any{"0x00000000000000000000000000000000000000AA"},
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"resolveClaimCalls": [][]interface{}{
{3, 512},
{2, 512},
// claim indices 1 and 0 have not been resolved yet
},
"unlocksWithSender": [][]interface{}{
// two unlocks for two resolveClaim calls
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000001", 400}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000002", 300}},
},
"ethBondsPerClaimIndex": []int{200, 100}, // the eth bonds for the remaining claim indices are 200 and 100
"ethBondAtMinClaim": 0, // the min claim index, which is 2, is fully resolved
"currDisputeEthBalance": 800, // too much eth is remains to be unlocked, which will cause the alert to fire
"pastWithdrawals": [][]interface{}{}, // no past withdrawals have occurred
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we expect to see the alert fired
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorEighteenFile)
}
}
func TestIncorrectBondBalancePartiallyResolvedMinClaim(t *testing.T) {
// We expect an alert to be fired when the FutureETHUnlocked is not the expected value due to a partially resolved min claim
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"addressesInTrace": []any{"0x00000000000000000000000000000000000000AA"},
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"resolveClaimCalls": [][]interface{}{
{3, 512},
{2, 1}, // claim 2 is only partially resolved, which means its bond has not been unlocked yet
// claim indices 1 and 0 have not been resolved yet
},
"unlocksWithSender": [][]interface{}{
// one unlock for one finished resolveClaim call
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000001", 400}},
},
"ethBondsPerClaimIndex": []int{200, 100}, // the eth bonds for the remaining claim indices are 200 and 100
"ethBondAtMinClaim": 300, // the min claim index, which is 2, has not been fully resolved yet
"currDisputeEthBalance": 800, // too much eth is remains to be unlocked, which will cause the alert to fire
"pastWithdrawals": [][]interface{}{}, // no past withdrawals have occurred
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we expect to see the alert fired
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorEighteenFile)
}
}
func TestIncorrectBondBalanceIncorrectCurrETHUnlocked(t *testing.T) {
// We expect an alert to be fired when the CurrentETHUnlocked is not the expected value
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"addressesInTrace": []any{"0x00000000000000000000000000000000000000AA"},
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"resolveClaimCalls": [][]interface{}{
// all claims have been resolved
{3, 512},
{2, 512},
{1, 512},
{0, 512},
},
"unlocksWithSender": [][]interface{}{
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000001", 400}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000002", 300}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000003", 200}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000004", 100}},
},
"ethBondsPerClaimIndex": []int{},
"ethBondAtMinClaim": 0, // all claims are fully resolved
"currDisputeEthBalance": 800, // too much eth has been unlocked, which will cause the alert to fire
"pastWithdrawals": [][]interface{}{}, // no past withdrawals have occurred
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we expect to see the alert fired
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorEighteenFile)
}
}
func TestIncorrectBondBalanceCorrectETHValues(t *testing.T) {
// We DO NOT expect an alert to be fired when the FutureETHUnlocked and CurrentETHUnlocked are the expected values
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"addressesInTrace": []any{"0x00000000000000000000000000000000000000AA"},
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"resolveClaimCalls": [][]interface{}{
{3, 512},
{2, 512},
// claim indices 1 and 0 have not been resolved yet
},
"unlocksWithSender": [][]interface{}{
// two unlocks for two resolveClaim calls
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000001", 400}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000002", 300}},
// this unlock is for a different dispute game so it should not be counted
{"0x00000000000000000000000000000000000000BB", []interface{}{"0x0000000000000000000000000000000000000002", 300}},
},
"ethBondAtMinClaim": 0, // the min claim index, which is 2, is fully resolved
"ethBondsPerClaimIndex": []int{200, 100}, // the eth bonds for the remaining claim indices are 200 and 100, respectively
"currDisputeEthBalance": 800,
"pastWithdrawalEvents": [][]interface{}{
// two withdrawal events have already happened, which when added to the current dispute
// eth balance gives the correct amount
{100},
{100},
},
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we DO NOT expect to see the alert fired
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorEighteenFile)
}
}
func TestIncorrectBondBalanceNoClaimsResolvedYet(t *testing.T) {
// We DO NOT expect an alert to be fired when no claims have been resolved yet
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"addressesInTrace": []any{"0x00000000000000000000000000000000000000AA"},
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"claimIndices": []int{}, // no claims have been resolved yet
"unlockAmounts": []int{},
// when NO claims have been resolved, it is difficult to determine the depth of the remainin claim indices,
// as the dispute game could still be going on - so instead when we haven't seen any claim yet, we just set
// the value of the future eth unlocked to the currDisputeEthBalance
"ethBondAtMinClaim": 0, // no claims have been resolved yet
"ethBondsPerClaimIndex": []int{}, // no indices are ready to be claimed yet
"currDisputeEthBalance": 800,
"pastWithdrawals": [][]interface{}{}, // no past withdrawals have occurred
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we DO NOT expect to see the alert fired
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorEighteenFile)
}
}
func TestIncorrectBondBalanceNoFilterAddress(t *testing.T) {
// We DO NOT expect an alert to be fired when the filter address is not in the trace
// set the params
params := map[string]any{
"disputeGame": "0x00000000000000000000000000000000000000AA",
}
// read in the gate file
data, err := ReadGateFile(monitorEighteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorEighteenFile, err)
}
// setup the mocks
mocks := map[string]any{
"delayedWETH": "0x00000000000000000000000000000000000000BB",
"resolveClaimCalls": [][]interface{}{
{3, 512},
{2, 512},
// claim indices 1 and 0 have not been resolved yet
},
"unlocksWithSender": [][]interface{}{
// two unlocks for two resolveClaim calls
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000001", 400}},
{"0x00000000000000000000000000000000000000AA", []interface{}{"0x0000000000000000000000000000000000000002", 300}},
},
"ethBondsPerClaimIndex": []int{200, 100}, // the eth bonds for the remaining claim indices are 200 and 100
"ethBondAtMinClaim": 0, // the min claim index, which is 2, is fully resolved
"currDisputeEthBalance": 800, // too much eth is remains to be unlocked, which will cause the alert to fire
"pastWithdrawals": [][]interface{}{}, // no past withdrawals have occurred
}
// call out to hexagate API to run the gate file with params and mocks
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorEighteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorEighteenFile, exceptions)
}
// we DO NOT expect to see the alert fired
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorEighteenFile)
}
}