-
Notifications
You must be signed in to change notification settings - Fork 0
/
unresolvable_dispute_game_test.go
137 lines (114 loc) · 4.21 KB
/
unresolvable_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
package tests
import (
"fmt"
"testing"
)
var (
monitorTwentyFile = "unresolvable_dispute_game.gate"
)
func TestUnresolvableDisputeGame(t *testing.T) {
// We expect an alert to be fired when a dispute game has not resolved within the time limit
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"extraTimeInSeconds": 172800,
}
// read in the gate file
data, err := ReadGateFile(monitorTwentyFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorTwentyFile, 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{
"creationTimestamp": 555555,
"gameDuration": 100,
"resolvedAt": 0, // game hasn't resolved yet
"currentTimestamp": 728556, // creationTimestamp + (2 * gameDuration) + extraTime + 1
}
// 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", monitorTwentyFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorTwentyFile, 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", monitorTwentyFile)
}
}
func TestUnresolvableDisputeGameNoAlertGameUnderTimeLimit(t *testing.T) {
// We DO NOT expect an alert to be fired when a dispute game has not resolved but
// the time limit has not been reached
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"extraTimeInSeconds": 172800,
}
// read in the gate file
data, err := ReadGateFile(monitorTwentyFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorTwentyFile, 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{
"creationTimestamp": 555555,
"gameDuration": 100,
"resolvedAt": 0, // game hasn't resolved yet
"currentTimestamp": 728554, // creationTimestamp + (2 * gameDuration) + extraTime - 1
}
// 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", monitorTwentyFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorTwentyFile, 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", monitorTwentyFile)
}
}
func TestUnresolvableDisputeGameNoAlertGameResolved(t *testing.T) {
// We DO NOT expect an alert to be fired when a dispute game has resolved
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"extraTimeInSeconds": 172800,
}
// read in the gate file
data, err := ReadGateFile(monitorTwentyFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorTwentyFile, 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{
"creationTimestamp": 555555,
"gameDuration": 100,
"resolvedAt": 555655, // game has resolved already
"currentTimestamp": 728554, // doesn't matter
}
// 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", monitorTwentyFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorTwentyFile, 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", monitorTwentyFile)
}
}