-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicate_dispute_game_test.go
357 lines (303 loc) · 13.3 KB
/
duplicate_dispute_game_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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package tests
import (
"fmt"
"testing"
)
var (
monitorFiveFile = "duplicate_dispute_game.gate"
)
func TestDuplicateDisputeGameCreated(t *testing.T) {
// We expect an alert to be fired when a dispute game is created in the current block that
// has the same UUID as a previous dispute game
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim := "0x17bdb49e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c2143d99bf"
extraData := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid := "0x4f73e8da3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128e32ece"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{
{0, rootClaim, extraData},
},
"createdDisputeGames": [][]interface{}{
{99, []interface{}{"0x0000000000000000000000000000000000000000", 0, rootClaim}},
},
"createdDisputeGamesExtraData": []string{extraData},
// technically it's the UUIDs that will trigger the alert, but we still want to mock the other data
// as close as possible to the actual data
"newDisputeGameUUIDs": []string{uuid},
"previousDisputeGameUUIDs": []string{uuid},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// check if the validate request failed
// in an inverse way, this indicates that the monitor successfully fired an alert as the invariant was breached
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorFiveFile)
}
}
func TestMultipleDuplicateDisputeGamesCreated(t *testing.T) {
// We expect an alert to be fired when multiple dispute games are created in the current block
// that have the same UUID as previous dispute game(s)
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim1 := "0xbbbbbb9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214bbbbbb"
extraData1 := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid1 := "0xbbbbbbda3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128bbbbbb"
rootClaim2 := "0xaaaaaa9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214aaaaaa"
extraData2 := "0x0000000000000000000000000000000000000000000000000000000000aaaaaa"
uuid2 := "0xaaaaaada3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128aaaaaa"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{
{0, rootClaim1, extraData1},
{0, rootClaim2, extraData2},
},
"createdDisputeGames": [][]interface{}{
{98, []interface{}{"0x0000000000000000000000000000000000000000", 0, rootClaim1}},
{99, []interface{}{"0x0000000000000000000000000000000000000000", 0, rootClaim2}},
},
"createdDisputeGamesExtraData": []string{extraData1, extraData2},
"newDisputeGameUUIDs": []string{uuid1, uuid2},
"previousDisputeGameUUIDs": []string{uuid1, uuid2},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// check if the validate request failed
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorFiveFile)
}
// check to make sure two duplicate dispute game instances were identified
duplicateGames := trace.(map[string]interface{})["foundDuplicateGameInfo"]
if len(duplicateGames.([]interface{})) != 2 || duplicateGames.([]interface{})[0].(bool) != true || duplicateGames.([]interface{})[1].(bool) != true {
fmt.Println(trace)
t.Errorf("Monitor did not identify the correct number of duplicate dispute games")
}
}
func TestDuplicateDisputeGameCreatedInSameBlock(t *testing.T) {
// We expect an alert to be fired if more than one dispute game is created in the current block
// and more than one of the newly-created dispute games have the same UUID
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim1 := "0xbbbbbb9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214bbbbbb"
extraData1 := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid1 := "0xbbbbbbda3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128bbbbbb"
rootClaim2 := "0xaaaaaa9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214aaaaaa"
extraData2 := "0x0000000000000000000000000000000000000000000000000000000000aaaaaa"
uuid2 := "0xaaaaaada3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128aaaaaa"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{
{0, rootClaim1, extraData1},
{0, rootClaim1, extraData1},
},
"createdDisputeGames": [][]interface{}{
{98, []interface{}{"0x0000000000000000000000000000000000000000", 0, rootClaim2}},
},
"createdDisputeGamesExtraData": []string{extraData2},
"newDisputeGameUUIDs": []string{uuid1, uuid1},
"previousDisputeGameUUIDs": []string{uuid2},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// check if the validate request failed
if len(failed) == 0 {
fmt.Println(trace)
t.Errorf("Monitor did not fire an alert for %s when it was supposed to", monitorFiveFile)
}
}
func TestDuplicateDisputeGameCreatedDifferentGameTypes(t *testing.T) {
// We DO NOT expect an alert to be fired if a dispute game is created in the current block
// that has the same UUID but a different game type as a previous dispute game
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim1 := "0xbbbbbb9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214bbbbbb"
extraData1 := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid1 := "0xbbbbbbda3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128bbbbbb"
rootClaim2 := "0xaaaaaa9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214aaaaaa"
extraData2 := "0x0000000000000000000000000000000000000000000000000000000000aaaaaa"
uuid2 := "0xaaaaaada3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128aaaaaa"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{
{0, rootClaim1, extraData1},
{0, rootClaim2, extraData2},
},
"createdDisputeGames": [][]interface{}{
{98, []interface{}{"0x0000000000000000000000000000000000000000", 2, rootClaim1}},
{99, []interface{}{"0x0000000000000000000000000000000000000000", 2, rootClaim2}},
},
"createdDisputeGamesExtraData": []string{extraData1, extraData2},
"newDisputeGameUUIDs": []string{uuid1, uuid2},
"previousDisputeGameUUIDs": []string{},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// in this case we DO NOT expect the monitor to fire an alert
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorFiveFile)
}
}
func TestNoDuplicateDisputeGameCreatedNoHistory(t *testing.T) {
// We DO NOT expect an alert to be fired if a dispute game is created in the current block
// and there is no history of a dispute game being created with the same UUID
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim1 := "0xbbbbbb9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214bbbbbb"
extraData1 := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid1 := "0xbbbbbbda3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128bbbbbb"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{
{0, rootClaim1, extraData1},
},
"createdDisputeGames": [][]interface{}{},
"createdDisputeGamesExtraData": []string{},
"newDisputeGameUUIDs": []string{uuid1},
"previousDisputeGameUUIDs": []string{},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// in this case we DO NOT expect the monitor to fire an alert
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorFiveFile)
}
}
func TestNoDuplicateDisputeGameCreatedNoGameCreatedInCurrBlock(t *testing.T) {
// We DO NOT expect an alert to be fired if no dispute games are created in the current block
// regardless of whether there are historical instances of duplciate dispute games being created
// setup the param value - this doesn't matter as much as we'll be mocking source data
params := map[string]any{
"optimismPortalProxy": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorFiveFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorFiveFile, err)
}
// setup the mock data
rootClaim1 := "0xbbbbbb9e89561f18e1dc284c1955238d2b942e0fa3b755279fce78c214bbbbbb"
extraData1 := "0x0000000000000000000000000000000000000000000000000000000000bbbbbb"
uuid1 := "0xbbbbbbda3b9d2fa9933b09187ee8b678b03fc2255e67975017d3462128bbbbbb"
mocks := map[string]any{
"disputeGameFactory": "0x0000000000000000000000000000000000000000",
"respectedGameType": 0,
"currBlock": 100,
"newDisputeGames": [][]interface{}{},
"createdDisputeGames": [][]interface{}{
{98, []interface{}{"0x0000000000000000000000000000000000000000", 0, rootClaim1}},
},
"createdDisputeGamesExtraData": []string{extraData1},
"newDisputeGameUUIDs": []string{},
"previousDisputeGameUUIDs": []string{uuid1},
}
// 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", monitorFiveFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorFiveFile, exceptions)
}
// in this case we DO NOT expect the monitor to fire an alert
if len(failed) > 0 {
fmt.Println(trace)
t.Errorf("Monitor fired an alert for %s when it was not supposed to", monitorFiveFile)
}
}