-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenged_proposal_test.go
312 lines (268 loc) · 12.2 KB
/
challenged_proposal_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
package tests
import (
"fmt"
"testing"
)
var (
monitorSixteenFile = "challenged_proposal.gate"
)
func TestChallengedProposalChallengerAttacksRootClaim(t *testing.T) {
// We expect an alert to be fired when the challenger attacks the root claim
// set the params, which DO matter for these tests
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
// we only use move events for length, but we still need the shape of the data to be accurate
"moveEvents": [][]interface{}{
{2, "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", "0x00"},
},
"claimCount": 4,
"claimData": [][]interface{}{
// the root claim doesn't have a real parent index since it is the root, so the index is type(uint32).max
{4294967295, "0x0000000000000000000000000000000000000000", "0x49277EE36A024120Ee218127354c4a3591dc90A9", 1, "0x00", 1, 123456},
// root claim is being attacked by the honest challenger
{0, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 2, 123456},
{1, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 3, 123456},
{2, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 4, 1233456},
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}
func TestChallengedProposalChallengerDefendsRootClaim(t *testing.T) {
// We DO NOT expect an alert to be fired when the challenger defends the root claim
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
"moveEvents": [][]interface{}{
{2, "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", "0x00"},
},
"claimCount": 4,
"claimData": [][]interface{}{
{4294967295, "0x0000000000000000000000000000000000000000", "0x49277EE36A024120Ee218127354c4a3591dc90A9", 1, "0x00", 1, 123456},
{0, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 2, 123456},
// root claim is being defended by the honest challenger
{1, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 3, 123456},
{2, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 4, 1233456},
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}
func TestChallengedProposalChallengerNotKnown(t *testing.T) {
// We DO NOT expect an alert to be fired when the challenger is not the honest challenger, regardless of
// whether the root claim submitted by the honest proposer is challenged or not
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
"moveEvents": [][]interface{}{
{2, "0x09dE888033b1e815419a3fb865f0DA5689332FdB", "0x00"},
},
"claimCount": 4,
"claimData": [][]interface{}{
{4294967295, "0x0000000000000000000000000000000000000000", "0x49277EE36A024120Ee218127354c4a3591dc90A9", 1, "0x00", 1, 123456},
// root claim is challenged, but by a random address
{0, "0x0000000000000000000000000000000000000000", "0x09dE888033b1e815419a3fb865f0DA5689332FdB", 1, "0x00", 2, 123456},
{1, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 3, 123456},
{2, "0x0000000000000000000000000000000000000000", "0x09dE888033b1e815419a3fb865f0DA5689332FdB", 1, "0x00", 4, 1233456},
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}
func TestChallengedProposalProposerNotKnown(t *testing.T) {
// We DO NOT expect an alert to be fired when the proposer is not the honest proposer, regardless of
// whether the challenger attacks the root claim or not
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
"moveEvents": [][]interface{}{
{2, "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", "0x00"},
},
"claimCount": 4,
"claimData": [][]interface{}{
// root claim is NOT proposed by the honest proposer
{4294967295, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 1, 123456},
// root claim is challenged by the honest challenger
{0, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 2, 123456},
{1, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 3, 123456},
{2, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 4, 1233456},
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}
func TestChallengedProposalOnlyRootClaim(t *testing.T) {
// We DO NOT expect an alert to be fired when the only claim is the root claim
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
"moveEvents": [][]interface{}{
{0, "0x49277EE36A024120Ee218127354c4a3591dc90A9", "0x00"},
},
"claimCount": 4,
"claimData": [][]interface{}{
{4294967295, "0x0000000000000000000000000000000000000000", "0x49277EE36A024120Ee218127354c4a3591dc90A9", 1, "0x00", 1, 123456},
// root claim is unchallenged
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}
func TestChallengedProposalNoMoveEventInBlock(t *testing.T) {
// We DO NOT expect an alert to be fired when there is no move event in the block,
// regardless of whether the claimData indicates the root claim is being challenged or not
// set the params, which DO matter for these tests
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestProposer": "0x49277EE36A024120Ee218127354c4a3591dc90A9",
"honestChallenger": "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4",
}
// read in the gate file
data, err := ReadGateFile(monitorSixteenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorSixteenFile, err)
}
// set the mock data that we will pass along with the Gate file and params to the validate request endpoint
mocks := map[string]any{
// same setup as the first test, except no moveEvents have been emitted in the block
"claimCount": 4,
"claimData": [][]interface{}{
// the root claim doesn't have a real parent index since it is the root, so the index is type(uint32).max
{4294967295, "0x0000000000000000000000000000000000000000", "0x49277EE36A024120Ee218127354c4a3591dc90A9", 1, "0x00", 1, 123456},
// root claim is being attacked by the honest challenger
{0, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 2, 123456},
{1, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", 1, "0x00", 3, 123456},
{2, "0x0000000000000000000000000000000000000000", "0xc96775081bcA132B0E7cbECDd0B58d9Ec07Fdaa4", 1, "0x00", 4, 1233456},
},
}
// call the validate request endpoint and parse the results
failed, exceptions, trace, err := HandleValidateRequest(data, params, mocks)
if err != nil {
t.Errorf("Error handling validate request for %s: %v", monitorSixteenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorSixteenFile, 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", monitorSixteenFile)
}
}