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
2a201dce
Unverified
Commit
2a201dce
authored
Mar 27, 2023
by
mergify[bot]
Committed by
GitHub
Mar 27, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5254 from ethereum-optimism/fix/event-tests
op-node: system config derive tests
parents
c6c9b864
0c8098b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
170 additions
and
0 deletions
+170
-0
system_config_test.go
op-node/rollup/derive/system_config_test.go
+170
-0
No files found.
op-node/rollup/derive/system_config_test.go
0 → 100644
View file @
2a201dce
package
derive
import
(
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)
var
(
// ABI encoding helpers
dynBytes
,
_
=
abi
.
NewType
(
"bytes"
,
""
,
nil
)
address
,
_
=
abi
.
NewType
(
"address"
,
""
,
nil
)
uint256T
,
_
=
abi
.
NewType
(
"uint256"
,
""
,
nil
)
addressArgs
=
abi
.
Arguments
{
{
Type
:
address
},
}
bytesArgs
=
abi
.
Arguments
{
{
Type
:
dynBytes
},
}
twoUint256
=
abi
.
Arguments
{
{
Type
:
uint256T
},
{
Type
:
uint256T
},
}
oneUint256
=
abi
.
Arguments
{
{
Type
:
uint256T
},
}
)
// TestProcessSystemConfigUpdateLogEvent tests the parsing of an event and mutating the
// SystemConfig. The hook will build the ABI encoded data dynamically. All tests create
// a new SystemConfig and apply a log against it and then assert that the mutated system
// config is equal to the defined system config in the test.
func
TestProcessSystemConfigUpdateLogEvent
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
log
*
types
.
Log
config
eth
.
SystemConfig
hook
func
(
*
testing
.
T
,
*
types
.
Log
)
*
types
.
Log
err
bool
}{
{
// The log data is ignored by consensus and no modifications to the
// system config occur.
name
:
"SystemConfigUpdateUnsafeBlockSigner"
,
log
:
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
ConfigUpdateEventABIHash
,
ConfigUpdateEventVersion0
,
SystemConfigUpdateUnsafeBlockSigner
,
},
},
hook
:
func
(
t
*
testing
.
T
,
log
*
types
.
Log
)
*
types
.
Log
{
addr
:=
common
.
Address
{}
data
,
err
:=
addressArgs
.
Pack
(
&
addr
)
require
.
NoError
(
t
,
err
)
log
.
Data
=
data
return
log
},
config
:
eth
.
SystemConfig
{},
err
:
false
,
},
{
// The batcher address should be updated.
name
:
"SystemConfigUpdateBatcher"
,
log
:
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
ConfigUpdateEventABIHash
,
ConfigUpdateEventVersion0
,
SystemConfigUpdateBatcher
,
},
},
hook
:
func
(
t
*
testing
.
T
,
log
*
types
.
Log
)
*
types
.
Log
{
addr
:=
common
.
Address
{
19
:
0xaa
}
addrData
,
err
:=
addressArgs
.
Pack
(
&
addr
)
require
.
NoError
(
t
,
err
)
data
,
err
:=
bytesArgs
.
Pack
(
addrData
)
require
.
NoError
(
t
,
err
)
log
.
Data
=
data
return
log
},
config
:
eth
.
SystemConfig
{
BatcherAddr
:
common
.
Address
{
19
:
0xaa
},
},
err
:
false
,
},
{
// The overhead and the scalar should be updated.
name
:
"SystemConfigUpdateGasConfig"
,
log
:
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
ConfigUpdateEventABIHash
,
ConfigUpdateEventVersion0
,
SystemConfigUpdateGasConfig
,
},
},
hook
:
func
(
t
*
testing
.
T
,
log
*
types
.
Log
)
*
types
.
Log
{
overhead
:=
big
.
NewInt
(
0xff
)
scalar
:=
big
.
NewInt
(
0xaa
)
numberData
,
err
:=
twoUint256
.
Pack
(
overhead
,
scalar
)
require
.
NoError
(
t
,
err
)
data
,
err
:=
bytesArgs
.
Pack
(
numberData
)
require
.
NoError
(
t
,
err
)
log
.
Data
=
data
return
log
},
config
:
eth
.
SystemConfig
{
Overhead
:
eth
.
Bytes32
{
31
:
0xff
},
Scalar
:
eth
.
Bytes32
{
31
:
0xaa
},
},
err
:
false
,
},
{
// The gas limit should be updated.
name
:
"SystemConfigUpdateGasLimit"
,
log
:
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
ConfigUpdateEventABIHash
,
ConfigUpdateEventVersion0
,
SystemConfigUpdateGasLimit
,
},
},
hook
:
func
(
t
*
testing
.
T
,
log
*
types
.
Log
)
*
types
.
Log
{
gasLimit
:=
big
.
NewInt
(
0xbb
)
numberData
,
err
:=
oneUint256
.
Pack
(
gasLimit
)
require
.
NoError
(
t
,
err
)
data
,
err
:=
bytesArgs
.
Pack
(
numberData
)
require
.
NoError
(
t
,
err
)
log
.
Data
=
data
return
log
},
config
:
eth
.
SystemConfig
{
GasLimit
:
0xbb
,
},
err
:
false
,
},
{
name
:
"SystemConfigOneTopic"
,
log
:
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{
ConfigUpdateEventABIHash
,
},
},
hook
:
func
(
t
*
testing
.
T
,
log
*
types
.
Log
)
*
types
.
Log
{
return
log
},
config
:
eth
.
SystemConfig
{},
err
:
true
,
},
}
for
_
,
test
:=
range
tests
{
test
:=
test
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
config
:=
eth
.
SystemConfig
{}
err
:=
ProcessSystemConfigUpdateLogEvent
(
&
config
,
test
.
hook
(
t
,
test
.
log
))
if
test
.
err
{
require
.
Error
(
t
,
err
)
}
else
{
require
.
NoError
(
t
,
err
)
}
require
.
Equal
(
t
,
config
,
test
.
config
)
})
}
}
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