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
6786de09
Commit
6786de09
authored
Jul 17, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a simple contract caller struct to the op-challenger for
visibility.
parent
eba4d0fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
219 additions
and
0 deletions
+219
-0
challenger.go
op-challenger/challenger.go
+6
-0
caller.go
op-challenger/fault/caller.go
+104
-0
caller_test.go
op-challenger/fault/caller_test.go
+109
-0
No files found.
op-challenger/challenger.go
View file @
6786de09
...
...
@@ -40,11 +40,17 @@ func Main(logger log.Logger, cfg *config.Config) error {
agent
:=
fault
.
NewAgent
(
loader
,
gameDepth
,
trace
,
responder
,
cfg
.
AgreeWithProposedOutput
,
logger
)
caller
,
err
:=
fault
.
NewFaultCallerFromBindings
(
cfg
.
GameAddress
,
client
,
logger
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to bind the fault contract: %w"
,
err
)
}
logger
.
Info
(
"Fault game started"
)
for
{
logger
.
Info
(
"Performing action"
)
_
=
agent
.
Act
()
caller
.
LogGameInfo
()
time
.
Sleep
(
300
*
time
.
Millisecond
)
}
}
op-challenger/fault/caller.go
0 → 100644
View file @
6786de09
package
fault
import
(
"context"
"math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
)
type
FaultDisputeGameCaller
interface
{
Status
(
opts
*
bind
.
CallOpts
)
(
uint8
,
error
)
ClaimDataLen
(
opts
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
}
type
FaultCaller
struct
{
FaultDisputeGameCaller
log
log
.
Logger
fdgAddr
common
.
Address
}
func
NewFaultCaller
(
fdgAddr
common
.
Address
,
caller
FaultDisputeGameCaller
,
log
log
.
Logger
)
*
FaultCaller
{
return
&
FaultCaller
{
caller
,
log
,
fdgAddr
,
}
}
func
NewFaultCallerFromBindings
(
fdgAddr
common
.
Address
,
client
*
ethclient
.
Client
,
log
log
.
Logger
)
(
*
FaultCaller
,
error
)
{
caller
,
err
:=
bindings
.
NewFaultDisputeGameCaller
(
fdgAddr
,
client
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
FaultCaller
{
caller
,
log
,
fdgAddr
,
},
nil
}
// LogGameInfo logs the game info.
func
(
fc
*
FaultCaller
)
LogGameInfo
()
{
status
,
err
:=
fc
.
GetGameStatus
(
context
.
Background
())
if
err
!=
nil
{
fc
.
log
.
Error
(
"failed to get game status"
,
"err"
,
err
)
return
}
claimLen
,
err
:=
fc
.
GetClaimDataLength
(
context
.
Background
())
if
err
!=
nil
{
fc
.
log
.
Error
(
"failed to get claim count"
,
"err"
,
err
)
return
}
fc
.
log
.
Info
(
"Game info"
,
"addr"
,
fc
.
fdgAddr
,
"claims"
,
claimLen
,
"status"
,
GameStatusString
(
status
))
}
// GetGameStatus returns the current game status.
// 0: In Progress
// 1: Challenger Won
// 2: Defender Won
func
(
fc
*
FaultCaller
)
GetGameStatus
(
ctx
context
.
Context
)
(
uint8
,
error
)
{
return
fc
.
Status
(
&
bind
.
CallOpts
{
Context
:
ctx
})
}
func
(
fc
*
FaultCaller
)
LogGameStatus
()
{
status
,
err
:=
fc
.
GetGameStatus
(
context
.
Background
())
if
err
!=
nil
{
fc
.
log
.
Error
(
"failed to get game status"
,
"err"
,
err
)
return
}
fc
.
log
.
Info
(
"Game status"
,
"status"
,
GameStatusString
(
status
))
}
// GetClaimDataLength returns the number of claims in the game.
func
(
fc
*
FaultCaller
)
GetClaimDataLength
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
return
fc
.
ClaimDataLen
(
&
bind
.
CallOpts
{
Context
:
ctx
})
}
func
(
fc
*
FaultCaller
)
LogClaimDataLength
()
{
claimLen
,
err
:=
fc
.
GetClaimDataLength
(
context
.
Background
())
if
err
!=
nil
{
fc
.
log
.
Error
(
"failed to get claim count"
,
"err"
,
err
)
return
}
fc
.
log
.
Info
(
"Number of claims"
,
"length"
,
claimLen
)
}
// GameStatusString returns the current game status as a string.
func
GameStatusString
(
status
uint8
)
string
{
switch
status
{
case
0
:
return
"In Progress"
case
1
:
return
"Challenger Won"
case
2
:
return
"Defender Won"
default
:
return
"Unknown"
}
}
op-challenger/fault/caller_test.go
0 → 100644
View file @
6786de09
package
fault
import
(
"context"
"errors"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
var
(
testAddr
=
common
.
HexToAddress
(
"0x1234567890123456789012345678901234567890"
)
errMock
=
errors
.
New
(
"mock error"
)
)
type
mockFaultDisputeGameCaller
struct
{
status
uint8
errStatus
bool
claimDataLen
*
big
.
Int
errClaimDataLen
bool
}
func
(
m
*
mockFaultDisputeGameCaller
)
Status
(
opts
*
bind
.
CallOpts
)
(
uint8
,
error
)
{
if
m
.
errStatus
{
return
0
,
errMock
}
return
m
.
status
,
nil
}
func
(
m
*
mockFaultDisputeGameCaller
)
ClaimDataLen
(
opts
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
if
m
.
errClaimDataLen
{
return
nil
,
errMock
}
return
m
.
claimDataLen
,
nil
}
func
TestFaultCaller_GetGameStatus
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
caller
FaultDisputeGameCaller
expectedStatus
uint8
expectedErr
error
}{
{
name
:
"success"
,
caller
:
&
mockFaultDisputeGameCaller
{
status
:
1
,
},
expectedStatus
:
1
,
expectedErr
:
nil
,
},
{
name
:
"error"
,
caller
:
&
mockFaultDisputeGameCaller
{
errStatus
:
true
,
},
expectedStatus
:
0
,
expectedErr
:
errMock
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
fc
:=
NewFaultCaller
(
testAddr
,
test
.
caller
,
nil
)
status
,
err
:=
fc
.
GetGameStatus
(
context
.
Background
())
require
.
Equal
(
t
,
test
.
expectedStatus
,
status
)
require
.
Equal
(
t
,
test
.
expectedErr
,
err
)
})
}
}
func
TestFaultCaller_GetClaimDataLength
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
caller
FaultDisputeGameCaller
expectedClaimDataLen
*
big
.
Int
expectedErr
error
}{
{
name
:
"success"
,
caller
:
&
mockFaultDisputeGameCaller
{
claimDataLen
:
big
.
NewInt
(
1
),
},
expectedClaimDataLen
:
big
.
NewInt
(
1
),
expectedErr
:
nil
,
},
{
name
:
"error"
,
caller
:
&
mockFaultDisputeGameCaller
{
errClaimDataLen
:
true
,
},
expectedClaimDataLen
:
nil
,
expectedErr
:
errMock
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
fc
:=
NewFaultCaller
(
testAddr
,
test
.
caller
,
nil
)
claimDataLen
,
err
:=
fc
.
GetClaimDataLength
(
context
.
Background
())
require
.
Equal
(
t
,
test
.
expectedClaimDataLen
,
claimDataLen
)
require
.
Equal
(
t
,
test
.
expectedErr
,
err
)
})
}
}
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