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
c7ec576c
Commit
c7ec576c
authored
Mar 08, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-chain-ops: migrated withdrawal gas limit tests
parent
7af32bda
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
9 deletions
+69
-9
migrate.go
op-chain-ops/crossdomain/migrate.go
+15
-9
migrate_test.go
op-chain-ops/crossdomain/migrate_test.go
+54
-0
No files found.
op-chain-ops/crossdomain/migrate.go
View file @
c7ec576c
...
...
@@ -83,6 +83,20 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com
return
nil
,
fmt
.
Errorf
(
"cannot abi encode relayMessage: %w"
,
err
)
}
gasLimit
:=
MigrateWithdrawalGasLimit
(
data
)
w
:=
NewWithdrawal
(
versionedNonce
,
&
predeploys
.
L2CrossDomainMessengerAddr
,
l1CrossDomainMessenger
,
value
,
new
(
big
.
Int
)
.
SetUint64
(
gasLimit
),
data
,
)
return
w
,
nil
}
func
MigrateWithdrawalGasLimit
(
data
[]
byte
)
uint64
{
// Compute the cost of the calldata
dataCost
:=
uint64
(
0
)
for
_
,
b
:=
range
data
{
...
...
@@ -101,13 +115,5 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com
gasLimit
=
25
_000_000
}
w
:=
NewWithdrawal
(
versionedNonce
,
&
predeploys
.
L2CrossDomainMessengerAddr
,
l1CrossDomainMessenger
,
value
,
new
(
big
.
Int
)
.
SetUint64
(
gasLimit
),
data
,
)
return
w
,
nil
return
gasLimit
}
op-chain-ops/crossdomain/migrate_test.go
View file @
c7ec576c
...
...
@@ -2,6 +2,7 @@ package crossdomain_test
import
(
"fmt"
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
...
...
@@ -11,6 +12,8 @@ import (
"github.com/stretchr/testify/require"
)
var
big25Million
=
big
.
NewInt
(
25
_000_000
)
func
TestMigrateWithdrawal
(
t
*
testing
.
T
)
{
withdrawals
:=
make
([]
*
crossdomain
.
LegacyWithdrawal
,
0
)
...
...
@@ -31,6 +34,57 @@ func TestMigrateWithdrawal(t *testing.T) {
require
.
Equal
(
t
,
legacy
.
XDomainNonce
.
Uint64
(),
withdrawal
.
Nonce
.
Uint64
())
require
.
Equal
(
t
,
*
withdrawal
.
Sender
,
predeploys
.
L2CrossDomainMessengerAddr
)
require
.
Equal
(
t
,
*
withdrawal
.
Target
,
l1CrossDomainMessenger
)
// Always equal to or lower than the cap
require
.
True
(
t
,
withdrawal
.
GasLimit
.
Cmp
(
big25Million
)
<=
0
)
})
}
}
// TestMigrateWithdrawalGasLimitMax computes the migrated withdrawal
// gas limit with a very large amount of data. The max value for a migrated
// withdrawal's gas limit is 25 million.
func
TestMigrateWithdrawalGasLimitMax
(
t
*
testing
.
T
)
{
size
:=
300
_000_000
/
16
data
:=
make
([]
byte
,
size
)
for
_
,
i
:=
range
data
{
data
[
i
]
=
0xff
}
result
:=
crossdomain
.
MigrateWithdrawalGasLimit
(
data
)
require
.
Equal
(
t
,
result
,
big25Million
.
Uint64
())
}
// TestMigrateWithdrawalGasLimit tests an assortment of zero and non zero
// bytes when computing the migrated withdrawal's gas limit.
func
TestMigrateWithdrawalGasLimit
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
[]
byte
output
uint64
}{
{
input
:
[]
byte
{},
output
:
200
_000
,
},
{
input
:
[]
byte
{
0xff
},
output
:
200
_000
+
16
,
},
{
input
:
[]
byte
{
0xff
,
0x00
},
output
:
200
_000
+
16
+
4
,
},
{
input
:
[]
byte
{
0x00
},
output
:
200
_000
+
4
,
},
{
input
:
[]
byte
{
0x00
,
0x00
,
0x00
},
output
:
200
_000
+
4
+
4
+
4
,
},
}
for
_
,
test
:=
range
tests
{
result
:=
crossdomain
.
MigrateWithdrawalGasLimit
(
test
.
input
)
require
.
Equal
(
t
,
test
.
output
,
result
)
}
}
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