Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
1316762f
Unverified
Commit
1316762f
authored
Feb 15, 2024
by
refcell
Committed by
GitHub
Feb 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(op-dispute-mon): Move types into their own package (#9542)
parent
aa3b147c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
71 deletions
+138
-71
detector.go
op-dispute-mon/mon/detector.go
+13
-12
detector_test.go
op-dispute-mon/mon/detector_test.go
+19
-18
forecast.go
op-dispute-mon/mon/forecast.go
+4
-3
types.go
op-dispute-mon/mon/types/types.go
+64
-0
types_test.go
op-dispute-mon/mon/types/types_test.go
+38
-38
No files found.
op-dispute-mon/mon/detector.go
View file @
1316762f
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"fmt"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -40,8 +41,8 @@ func newDetector(logger log.Logger, metrics DetectorMetrics, creator GameCallerC
...
@@ -40,8 +41,8 @@ func newDetector(logger log.Logger, metrics DetectorMetrics, creator GameCallerC
}
}
func
(
d
*
detector
)
Detect
(
ctx
context
.
Context
,
games
[]
types
.
GameMetadata
)
{
func
(
d
*
detector
)
Detect
(
ctx
context
.
Context
,
games
[]
types
.
GameMetadata
)
{
statBatch
:=
s
tatusBatch
{}
statBatch
:=
monTypes
.
S
tatusBatch
{}
detectBatch
:=
d
etectionBatch
{}
detectBatch
:=
monTypes
.
D
etectionBatch
{}
for
_
,
game
:=
range
games
{
for
_
,
game
:=
range
games
{
// Fetch the game metadata to ensure the game status is recorded
// Fetch the game metadata to ensure the game status is recorded
// regardless of whether the game agreement is checked.
// regardless of whether the game agreement is checked.
...
@@ -58,17 +59,17 @@ func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) {
...
@@ -58,17 +59,17 @@ func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) {
}
}
detectBatch
.
Merge
(
processed
)
detectBatch
.
Merge
(
processed
)
}
}
d
.
metrics
.
RecordGamesStatus
(
statBatch
.
inProgress
,
statBatch
.
defenderWon
,
statBatch
.
c
hallengerWon
)
d
.
metrics
.
RecordGamesStatus
(
statBatch
.
InProgress
,
statBatch
.
DefenderWon
,
statBatch
.
C
hallengerWon
)
d
.
recordBatch
(
detectBatch
)
d
.
recordBatch
(
detectBatch
)
d
.
logger
.
Info
(
"Completed updating games"
,
"count"
,
len
(
games
))
d
.
logger
.
Info
(
"Completed updating games"
,
"count"
,
len
(
games
))
}
}
func
(
d
*
detector
)
recordBatch
(
batch
d
etectionBatch
)
{
func
(
d
*
detector
)
recordBatch
(
batch
monTypes
.
D
etectionBatch
)
{
d
.
metrics
.
RecordGameAgreement
(
"in_progress"
,
batch
.
i
nProgress
)
d
.
metrics
.
RecordGameAgreement
(
"in_progress"
,
batch
.
I
nProgress
)
d
.
metrics
.
RecordGameAgreement
(
"agree_defender_wins"
,
batch
.
a
greeDefenderWins
)
d
.
metrics
.
RecordGameAgreement
(
"agree_defender_wins"
,
batch
.
A
greeDefenderWins
)
d
.
metrics
.
RecordGameAgreement
(
"disagree_defender_wins"
,
batch
.
d
isagreeDefenderWins
)
d
.
metrics
.
RecordGameAgreement
(
"disagree_defender_wins"
,
batch
.
D
isagreeDefenderWins
)
d
.
metrics
.
RecordGameAgreement
(
"agree_challenger_wins"
,
batch
.
a
greeChallengerWins
)
d
.
metrics
.
RecordGameAgreement
(
"agree_challenger_wins"
,
batch
.
A
greeChallengerWins
)
d
.
metrics
.
RecordGameAgreement
(
"disagree_challenger_wins"
,
batch
.
d
isagreeChallengerWins
)
d
.
metrics
.
RecordGameAgreement
(
"disagree_challenger_wins"
,
batch
.
D
isagreeChallengerWins
)
}
}
func
(
d
*
detector
)
fetchGameMetadata
(
ctx
context
.
Context
,
game
types
.
GameMetadata
)
(
uint64
,
common
.
Hash
,
types
.
GameStatus
,
error
)
{
func
(
d
*
detector
)
fetchGameMetadata
(
ctx
context
.
Context
,
game
types
.
GameMetadata
)
(
uint64
,
common
.
Hash
,
types
.
GameStatus
,
error
)
{
...
@@ -83,12 +84,12 @@ func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadat
...
@@ -83,12 +84,12 @@ func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadat
return
blockNum
,
rootClaim
,
status
,
nil
return
blockNum
,
rootClaim
,
status
,
nil
}
}
func
(
d
*
detector
)
checkAgreement
(
ctx
context
.
Context
,
addr
common
.
Address
,
blockNum
uint64
,
rootClaim
common
.
Hash
,
status
types
.
GameStatus
)
(
d
etectionBatch
,
error
)
{
func
(
d
*
detector
)
checkAgreement
(
ctx
context
.
Context
,
addr
common
.
Address
,
blockNum
uint64
,
rootClaim
common
.
Hash
,
status
types
.
GameStatus
)
(
monTypes
.
D
etectionBatch
,
error
)
{
agree
,
expectedClaim
,
err
:=
d
.
validator
.
CheckRootAgreement
(
ctx
,
blockNum
,
rootClaim
)
agree
,
expectedClaim
,
err
:=
d
.
validator
.
CheckRootAgreement
(
ctx
,
blockNum
,
rootClaim
)
if
err
!=
nil
{
if
err
!=
nil
{
return
d
etectionBatch
{},
err
return
monTypes
.
D
etectionBatch
{},
err
}
}
batch
:=
d
etectionBatch
{}
batch
:=
monTypes
.
D
etectionBatch
{}
batch
.
Update
(
status
,
agree
)
batch
.
Update
(
status
,
agree
)
if
status
!=
types
.
GameStatusInProgress
{
if
status
!=
types
.
GameStatusInProgress
{
expectedResult
:=
types
.
GameStatusDefenderWon
expectedResult
:=
types
.
GameStatusDefenderWon
...
...
op-dispute-mon/mon/detector_test.go
View file @
1316762f
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
faultTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
faultTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
...
@@ -67,45 +68,45 @@ func TestDetector_Detect(t *testing.T) {
...
@@ -67,45 +68,45 @@ func TestDetector_Detect(t *testing.T) {
func
TestDetector_RecordBatch
(
t
*
testing
.
T
)
{
func
TestDetector_RecordBatch
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
batch
d
etectionBatch
batch
monTypes
.
D
etectionBatch
expect
func
(
*
testing
.
T
,
*
mockDetectorMetricer
)
expect
func
(
*
testing
.
T
,
*
mockDetectorMetricer
)
}{
}{
{
{
name
:
"no games"
,
name
:
"no games"
,
batch
:
d
etectionBatch
{},
batch
:
monTypes
.
D
etectionBatch
{},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{},
},
},
{
{
name
:
"in_progress"
,
name
:
"in_progress"
,
batch
:
detectionBatch
{
i
nProgress
:
1
},
batch
:
monTypes
.
DetectionBatch
{
I
nProgress
:
1
},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"in_progress"
])
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"in_progress"
])
},
},
},
},
{
{
name
:
"agree_defender_wins"
,
name
:
"agree_defender_wins"
,
batch
:
detectionBatch
{
a
greeDefenderWins
:
1
},
batch
:
monTypes
.
DetectionBatch
{
A
greeDefenderWins
:
1
},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"agree_defender_wins"
])
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"agree_defender_wins"
])
},
},
},
},
{
{
name
:
"disagree_defender_wins"
,
name
:
"disagree_defender_wins"
,
batch
:
detectionBatch
{
d
isagreeDefenderWins
:
1
},
batch
:
monTypes
.
DetectionBatch
{
D
isagreeDefenderWins
:
1
},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"disagree_defender_wins"
])
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"disagree_defender_wins"
])
},
},
},
},
{
{
name
:
"agree_challenger_wins"
,
name
:
"agree_challenger_wins"
,
batch
:
detectionBatch
{
a
greeChallengerWins
:
1
},
batch
:
monTypes
.
DetectionBatch
{
A
greeChallengerWins
:
1
},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"agree_challenger_wins"
])
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"agree_challenger_wins"
])
},
},
},
},
{
{
name
:
"disagree_challenger_wins"
,
name
:
"disagree_challenger_wins"
,
batch
:
detectionBatch
{
d
isagreeChallengerWins
:
1
},
batch
:
monTypes
.
DetectionBatch
{
D
isagreeChallengerWins
:
1
},
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
expect
:
func
(
t
*
testing
.
T
,
metrics
*
mockDetectorMetricer
)
{
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"disagree_challenger_wins"
])
require
.
Equal
(
t
,
1
,
metrics
.
gameAgreement
[
"disagree_challenger_wins"
])
},
},
...
@@ -163,15 +164,15 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
...
@@ -163,15 +164,15 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
name
string
name
string
rootClaim
common
.
Hash
rootClaim
common
.
Hash
status
types
.
GameStatus
status
types
.
GameStatus
expectBatch
func
(
*
d
etectionBatch
)
expectBatch
func
(
*
monTypes
.
D
etectionBatch
)
expectErrorLog
bool
expectErrorLog
bool
expectStatus
types
.
GameStatus
expectStatus
types
.
GameStatus
err
error
err
error
}{
}{
{
{
name
:
"in_progress"
,
name
:
"in_progress"
,
expectBatch
:
func
(
batch
*
d
etectionBatch
)
{
expectBatch
:
func
(
batch
*
monTypes
.
D
etectionBatch
)
{
require
.
Equal
(
t
,
1
,
batch
.
i
nProgress
)
require
.
Equal
(
t
,
1
,
batch
.
I
nProgress
)
},
},
},
},
{
{
...
@@ -179,16 +180,16 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
...
@@ -179,16 +180,16 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
rootClaim
:
mockRootClaim
,
rootClaim
:
mockRootClaim
,
status
:
types
.
GameStatusDefenderWon
,
status
:
types
.
GameStatusDefenderWon
,
expectStatus
:
types
.
GameStatusDefenderWon
,
expectStatus
:
types
.
GameStatusDefenderWon
,
expectBatch
:
func
(
batch
*
d
etectionBatch
)
{
expectBatch
:
func
(
batch
*
monTypes
.
D
etectionBatch
)
{
require
.
Equal
(
t
,
1
,
batch
.
a
greeDefenderWins
)
require
.
Equal
(
t
,
1
,
batch
.
A
greeDefenderWins
)
},
},
},
},
{
{
name
:
"disagree_defender_wins"
,
name
:
"disagree_defender_wins"
,
status
:
types
.
GameStatusDefenderWon
,
status
:
types
.
GameStatusDefenderWon
,
expectStatus
:
types
.
GameStatusChallengerWon
,
expectStatus
:
types
.
GameStatusChallengerWon
,
expectBatch
:
func
(
batch
*
d
etectionBatch
)
{
expectBatch
:
func
(
batch
*
monTypes
.
D
etectionBatch
)
{
require
.
Equal
(
t
,
1
,
batch
.
d
isagreeDefenderWins
)
require
.
Equal
(
t
,
1
,
batch
.
D
isagreeDefenderWins
)
},
},
expectErrorLog
:
true
,
expectErrorLog
:
true
,
},
},
...
@@ -197,8 +198,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
...
@@ -197,8 +198,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
rootClaim
:
mockRootClaim
,
rootClaim
:
mockRootClaim
,
status
:
types
.
GameStatusChallengerWon
,
status
:
types
.
GameStatusChallengerWon
,
expectStatus
:
types
.
GameStatusDefenderWon
,
expectStatus
:
types
.
GameStatusDefenderWon
,
expectBatch
:
func
(
batch
*
d
etectionBatch
)
{
expectBatch
:
func
(
batch
*
monTypes
.
D
etectionBatch
)
{
require
.
Equal
(
t
,
1
,
batch
.
a
greeChallengerWins
)
require
.
Equal
(
t
,
1
,
batch
.
A
greeChallengerWins
)
},
},
expectErrorLog
:
true
,
expectErrorLog
:
true
,
},
},
...
@@ -206,8 +207,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
...
@@ -206,8 +207,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
name
:
"disagree_challenger_wins"
,
name
:
"disagree_challenger_wins"
,
status
:
types
.
GameStatusChallengerWon
,
status
:
types
.
GameStatusChallengerWon
,
expectStatus
:
types
.
GameStatusChallengerWon
,
expectStatus
:
types
.
GameStatusChallengerWon
,
expectBatch
:
func
(
batch
*
d
etectionBatch
)
{
expectBatch
:
func
(
batch
*
monTypes
.
D
etectionBatch
)
{
require
.
Equal
(
t
,
1
,
batch
.
d
isagreeChallengerWins
)
require
.
Equal
(
t
,
1
,
batch
.
D
isagreeChallengerWins
)
},
},
},
},
}
}
...
...
op-dispute-mon/mon/forecast.go
View file @
1316762f
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"fmt"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
...
@@ -39,7 +40,7 @@ func newForecast(logger log.Logger, metrics ForecastMetrics, creator GameCallerC
...
@@ -39,7 +40,7 @@ func newForecast(logger log.Logger, metrics ForecastMetrics, creator GameCallerC
}
}
func
(
f
*
forecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
types
.
GameMetadata
)
{
func
(
f
*
forecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
types
.
GameMetadata
)
{
batch
:=
f
orecastBatch
{}
batch
:=
monTypes
.
F
orecastBatch
{}
for
_
,
game
:=
range
games
{
for
_
,
game
:=
range
games
{
if
err
:=
f
.
forecastGame
(
ctx
,
game
,
&
batch
);
err
!=
nil
{
if
err
:=
f
.
forecastGame
(
ctx
,
game
,
&
batch
);
err
!=
nil
{
f
.
logger
.
Error
(
"Failed to forecast game"
,
"err"
,
err
)
f
.
logger
.
Error
(
"Failed to forecast game"
,
"err"
,
err
)
...
@@ -48,14 +49,14 @@ func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) {
...
@@ -48,14 +49,14 @@ func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) {
f
.
recordBatch
(
batch
)
f
.
recordBatch
(
batch
)
}
}
func
(
f
*
forecast
)
recordBatch
(
batch
f
orecastBatch
)
{
func
(
f
*
forecast
)
recordBatch
(
batch
monTypes
.
F
orecastBatch
)
{
f
.
metrics
.
RecordGameAgreement
(
"agree_challenger_ahead"
,
batch
.
AgreeChallengerAhead
)
f
.
metrics
.
RecordGameAgreement
(
"agree_challenger_ahead"
,
batch
.
AgreeChallengerAhead
)
f
.
metrics
.
RecordGameAgreement
(
"disagree_challenger_ahead"
,
batch
.
DisagreeChallengerAhead
)
f
.
metrics
.
RecordGameAgreement
(
"disagree_challenger_ahead"
,
batch
.
DisagreeChallengerAhead
)
f
.
metrics
.
RecordGameAgreement
(
"agree_defender_ahead"
,
batch
.
AgreeDefenderAhead
)
f
.
metrics
.
RecordGameAgreement
(
"agree_defender_ahead"
,
batch
.
AgreeDefenderAhead
)
f
.
metrics
.
RecordGameAgreement
(
"disagree_defender_ahead"
,
batch
.
DisagreeDefenderAhead
)
f
.
metrics
.
RecordGameAgreement
(
"disagree_defender_ahead"
,
batch
.
DisagreeDefenderAhead
)
}
}
func
(
f
*
forecast
)
forecastGame
(
ctx
context
.
Context
,
game
types
.
GameMetadata
,
metrics
*
f
orecastBatch
)
error
{
func
(
f
*
forecast
)
forecastGame
(
ctx
context
.
Context
,
game
types
.
GameMetadata
,
metrics
*
monTypes
.
F
orecastBatch
)
error
{
loader
,
err
:=
f
.
creator
.
CreateContract
(
game
)
loader
,
err
:=
f
.
creator
.
CreateContract
(
game
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%w: %w"
,
ErrContractCreation
,
err
)
return
fmt
.
Errorf
(
"%w: %w"
,
ErrContractCreation
,
err
)
...
...
op-dispute-mon/mon/types.go
→
op-dispute-mon/mon/types
/types
.go
View file @
1316762f
package
mon
package
types
import
(
import
(
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
)
)
type
statusBatch
struct
{
type
StatusBatch
struct
{
inProgress
,
defenderWon
,
challengerWon
int
InProgress
int
DefenderWon
int
ChallengerWon
int
}
}
func
(
s
*
s
tatusBatch
)
Add
(
status
types
.
GameStatus
)
{
func
(
s
*
S
tatusBatch
)
Add
(
status
types
.
GameStatus
)
{
switch
status
{
switch
status
{
case
types
.
GameStatusInProgress
:
case
types
.
GameStatusInProgress
:
s
.
i
nProgress
++
s
.
I
nProgress
++
case
types
.
GameStatusDefenderWon
:
case
types
.
GameStatusDefenderWon
:
s
.
d
efenderWon
++
s
.
D
efenderWon
++
case
types
.
GameStatusChallengerWon
:
case
types
.
GameStatusChallengerWon
:
s
.
c
hallengerWon
++
s
.
C
hallengerWon
++
}
}
}
}
type
f
orecastBatch
struct
{
type
F
orecastBatch
struct
{
AgreeDefenderAhead
int
AgreeDefenderAhead
int
DisagreeDefenderAhead
int
DisagreeDefenderAhead
int
AgreeChallengerAhead
int
AgreeChallengerAhead
int
DisagreeChallengerAhead
int
DisagreeChallengerAhead
int
}
}
type
d
etectionBatch
struct
{
type
D
etectionBatch
struct
{
i
nProgress
int
I
nProgress
int
a
greeDefenderWins
int
A
greeDefenderWins
int
d
isagreeDefenderWins
int
D
isagreeDefenderWins
int
a
greeChallengerWins
int
A
greeChallengerWins
int
d
isagreeChallengerWins
int
D
isagreeChallengerWins
int
}
}
func
(
d
*
d
etectionBatch
)
Update
(
status
types
.
GameStatus
,
agree
bool
)
{
func
(
d
*
D
etectionBatch
)
Update
(
status
types
.
GameStatus
,
agree
bool
)
{
switch
status
{
switch
status
{
case
types
.
GameStatusInProgress
:
case
types
.
GameStatusInProgress
:
d
.
i
nProgress
++
d
.
I
nProgress
++
case
types
.
GameStatusDefenderWon
:
case
types
.
GameStatusDefenderWon
:
if
agree
{
if
agree
{
d
.
a
greeDefenderWins
++
d
.
A
greeDefenderWins
++
}
else
{
}
else
{
d
.
d
isagreeDefenderWins
++
d
.
D
isagreeDefenderWins
++
}
}
case
types
.
GameStatusChallengerWon
:
case
types
.
GameStatusChallengerWon
:
if
agree
{
if
agree
{
d
.
a
greeChallengerWins
++
d
.
A
greeChallengerWins
++
}
else
{
}
else
{
d
.
d
isagreeChallengerWins
++
d
.
D
isagreeChallengerWins
++
}
}
}
}
}
}
func
(
d
*
detectionBatch
)
Merge
(
other
d
etectionBatch
)
{
func
(
d
*
DetectionBatch
)
Merge
(
other
D
etectionBatch
)
{
d
.
inProgress
+=
other
.
i
nProgress
d
.
InProgress
+=
other
.
I
nProgress
d
.
agreeDefenderWins
+=
other
.
a
greeDefenderWins
d
.
AgreeDefenderWins
+=
other
.
A
greeDefenderWins
d
.
disagreeDefenderWins
+=
other
.
d
isagreeDefenderWins
d
.
DisagreeDefenderWins
+=
other
.
D
isagreeDefenderWins
d
.
agreeChallengerWins
+=
other
.
a
greeChallengerWins
d
.
AgreeChallengerWins
+=
other
.
A
greeChallengerWins
d
.
disagreeChallengerWins
+=
other
.
d
isagreeChallengerWins
d
.
DisagreeChallengerWins
+=
other
.
D
isagreeChallengerWins
}
}
op-dispute-mon/mon/types_test.go
→
op-dispute-mon/mon/types
/types
_test.go
View file @
1316762f
package
mon
package
types
import
(
import
(
"fmt"
"fmt"
...
@@ -11,24 +11,24 @@ import (
...
@@ -11,24 +11,24 @@ import (
func
TestStatusBatch_Add
(
t
*
testing
.
T
)
{
func
TestStatusBatch_Add
(
t
*
testing
.
T
)
{
statusExpectations
:=
[]
struct
{
statusExpectations
:=
[]
struct
{
status
types
.
GameStatus
status
types
.
GameStatus
create
func
(
int
)
s
tatusBatch
create
func
(
int
)
S
tatusBatch
}{
}{
{
{
status
:
types
.
GameStatusInProgress
,
status
:
types
.
GameStatusInProgress
,
create
:
func
(
inProgress
int
)
s
tatusBatch
{
create
:
func
(
inProgress
int
)
S
tatusBatch
{
return
s
tatusBatch
{
inProgress
,
0
,
0
}
return
S
tatusBatch
{
inProgress
,
0
,
0
}
},
},
},
},
{
{
status
:
types
.
GameStatusDefenderWon
,
status
:
types
.
GameStatusDefenderWon
,
create
:
func
(
defenderWon
int
)
s
tatusBatch
{
create
:
func
(
defenderWon
int
)
S
tatusBatch
{
return
s
tatusBatch
{
0
,
defenderWon
,
0
}
return
S
tatusBatch
{
0
,
defenderWon
,
0
}
},
},
},
},
{
{
status
:
types
.
GameStatusChallengerWon
,
status
:
types
.
GameStatusChallengerWon
,
create
:
func
(
challengerWon
int
)
s
tatusBatch
{
create
:
func
(
challengerWon
int
)
S
tatusBatch
{
return
s
tatusBatch
{
0
,
0
,
challengerWon
}
return
S
tatusBatch
{
0
,
0
,
challengerWon
}
},
},
},
},
}
}
...
@@ -37,7 +37,7 @@ func TestStatusBatch_Add(t *testing.T) {
...
@@ -37,7 +37,7 @@ func TestStatusBatch_Add(t *testing.T) {
name
string
name
string
status
types
.
GameStatus
status
types
.
GameStatus
invocations
int
invocations
int
expected
s
tatusBatch
expected
S
tatusBatch
}
}
var
tests
[]
test
var
tests
[]
test
...
@@ -55,7 +55,7 @@ func TestStatusBatch_Add(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestStatusBatch_Add(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
test
:=
test
test
:=
test
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
s
:=
s
tatusBatch
{}
s
:=
S
tatusBatch
{}
for
i
:=
0
;
i
<
test
.
invocations
;
i
++
{
for
i
:=
0
;
i
<
test
.
invocations
;
i
++
{
s
.
Add
(
test
.
status
)
s
.
Add
(
test
.
status
)
}
}
...
@@ -67,30 +67,30 @@ func TestStatusBatch_Add(t *testing.T) {
...
@@ -67,30 +67,30 @@ func TestStatusBatch_Add(t *testing.T) {
func
TestDetectionBatch_Update
(
t
*
testing
.
T
)
{
func
TestDetectionBatch_Update
(
t
*
testing
.
T
)
{
statusExpectations
:=
[]
struct
{
statusExpectations
:=
[]
struct
{
status
types
.
GameStatus
status
types
.
GameStatus
create
func
(
int
,
bool
)
d
etectionBatch
create
func
(
int
,
bool
)
D
etectionBatch
}{
}{
{
{
status
:
types
.
GameStatusInProgress
,
status
:
types
.
GameStatusInProgress
,
create
:
func
(
inProgress
int
,
_
bool
)
d
etectionBatch
{
create
:
func
(
inProgress
int
,
_
bool
)
D
etectionBatch
{
return
d
etectionBatch
{
inProgress
,
0
,
0
,
0
,
0
}
return
D
etectionBatch
{
inProgress
,
0
,
0
,
0
,
0
}
},
},
},
},
{
{
status
:
types
.
GameStatusDefenderWon
,
status
:
types
.
GameStatusDefenderWon
,
create
:
func
(
defenderWon
int
,
agree
bool
)
d
etectionBatch
{
create
:
func
(
defenderWon
int
,
agree
bool
)
D
etectionBatch
{
if
agree
{
if
agree
{
return
d
etectionBatch
{
0
,
defenderWon
,
0
,
0
,
0
}
return
D
etectionBatch
{
0
,
defenderWon
,
0
,
0
,
0
}
}
}
return
d
etectionBatch
{
0
,
0
,
defenderWon
,
0
,
0
}
return
D
etectionBatch
{
0
,
0
,
defenderWon
,
0
,
0
}
},
},
},
},
{
{
status
:
types
.
GameStatusChallengerWon
,
status
:
types
.
GameStatusChallengerWon
,
create
:
func
(
challengerWon
int
,
agree
bool
)
d
etectionBatch
{
create
:
func
(
challengerWon
int
,
agree
bool
)
D
etectionBatch
{
if
agree
{
if
agree
{
return
d
etectionBatch
{
0
,
0
,
0
,
challengerWon
,
0
}
return
D
etectionBatch
{
0
,
0
,
0
,
challengerWon
,
0
}
}
}
return
d
etectionBatch
{
0
,
0
,
0
,
0
,
challengerWon
}
return
D
etectionBatch
{
0
,
0
,
0
,
0
,
challengerWon
}
},
},
},
},
}
}
...
@@ -100,7 +100,7 @@ func TestDetectionBatch_Update(t *testing.T) {
...
@@ -100,7 +100,7 @@ func TestDetectionBatch_Update(t *testing.T) {
status
types
.
GameStatus
status
types
.
GameStatus
agree
bool
agree
bool
invocations
int
invocations
int
expected
d
etectionBatch
expected
D
etectionBatch
}
}
var
tests
[]
test
var
tests
[]
test
...
@@ -120,7 +120,7 @@ func TestDetectionBatch_Update(t *testing.T) {
...
@@ -120,7 +120,7 @@ func TestDetectionBatch_Update(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
test
:=
test
test
:=
test
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
d
:=
d
etectionBatch
{}
d
:=
D
etectionBatch
{}
for
i
:=
0
;
i
<
test
.
invocations
;
i
++
{
for
i
:=
0
;
i
<
test
.
invocations
;
i
++
{
d
.
Update
(
test
.
status
,
test
.
agree
)
d
.
Update
(
test
.
status
,
test
.
agree
)
}
}
...
@@ -132,52 +132,52 @@ func TestDetectionBatch_Update(t *testing.T) {
...
@@ -132,52 +132,52 @@ func TestDetectionBatch_Update(t *testing.T) {
func
TestDetectionBatch_Merge
(
t
*
testing
.
T
)
{
func
TestDetectionBatch_Merge
(
t
*
testing
.
T
)
{
type
test
struct
{
type
test
struct
{
name
string
name
string
merge
d
etectionBatch
merge
D
etectionBatch
expected
d
etectionBatch
expected
D
etectionBatch
}
}
tests
:=
[]
test
{
tests
:=
[]
test
{
{
{
name
:
"Empty"
,
name
:
"Empty"
,
merge
:
d
etectionBatch
{},
merge
:
D
etectionBatch
{},
expected
:
d
etectionBatch
{},
expected
:
D
etectionBatch
{},
},
},
{
{
name
:
"InProgress"
,
name
:
"InProgress"
,
merge
:
d
etectionBatch
{
1
,
0
,
0
,
0
,
0
},
merge
:
D
etectionBatch
{
1
,
0
,
0
,
0
,
0
},
expected
:
d
etectionBatch
{
1
,
0
,
0
,
0
,
0
},
expected
:
D
etectionBatch
{
1
,
0
,
0
,
0
,
0
},
},
},
{
{
name
:
"AgreeDefenderWins"
,
name
:
"AgreeDefenderWins"
,
merge
:
d
etectionBatch
{
0
,
1
,
0
,
0
,
0
},
merge
:
D
etectionBatch
{
0
,
1
,
0
,
0
,
0
},
expected
:
d
etectionBatch
{
0
,
1
,
0
,
0
,
0
},
expected
:
D
etectionBatch
{
0
,
1
,
0
,
0
,
0
},
},
},
{
{
name
:
"DisagreeDefenderWins"
,
name
:
"DisagreeDefenderWins"
,
merge
:
d
etectionBatch
{
0
,
0
,
1
,
0
,
0
},
merge
:
D
etectionBatch
{
0
,
0
,
1
,
0
,
0
},
expected
:
d
etectionBatch
{
0
,
0
,
1
,
0
,
0
},
expected
:
D
etectionBatch
{
0
,
0
,
1
,
0
,
0
},
},
},
{
{
name
:
"AgreeChallengerWins"
,
name
:
"AgreeChallengerWins"
,
merge
:
d
etectionBatch
{
0
,
0
,
0
,
1
,
0
},
merge
:
D
etectionBatch
{
0
,
0
,
0
,
1
,
0
},
expected
:
d
etectionBatch
{
0
,
0
,
0
,
1
,
0
},
expected
:
D
etectionBatch
{
0
,
0
,
0
,
1
,
0
},
},
},
{
{
name
:
"DisagreeChallengerWins"
,
name
:
"DisagreeChallengerWins"
,
merge
:
d
etectionBatch
{
0
,
0
,
0
,
0
,
1
},
merge
:
D
etectionBatch
{
0
,
0
,
0
,
0
,
1
},
expected
:
d
etectionBatch
{
0
,
0
,
0
,
0
,
1
},
expected
:
D
etectionBatch
{
0
,
0
,
0
,
0
,
1
},
},
},
{
{
name
:
"All"
,
name
:
"All"
,
merge
:
d
etectionBatch
{
1
,
1
,
1
,
1
,
1
},
merge
:
D
etectionBatch
{
1
,
1
,
1
,
1
,
1
},
expected
:
d
etectionBatch
{
1
,
1
,
1
,
1
,
1
},
expected
:
D
etectionBatch
{
1
,
1
,
1
,
1
,
1
},
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
test
:=
test
test
:=
test
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
d
:=
d
etectionBatch
{}
d
:=
D
etectionBatch
{}
d
.
Merge
(
test
.
merge
)
d
.
Merge
(
test
.
merge
)
require
.
Equal
(
t
,
test
.
expected
,
d
)
require
.
Equal
(
t
,
test
.
expected
,
d
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment