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
ee33ff83
Unverified
Commit
ee33ff83
authored
Jul 25, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Add config and CLI args to support actually executing cannon
parent
3891726b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
215 additions
and
65 deletions
+215
-65
main_test.go
op-challenger/cmd/main_test.go
+105
-29
config.go
op-challenger/config/config.go
+32
-15
config_test.go
op-challenger/config/config_test.go
+45
-18
flags.go
op-challenger/flags/flags.go
+33
-3
No files found.
op-challenger/cmd/main_test.go
View file @
ee33ff83
...
...
@@ -15,7 +15,10 @@ import (
var
(
l1EthRpc
=
"http://example.com:8545"
gameAddressValue
=
"0xaa00000000000000000000000000000000000000"
cannonBin
=
"./bin/cannon"
cannonPreState
=
"./pre.json"
cannonDatadir
=
"./test_data"
cannonL2
=
"http://example.com:9545"
alphabetTrace
=
"abcdefghijz"
agreeWithProposedOutput
=
"true"
gameDepth
=
"4"
...
...
@@ -23,13 +26,13 @@ var (
func
TestLogLevel
(
t
*
testing
.
T
)
{
t
.
Run
(
"RejectInvalid"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"unknown level: foo"
,
addRequiredArgs
(
"--log.level=foo"
))
verifyArgsInvalid
(
t
,
"unknown level: foo"
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--log.level=foo"
))
})
for
_
,
lvl
:=
range
[]
string
{
"trace"
,
"debug"
,
"info"
,
"error"
,
"crit"
}
{
lvl
:=
lvl
t
.
Run
(
"AcceptValid_"
+
lvl
,
func
(
t
*
testing
.
T
)
{
logger
,
_
,
err
:=
runWithArgs
(
addRequiredArgs
(
"--log.level"
,
lvl
))
logger
,
_
,
err
:=
runWithArgs
(
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--log.level"
,
lvl
))
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
logger
)
})
...
...
@@ -37,24 +40,29 @@ func TestLogLevel(t *testing.T) {
}
func
TestDefaultCLIOptionsMatchDefaultConfig
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
())
defaultCfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
alphabetTrace
,
cannonDatadir
,
true
,
4
)
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
))
defaultCfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
true
,
4
)
// Add in the extra CLI options required when using alphabet trace type
defaultCfg
.
AlphabetTrace
=
alphabetTrace
require
.
Equal
(
t
,
defaultCfg
,
cfg
)
}
func
TestDefaultConfigIsValid
(
t
*
testing
.
T
)
{
cfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
alphabetTrace
,
cannonDatadir
,
true
,
4
)
cfg
:=
config
.
NewConfig
(
l1EthRpc
,
common
.
HexToAddress
(
gameAddressValue
),
config
.
TraceTypeAlphabet
,
true
,
4
)
// Add in options that are required based on the specific trace type
// To avoid needing to specify unused options, these aren't included in the params for NewConfig
cfg
.
AlphabetTrace
=
alphabetTrace
require
.
NoError
(
t
,
cfg
.
Check
())
}
func
TestL1ETHRPCAddress
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag l1-eth-rpc is required"
,
addRequiredArgsExcept
(
"--l1-eth-rpc"
))
verifyArgsInvalid
(
t
,
"flag l1-eth-rpc is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--l1-eth-rpc"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
url
:=
"http://example.com:8888"
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
"--l1-eth-rpc"
,
"--l1-eth-rpc="
+
url
))
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--l1-eth-rpc"
,
"--l1-eth-rpc="
+
url
))
require
.
Equal
(
t
,
url
,
cfg
.
L1EthRpc
)
require
.
Equal
(
t
,
url
,
cfg
.
TxMgrConfig
.
L1RPCURL
)
})
...
...
@@ -62,74 +70,134 @@ func TestL1ETHRPCAddress(t *testing.T) {
func
TestTraceType
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag trace-type is required"
,
addRequiredArgsExcept
(
"--trace-type"
))
verifyArgsInvalid
(
t
,
"flag trace-type is required"
,
addRequiredArgsExcept
(
"
"
,
"
--trace-type"
))
})
for
_
,
traceType
:=
range
config
.
TraceTypes
{
traceType
:=
traceType
t
.
Run
(
"Valid_"
+
traceType
.
String
(),
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
Except
(
"--trace-type"
,
"--trace-type"
,
traceType
.
String
()
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
traceType
))
require
.
Equal
(
t
,
traceType
,
cfg
.
TraceType
)
})
}
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"unknown trace type:
\"
foo
\"
"
,
addRequiredArgsExcept
(
"--trace-type"
,
"--trace-type=foo"
))
verifyArgsInvalid
(
t
,
"unknown trace type:
\"
foo
\"
"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--trace-type"
,
"--trace-type=foo"
))
})
}
func
TestGameAddress
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag game-address is required"
,
addRequiredArgsExcept
(
"--game-address"
))
verifyArgsInvalid
(
t
,
"flag game-address is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--game-address"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
addr
:=
common
.
Address
{
0xbb
,
0xcc
,
0xdd
}
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
"--game-address"
,
"--game-address="
+
addr
.
Hex
()))
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--game-address"
,
"--game-address="
+
addr
.
Hex
()))
require
.
Equal
(
t
,
addr
,
cfg
.
GameAddress
)
})
t
.
Run
(
"Invalid"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"invalid address: foo"
,
addRequiredArgsExcept
(
"--game-address"
,
"--game-address=foo"
))
verifyArgsInvalid
(
t
,
"invalid address: foo"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--game-address"
,
"--game-address=foo"
))
})
}
func
TestTxManagerFlagsSupported
(
t
*
testing
.
T
)
{
// Not a comprehensive list of flags, just enough to sanity check the txmgr.CLIFlags were defined
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
"--"
+
txmgr
.
NumConfirmationsFlagName
,
"7"
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--"
+
txmgr
.
NumConfirmationsFlagName
,
"7"
))
require
.
Equal
(
t
,
uint64
(
7
),
cfg
.
TxMgrConfig
.
NumConfirmations
)
}
func
TestAgreeWithProposedOutput
(
t
*
testing
.
T
)
{
t
.
Run
(
"MustBeProvided"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag agree-with-proposed-output is required"
,
addRequiredArgsExcept
(
"--agree-with-proposed-output"
))
verifyArgsInvalid
(
t
,
"flag agree-with-proposed-output is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--agree-with-proposed-output"
))
})
t
.
Run
(
"Enabled"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
"--agree-with-proposed-output"
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--agree-with-proposed-output"
))
require
.
True
(
t
,
cfg
.
AgreeWithProposedOutput
)
})
t
.
Run
(
"EnabledWithArg"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
"--agree-with-proposed-output=true"
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--agree-with-proposed-output=true"
))
require
.
True
(
t
,
cfg
.
AgreeWithProposedOutput
)
})
t
.
Run
(
"Disabled"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
"--agree-with-proposed-output=false"
))
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeAlphabet
,
"--agree-with-proposed-output=false"
))
require
.
False
(
t
,
cfg
.
AgreeWithProposedOutput
)
})
}
func
TestGameDepth
(
t
*
testing
.
T
)
{
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag game-depth is required"
,
addRequiredArgsExcept
(
"--game-depth"
))
verifyArgsInvalid
(
t
,
"flag game-depth is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--game-depth"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
value
:=
"4"
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
"--game-depth"
,
"--game-depth="
+
value
))
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--game-depth"
,
"--game-depth="
+
value
))
require
.
Equal
(
t
,
value
,
fmt
.
Sprint
(
cfg
.
GameDepth
))
})
}
func
TestCannonBin
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-bin"
))
})
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag cannon-bin is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-bin"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-bin"
,
"--cannon-bin=./cannon"
))
require
.
Equal
(
t
,
"./cannon"
,
cfg
.
CannonBin
)
})
}
func
TestCannonAbsolutePrestate
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-prestate"
))
})
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag cannon-prestate is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-prestate"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-prestate"
,
"--cannon-prestate=./pre.json"
))
require
.
Equal
(
t
,
"./pre.json"
,
cfg
.
CannonAbsolutePreState
)
})
}
func
TestCannonDataDir
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-datadir"
))
})
t
.
Run
(
"Required"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag cannon-datadir is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-datadir"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-datadir"
,
"--cannon-datadir=/foo/bar/cannon"
))
require
.
Equal
(
t
,
"/foo/bar/cannon"
,
cfg
.
CannonDatadir
)
})
}
func
TestCannonL2
(
t
*
testing
.
T
)
{
t
.
Run
(
"NotRequiredForAlphabetTrace"
,
func
(
t
*
testing
.
T
)
{
configForArgs
(
t
,
addRequiredArgsExcept
(
config
.
TraceTypeAlphabet
,
"--cannon-l2"
))
})
t
.
Run
(
"RequiredForCannonTrace"
,
func
(
t
*
testing
.
T
)
{
verifyArgsInvalid
(
t
,
"flag cannon-l2 is required"
,
addRequiredArgsExcept
(
config
.
TraceTypeCannon
,
"--cannon-l2"
))
})
t
.
Run
(
"Valid"
,
func
(
t
*
testing
.
T
)
{
cfg
:=
configForArgs
(
t
,
addRequiredArgs
(
config
.
TraceTypeCannon
))
require
.
Equal
(
t
,
cannonL2
,
cfg
.
CannonL2
)
})
}
func
verifyArgsInvalid
(
t
*
testing
.
T
,
messageContains
string
,
cliArgs
[]
string
)
{
_
,
_
,
err
:=
runWithArgs
(
cliArgs
)
require
.
ErrorContains
(
t
,
err
,
messageContains
)
...
...
@@ -153,28 +221,36 @@ func runWithArgs(cliArgs []string) (log.Logger, config.Config, error) {
return
logger
,
*
cfg
,
err
}
func
addRequiredArgs
(
args
...
string
)
[]
string
{
req
:=
requiredArgs
()
func
addRequiredArgs
(
traceType
config
.
TraceType
,
args
...
string
)
[]
string
{
req
:=
requiredArgs
(
traceType
)
combined
:=
toArgList
(
req
)
return
append
(
combined
,
args
...
)
}
func
addRequiredArgsExcept
(
name
string
,
optionalArgs
...
string
)
[]
string
{
req
:=
requiredArgs
()
func
addRequiredArgsExcept
(
traceType
config
.
TraceType
,
name
string
,
optionalArgs
...
string
)
[]
string
{
req
:=
requiredArgs
(
traceType
)
delete
(
req
,
name
)
return
append
(
toArgList
(
req
),
optionalArgs
...
)
}
func
requiredArgs
()
map
[
string
]
string
{
return
map
[
string
]
string
{
func
requiredArgs
(
traceType
config
.
TraceType
)
map
[
string
]
string
{
args
:=
map
[
string
]
string
{
"--game-depth"
:
gameDepth
,
"--agree-with-proposed-output"
:
agreeWithProposedOutput
,
"--l1-eth-rpc"
:
l1EthRpc
,
"--game-address"
:
gameAddressValue
,
"--trace-type"
:
"alphabet"
,
"--alphabet"
:
alphabetTrace
,
"--cannon-datadir"
:
cannonDatadir
,
"--trace-type"
:
traceType
.
String
(),
}
switch
traceType
{
case
config
.
TraceTypeAlphabet
:
args
[
"--alphabet"
]
=
alphabetTrace
case
config
.
TraceTypeCannon
:
args
[
"--cannon-bin"
]
=
cannonBin
args
[
"--cannon-prestate"
]
=
cannonPreState
args
[
"--cannon-datadir"
]
=
cannonDatadir
args
[
"--cannon-l2"
]
=
cannonL2
}
return
args
}
func
toArgList
(
req
map
[
string
]
string
)
[]
string
{
...
...
op-challenger/config/config.go
View file @
ee33ff83
...
...
@@ -9,11 +9,14 @@ import (
)
var
(
ErrMissingTraceType
=
errors
.
New
(
"missing trace type"
)
ErrMissingCannonDatadir
=
errors
.
New
(
"missing cannon datadir"
)
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
ErrMissingTraceType
=
errors
.
New
(
"missing trace type"
)
ErrMissingCannonDatadir
=
errors
.
New
(
"missing cannon datadir"
)
ErrMissingCannonL2
=
errors
.
New
(
"missing cannon L2"
)
ErrMissingCannonBin
=
errors
.
New
(
"missing cannon bin"
)
ErrMissingCannonAbsolutePreState
=
errors
.
New
(
"missing cannon absolute pre-state"
)
ErrMissingAlphabetTrace
=
errors
.
New
(
"missing alphabet trace"
)
ErrMissingL1EthRPC
=
errors
.
New
(
"missing l1 eth rpc url"
)
ErrMissingGameAddress
=
errors
.
New
(
"missing game address"
)
)
type
TraceType
string
...
...
@@ -56,9 +59,16 @@ type Config struct {
AgreeWithProposedOutput
bool
// Temporary config if we agree or disagree with the posted output
GameDepth
int
// Depth of the game tree
TraceType
TraceType
// Type of trace
AlphabetTrace
string
// String for the AlphabetTraceProvider
CannonDatadir
string
// Cannon Data Directory for the CannonTraceProvider
TraceType
TraceType
// Type of trace
// Specific to the alphabet trace provider
AlphabetTrace
string
// String for the AlphabetTraceProvider
// Specific to the cannon trace provider
CannonBin
string
// Path to the cannon executable to run when generating trace data
CannonAbsolutePreState
string
// File to load the absolute pre-state for Cannon traces from
CannonDatadir
string
// Cannon Data Directory
CannonL2
string
// L2 RPC Url
TxMgrConfig
txmgr
.
CLIConfig
}
...
...
@@ -67,8 +77,6 @@ func NewConfig(
l1EthRpc
string
,
gameAddress
common
.
Address
,
traceType
TraceType
,
alphabetTrace
string
,
cannonDatadir
string
,
agreeWithProposedOutput
bool
,
gameDepth
int
,
)
Config
{
...
...
@@ -79,9 +87,7 @@ func NewConfig(
AgreeWithProposedOutput
:
agreeWithProposedOutput
,
GameDepth
:
gameDepth
,
TraceType
:
traceType
,
AlphabetTrace
:
alphabetTrace
,
CannonDatadir
:
cannonDatadir
,
TraceType
:
traceType
,
TxMgrConfig
:
txmgr
.
NewCLIConfig
(
l1EthRpc
),
}
...
...
@@ -97,8 +103,19 @@ func (c Config) Check() error {
if
c
.
TraceType
==
""
{
return
ErrMissingTraceType
}
if
c
.
TraceType
==
TraceTypeCannon
&&
c
.
CannonDatadir
==
""
{
return
ErrMissingCannonDatadir
if
c
.
TraceType
==
TraceTypeCannon
{
if
c
.
CannonBin
==
""
{
return
ErrMissingCannonBin
}
if
c
.
CannonAbsolutePreState
==
""
{
return
ErrMissingCannonAbsolutePreState
}
if
c
.
CannonDatadir
==
""
{
return
ErrMissingCannonDatadir
}
if
c
.
CannonL2
==
""
{
return
ErrMissingCannonL2
}
}
if
c
.
TraceType
==
TraceTypeAlphabet
&&
c
.
AlphabetTrace
==
""
{
return
ErrMissingAlphabetTrace
...
...
op-challenger/config/config_test.go
View file @
ee33ff83
...
...
@@ -9,23 +9,40 @@ import (
)
var
(
validL1EthRpc
=
"http://localhost:8545"
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validAlphabetTrace
=
"abcdefgh"
validCannonDatadir
=
"/tmp/cannon"
agreeWithProposedOutput
=
true
gameDepth
=
4
validL1EthRpc
=
"http://localhost:8545"
validGameAddress
=
common
.
HexToAddress
(
"0x7bdd3b028C4796eF0EAf07d11394d0d9d8c24139"
)
validAlphabetTrace
=
"abcdefgh"
validCannonBin
=
"./bin/cannon"
validCannonAbsolutPreState
=
"pre.json"
validCannonDatadir
=
"/tmp/cannon"
validCannonL2
=
"http://localhost:9545"
agreeWithProposedOutput
=
true
gameDepth
=
4
)
func
validConfig
(
traceType
TraceType
)
Config
{
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
traceType
,
validAlphabetTrace
,
validCannonDatadir
,
agreeWithProposedOutput
,
gameDepth
)
cfg
:=
NewConfig
(
validL1EthRpc
,
validGameAddress
,
traceType
,
agreeWithProposedOutput
,
gameDepth
)
switch
traceType
{
case
TraceTypeAlphabet
:
cfg
.
AlphabetTrace
=
validAlphabetTrace
case
TraceTypeCannon
:
cfg
.
CannonBin
=
validCannonBin
cfg
.
CannonAbsolutePreState
=
validCannonAbsolutPreState
cfg
.
CannonDatadir
=
validCannonDatadir
cfg
.
CannonL2
=
validCannonL2
}
return
cfg
}
// TestValidConfigIsValid checks that the config provided by validConfig is actually valid
func
TestValidConfigIsValid
(
t
*
testing
.
T
)
{
err
:=
validConfig
(
TraceTypeCannon
)
.
Check
()
require
.
NoError
(
t
,
err
)
for
_
,
traceType
:=
range
TraceTypes
{
traceType
:=
traceType
t
.
Run
(
traceType
.
String
(),
func
(
t
*
testing
.
T
)
{
err
:=
validConfig
(
traceType
)
.
Check
()
require
.
NoError
(
t
,
err
)
})
}
}
func
TestTxMgrConfig
(
t
*
testing
.
T
)
{
...
...
@@ -40,30 +57,40 @@ func TestL1EthRpcRequired(t *testing.T) {
config
:=
validConfig
(
TraceTypeCannon
)
config
.
L1EthRpc
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingL1EthRPC
)
config
.
L1EthRpc
=
validL1EthRpc
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestGameAddressRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
GameAddress
=
common
.
Address
{}
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingGameAddress
)
config
.
GameAddress
=
validGameAddress
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestAlphabetTraceRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeAlphabet
)
config
.
AlphabetTrace
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingAlphabetTrace
)
config
.
AlphabetTrace
=
validAlphabetTrace
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestCannonTraceRequired
(
t
*
testing
.
T
)
{
func
TestCannonBinRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonBin
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonBin
)
}
func
TestCannonAbsolutePreStateRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonAbsolutePreState
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonAbsolutePreState
)
}
func
TestCannonDatadirRequired
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonDatadir
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonDatadir
)
config
.
CannonDatadir
=
validCannonDatadir
require
.
NoError
(
t
,
config
.
Check
())
}
func
TestCannonL2Required
(
t
*
testing
.
T
)
{
config
:=
validConfig
(
TraceTypeCannon
)
config
.
CannonL2
=
""
require
.
ErrorIs
(
t
,
config
.
Check
(),
ErrMissingCannonL2
)
}
op-challenger/flags/flags.go
View file @
ee33ff83
...
...
@@ -55,14 +55,29 @@ var (
// Optional Flags
AlphabetFlag
=
&
cli
.
StringFlag
{
Name
:
"alphabet"
,
Usage
:
"
Alphabet Trace (temporar
y)"
,
Usage
:
"
Correct Alphabet Trace (alphabet trace type onl
y)"
,
EnvVars
:
prefixEnvVars
(
"ALPHABET"
),
}
CannonBinFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-bin"
,
Usage
:
"Path to cannon executable to use when generating trace data (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_BIN"
),
}
CannonPreStateFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-prestate"
,
Usage
:
"Path to absolute prestate to use when generating trace data (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_PRESTATE"
),
}
CannonDatadirFlag
=
&
cli
.
StringFlag
{
Name
:
"cannon-datadir"
,
Usage
:
"
Cannon Data Directory
"
,
Usage
:
"
Directory to store data generated by cannon (cannon trace type only)
"
,
EnvVars
:
prefixEnvVars
(
"CANNON_DATADIR"
),
}
CannonL2Flag
=
&
cli
.
StringFlag
{
Name
:
"cannon-l2"
,
Usage
:
"L2 Address of L2 JSON-RPC endpoint to use (eth and debug namespace required) (cannon trace type only)"
,
EnvVars
:
prefixEnvVars
(
"CANNON_L2"
),
}
)
// requiredFlags are checked by [CheckRequired]
...
...
@@ -77,7 +92,10 @@ var requiredFlags = []cli.Flag{
// optionalFlags is a list of unchecked cli flags
var
optionalFlags
=
[]
cli
.
Flag
{
AlphabetFlag
,
CannonBinFlag
,
CannonPreStateFlag
,
CannonDatadirFlag
,
CannonL2Flag
,
}
func
init
()
{
...
...
@@ -99,8 +117,17 @@ func CheckRequired(ctx *cli.Context) error {
gameType
:=
config
.
TraceType
(
strings
.
ToLower
(
ctx
.
String
(
TraceTypeFlag
.
Name
)))
switch
gameType
{
case
config
.
TraceTypeCannon
:
if
!
ctx
.
IsSet
(
CannonBinFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonBinFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonPreStateFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonPreStateFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonDatadirFlag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
"cannon-datadir"
)
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonDatadirFlag
.
Name
)
}
if
!
ctx
.
IsSet
(
CannonL2Flag
.
Name
)
{
return
fmt
.
Errorf
(
"flag %s is required"
,
CannonL2Flag
.
Name
)
}
case
config
.
TraceTypeAlphabet
:
if
!
ctx
.
IsSet
(
AlphabetFlag
.
Name
)
{
...
...
@@ -132,7 +159,10 @@ func NewConfigFromCLI(ctx *cli.Context) (*config.Config, error) {
TraceType
:
traceTypeFlag
,
GameAddress
:
dgfAddress
,
AlphabetTrace
:
ctx
.
String
(
AlphabetFlag
.
Name
),
CannonBin
:
ctx
.
String
(
CannonBinFlag
.
Name
),
CannonAbsolutePreState
:
ctx
.
String
(
CannonPreStateFlag
.
Name
),
CannonDatadir
:
ctx
.
String
(
CannonDatadirFlag
.
Name
),
CannonL2
:
ctx
.
String
(
CannonL2Flag
.
Name
),
AgreeWithProposedOutput
:
ctx
.
Bool
(
AgreeWithProposedOutputFlag
.
Name
),
GameDepth
:
ctx
.
Int
(
GameDepthFlag
.
Name
),
TxMgrConfig
:
txMgrConfig
,
...
...
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