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
fedab2a6
Unverified
Commit
fedab2a6
authored
Jan 05, 2024
by
refcell.eth
Committed by
GitHub
Jan 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: touchup alphabet trace provider tests (#8860)
parent
a7a1775b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
54 deletions
+121
-54
provider.go
op-challenger/game/fault/trace/alphabet/provider.go
+6
-4
provider_test.go
op-challenger/game/fault/trace/alphabet/provider_test.go
+115
-50
No files found.
op-challenger/game/fault/trace/alphabet/provider.go
View file @
fedab2a6
...
@@ -24,8 +24,10 @@ var (
...
@@ -24,8 +24,10 @@ var (
ErrIndexTooLarge
=
errors
.
New
(
"index is larger than the maximum index"
)
ErrIndexTooLarge
=
errors
.
New
(
"index is larger than the maximum index"
)
)
)
// AlphabetTraceProvider is a [TraceProvider] that provides claims for specific
var
_
types
.
TraceProvider
=
(
*
AlphabetTraceProvider
)(
nil
)
// indices in the given trace.
// AlphabetTraceProvider is a [TraceProvider] that monotonically increments
// the starting l2 block number as the claim value.
type
AlphabetTraceProvider
struct
{
type
AlphabetTraceProvider
struct
{
AlphabetPrestateProvider
AlphabetPrestateProvider
startingBlockNumber
*
big
.
Int
startingBlockNumber
*
big
.
Int
...
@@ -93,8 +95,8 @@ func (ap *AlphabetTraceProvider) Get(ctx context.Context, i types.Position) (com
...
@@ -93,8 +95,8 @@ func (ap *AlphabetTraceProvider) Get(ctx context.Context, i types.Position) (com
}
}
// BuildAlphabetPreimage constructs the claim bytes for the index and claim.
// BuildAlphabetPreimage constructs the claim bytes for the index and claim.
func
BuildAlphabetPreimage
(
i
*
big
.
Int
,
blockNumber
*
big
.
Int
)
[]
byte
{
func
BuildAlphabetPreimage
(
traceIndex
*
big
.
Int
,
claim
*
big
.
Int
)
[]
byte
{
return
append
(
i
.
FillBytes
(
make
([]
byte
,
32
)),
blockNumber
.
FillBytes
(
make
([]
byte
,
32
))
...
)
return
append
(
traceIndex
.
FillBytes
(
make
([]
byte
,
32
)),
claim
.
FillBytes
(
make
([]
byte
,
32
))
...
)
}
}
func
alphabetStateHash
(
state
[]
byte
)
common
.
Hash
{
func
alphabetStateHash
(
state
[]
byte
)
common
.
Hash
{
...
...
op-challenger/game/fault/trace/alphabet/provider_test.go
View file @
fedab2a6
...
@@ -80,62 +80,127 @@ func TestAlphabetProvider_Get_ClaimsByTraceIndex(t *testing.T) {
...
@@ -80,62 +80,127 @@ func TestAlphabetProvider_Get_ClaimsByTraceIndex(t *testing.T) {
}
}
}
}
// TestGetPreimage_Succeeds tests the GetPreimage function
// TestAlphabetProvider_GetStepData tests the GetStepData function.
// returns the correct pre-image for a index.
func
TestAlphabetProvider_GetStepData
(
t
*
testing
.
T
)
{
func
TestGetStepData_Succeeds
(
t
*
testing
.
T
)
{
depth
:=
types
.
Depth
(
2
)
depth
:=
types
.
Depth
(
2
)
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
expected
:=
absolutePrestate
pos
:=
types
.
NewPosition
(
depth
,
big
.
NewInt
(
0
))
retrieved
,
proof
,
data
,
err
:=
ap
.
GetStepData
(
context
.
Background
(),
pos
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
expected
,
retrieved
)
require
.
Empty
(
t
,
proof
)
key
:=
preimage
.
LocalIndexKey
(
L2ClaimBlockNumberLocalIndex
)
.
PreimageKey
()
key
:=
preimage
.
LocalIndexKey
(
L2ClaimBlockNumberLocalIndex
)
.
PreimageKey
()
expectedLocalContextData
:=
types
.
NewPreimageOracleData
(
key
[
:
],
startingL2BlockNumber
.
Bytes
(),
0
)
expectedPreimageData
:=
types
.
NewPreimageOracleData
(
key
[
:
],
startingL2BlockNumber
.
Bytes
(),
0
)
require
.
Equal
(
t
,
expectedLocalContextData
,
data
)
}
tests
:=
[]
struct
{
name
string
// TestGetPreimage_TooLargeIndex_Fails tests the GetPreimage
indexAtDepth
*
big
.
Int
// function errors if the index is too large.
expectedResult
[]
byte
func
TestGetStepData_TooLargeIndex_Fails
(
t
*
testing
.
T
)
{
expectedPreimageData
*
types
.
PreimageOracleData
depth
:=
types
.
Depth
(
2
)
expectedError
error
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
}{
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
{
pos
:=
types
.
NewPosition
(
depth
,
big
.
NewInt
(
5
))
name
:
"AbsolutePrestate"
,
_
,
_
,
_
,
err
:=
ap
.
GetStepData
(
context
.
Background
(),
pos
)
indexAtDepth
:
big
.
NewInt
(
0
),
require
.
ErrorIs
(
t
,
err
,
ErrIndexTooLarge
)
expectedResult
:
absolutePrestate
,
}
expectedPreimageData
:
expectedPreimageData
,
expectedError
:
nil
,
},
{
name
:
"SecondStep"
,
indexAtDepth
:
big
.
NewInt
(
1
),
expectedResult
:
BuildAlphabetPreimage
(
big
.
NewInt
(
17
),
big
.
NewInt
(
113
)),
expectedPreimageData
:
expectedPreimageData
,
expectedError
:
nil
,
},
{
name
:
"LastStep"
,
indexAtDepth
:
big
.
NewInt
(
4
),
expectedResult
:
BuildAlphabetPreimage
(
big
.
NewInt
(
20
),
big
.
NewInt
(
116
)),
expectedPreimageData
:
expectedPreimageData
,
expectedError
:
nil
,
},
{
name
:
"IndexTooLarge"
,
indexAtDepth
:
big
.
NewInt
(
5
),
expectedResult
:
nil
,
expectedPreimageData
:
nil
,
expectedError
:
ErrIndexTooLarge
,
},
}
// TestGet_Succeeds tests the Get function.
for
_
,
test
:=
range
tests
{
func
TestGet_Succeeds
(
t
*
testing
.
T
)
{
test
:=
test
depth
:=
types
.
Depth
(
2
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
result
,
proof
,
data
,
err
:=
ap
.
GetStepData
(
context
.
Background
(),
types
.
NewPosition
(
depth
,
test
.
indexAtDepth
))
pos
:=
types
.
NewPosition
(
depth
,
big
.
NewInt
(
0
))
require
.
Equal
(
t
,
test
.
expectedResult
,
result
)
claim
,
err
:=
ap
.
Get
(
context
.
Background
(),
pos
)
require
.
Empty
(
t
,
proof
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
test
.
expectedPreimageData
,
data
)
expected
:=
alphabetClaim
(
big
.
NewInt
(
17
),
big
.
NewInt
(
113
))
if
test
.
expectedError
!=
nil
{
require
.
Equal
(
t
,
expected
,
claim
)
require
.
ErrorIs
(
t
,
err
,
test
.
expectedError
)
}
else
{
require
.
NoError
(
t
,
err
)
}
})
}
}
}
// TestGet_IndexTooLarge tests the Get function with an index
// TestAlphabetProvider_Get tests the Get function.
// greater than the number of indices: 2^depth - 1.
func
TestAlphabetProvider_Get
(
t
*
testing
.
T
)
{
func
TestGet_IndexTooLarge
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
depth
:=
types
.
Depth
(
2
)
name
string
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
depth
types
.
Depth
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
indexAtDepth
*
big
.
Int
pos
:=
types
.
NewPosition
(
depth
,
big
.
NewInt
(
4
))
expectedClaim
common
.
Hash
_
,
err
:=
ap
.
Get
(
context
.
Background
(),
pos
)
expectedError
error
require
.
ErrorIs
(
t
,
err
,
ErrIndexTooLarge
)
}{
}
{
name
:
"AbsolutePrestate"
,
depth
:
types
.
Depth
(
2
),
indexAtDepth
:
big
.
NewInt
(
0
),
expectedClaim
:
alphabetClaim
(
big
.
NewInt
(
17
),
big
.
NewInt
(
113
)),
expectedError
:
nil
,
},
{
name
:
"SecondStep"
,
depth
:
types
.
Depth
(
2
),
indexAtDepth
:
big
.
NewInt
(
1
),
expectedClaim
:
alphabetClaim
(
big
.
NewInt
(
18
),
big
.
NewInt
(
114
)),
expectedError
:
nil
,
},
{
name
:
"LastStep"
,
depth
:
types
.
Depth
(
2
),
indexAtDepth
:
big
.
NewInt
(
3
),
expectedClaim
:
alphabetClaim
(
big
.
NewInt
(
20
),
big
.
NewInt
(
116
)),
expectedError
:
nil
,
},
{
name
:
"IndexTooLarge"
,
depth
:
types
.
Depth
(
2
),
indexAtDepth
:
big
.
NewInt
(
5
),
expectedClaim
:
common
.
Hash
{},
expectedError
:
ErrIndexTooLarge
,
},
{
name
:
"DepthTooLarge"
,
depth
:
types
.
Depth
(
3
),
indexAtDepth
:
big
.
NewInt
(
0
),
expectedClaim
:
common
.
Hash
{},
expectedError
:
ErrIndexTooLarge
,
},
}
func
TestGet_DepthTooLarge
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
tests
{
depth
:=
types
.
Depth
(
2
)
test
:=
test
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
depth
)
startingL2BlockNumber
:=
big
.
NewInt
(
1
)
pos
:=
types
.
NewPosition
(
depth
+
1
,
big
.
NewInt
(
0
))
ap
:=
NewTraceProvider
(
startingL2BlockNumber
,
types
.
Depth
(
2
))
_
,
err
:=
ap
.
Get
(
context
.
Background
(),
pos
)
require
.
ErrorIs
(
t
,
err
,
ErrIndexTooLarge
)
result
,
err
:=
ap
.
Get
(
context
.
Background
(),
types
.
NewPosition
(
test
.
depth
,
test
.
indexAtDepth
))
require
.
Equal
(
t
,
test
.
expectedClaim
,
result
)
if
test
.
expectedError
!=
nil
{
require
.
ErrorIs
(
t
,
err
,
test
.
expectedError
)
}
else
{
require
.
NoError
(
t
,
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