-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth_deficit_test.go
178 lines (148 loc) · 5.28 KB
/
eth_deficit_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
package tests
import (
"fmt"
"testing"
)
var (
monitorElevenFile = "eth_deficit.gate"
)
func TestETHDeficitTotalCreditDeficit(t *testing.T) {
// We expect an alert to be fired when totalCredit is less than claimCredit
// set the params, which don't really matter for these tests
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestChallenger": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorElevenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorElevenFile, err)
}
// set the mock data
mocks := map[string]any{
"delayedWETH": "0x0000000000000000000000000000000000000000",
"claimCredit": 100,
"totalCredit": []interface{}{50, 123456},
"ethBalanceDisputeGame": 500,
}
// 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", monitorElevenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorElevenFile, 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", monitorElevenFile)
}
}
func TestETHDeficitTotalETHBalanceDeficit(t *testing.T) {
// We expect an alert to be fired when ethBalanceDisputeGame is less than totalCredit
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestChallenger": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorElevenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorElevenFile, err)
}
// set the mock data
mocks := map[string]any{
"delayedWETH": "0x0000000000000000000000000000000000000000",
"claimCredit": 50,
"totalCredit": []interface{}{150, 123456},
"ethBalanceDisputeGame": 100,
}
// 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", monitorElevenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorElevenFile, 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", monitorElevenFile)
}
}
func TestETHDeficitCurrCreditZeroTotalCreditNonZero(t *testing.T) {
// We expect an alert to be fired when claimCredit is zero and totalCredit is non-zero
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestChallenger": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorElevenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorElevenFile, err)
}
// set the mock data
mocks := map[string]any{
"delayedWETH": "0x0000000000000000000000000000000000000000",
"claimCredit": 0,
"totalCredit": []interface{}{150, 123456},
"ethBalanceDisputeGame": 1500,
}
// 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", monitorElevenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorElevenFile, 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", monitorElevenFile)
}
}
func TestETHDeficitNoDeficit(t *testing.T) {
// We DO NOT expect an alert to be fired if there is no deficit
// set the params
params := map[string]any{
"disputeGame": "0x0000000000000000000000000000000000000000",
"honestChallenger": "0x0000000000000000000000000000000000000000",
}
// read in the gate file
data, err := ReadGateFile(monitorElevenFile)
if err != nil {
t.Errorf("Error reading file %s: %v", monitorElevenFile, err)
}
// set the mock data
mocks := map[string]any{
"delayedWETH": "0x0000000000000000000000000000000000000000",
"claimCredit": 100,
"totalCredit": []interface{}{200, 123456},
"ethBalanceDisputeGame": 300,
}
// 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", monitorElevenFile, err)
}
// check if the validate request threw any exceptions
if len(exceptions) > 0 {
fmt.Println(trace)
t.Errorf("Exceptions for %s: %v", monitorElevenFile, 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", monitorElevenFile)
}
}