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
43c4158f
Commit
43c4158f
authored
Mar 08, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sdk: add tests for min gas util
parent
c7ec576c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
8 deletions
+46
-8
cross-chain-messenger.ts
packages/sdk/src/cross-chain-messenger.ts
+2
-7
message-utils.ts
packages/sdk/src/utils/message-utils.ts
+15
-1
message-utils.spec.ts
packages/sdk/test/utils/message-utils.spec.ts
+29
-0
No files found.
packages/sdk/src/cross-chain-messenger.ts
View file @
43c4158f
...
@@ -26,7 +26,6 @@ import {
...
@@ -26,7 +26,6 @@ import {
BedrockCrossChainMessageProof
,
BedrockCrossChainMessageProof
,
decodeVersionedNonce
,
decodeVersionedNonce
,
encodeVersionedNonce
,
encodeVersionedNonce
,
calldataCost
,
}
from
'
@eth-optimism/core-utils
'
}
from
'
@eth-optimism/core-utils
'
import
{
getContractInterface
,
predeploys
}
from
'
@eth-optimism/contracts
'
import
{
getContractInterface
,
predeploys
}
from
'
@eth-optimism/contracts
'
import
*
as
rlp
from
'
rlp
'
import
*
as
rlp
from
'
rlp
'
...
@@ -66,6 +65,7 @@ import {
...
@@ -66,6 +65,7 @@ import {
makeMerkleTreeProof
,
makeMerkleTreeProof
,
makeStateTrieProof
,
makeStateTrieProof
,
hashLowLevelMessage
,
hashLowLevelMessage
,
migratedWithdrawalGasLimit
,
DEPOSIT_CONFIRMATION_BLOCKS
,
DEPOSIT_CONFIRMATION_BLOCKS
,
CHAIN_BLOCK_TIMES
,
CHAIN_BLOCK_TIMES
,
}
from
'
./utils
'
}
from
'
./utils
'
...
@@ -351,12 +351,7 @@ export class CrossChainMessenger {
...
@@ -351,12 +351,7 @@ export class CrossChainMessenger {
}
}
}
}
// Compute the gas limit and cap at 25 million
const
minGasLimit
=
migratedWithdrawalGasLimit
(
resolved
.
message
)
const
dataCost
=
calldataCost
(
resolved
.
message
)
let
minGasLimit
=
dataCost
.
add
(
200
_000
)
if
(
minGasLimit
.
gt
(
25
_000_000
))
{
minGasLimit
=
BigNumber
.
from
(
25
_000_000
)
}
return
{
return
{
...
resolved
,
...
resolved
,
...
...
packages/sdk/src/utils/message-utils.ts
View file @
43c4158f
import
{
hashWithdrawal
}
from
'
@eth-optimism/core-utils
'
import
{
hashWithdrawal
,
calldataCost
}
from
'
@eth-optimism/core-utils
'
import
{
BigNumber
}
from
'
ethers
'
import
{
LowLevelMessage
}
from
'
../interfaces
'
import
{
LowLevelMessage
}
from
'
../interfaces
'
...
@@ -18,3 +19,16 @@ export const hashLowLevelMessage = (message: LowLevelMessage): string => {
...
@@ -18,3 +19,16 @@ export const hashLowLevelMessage = (message: LowLevelMessage): string => {
message
.
message
message
.
message
)
)
}
}
/**
* Compute the min gas limit for a migrated withdrawal.
*/
export
const
migratedWithdrawalGasLimit
=
(
data
:
string
):
BigNumber
=>
{
// Compute the gas limit and cap at 25 million
const
dataCost
=
calldataCost
(
data
)
let
minGasLimit
=
dataCost
.
add
(
200
_000
)
if
(
minGasLimit
.
gt
(
25
_000_000
))
{
minGasLimit
=
BigNumber
.
from
(
25
_000_000
)
}
return
minGasLimit
}
packages/sdk/test/utils/message-utils.spec.ts
0 → 100644
View file @
43c4158f
import
{
BigNumber
}
from
'
ethers
'
import
{
expect
}
from
'
../setup
'
import
{
migratedWithdrawalGasLimit
}
from
'
../../src/utils/message-utils
'
describe
(
'
Message Utils
'
,
()
=>
{
describe
(
'
migratedWithdrawalGasLimit
'
,
()
=>
{
it
(
'
should have a max of 25 million
'
,
()
=>
{
const
data
=
'
0x
'
+
'
ff
'
.
repeat
(
15
_000_000
)
const
result
=
migratedWithdrawalGasLimit
(
data
)
expect
(
result
).
to
.
eq
(
BigNumber
.
from
(
25
_000_000
))
})
it
(
'
should work for mixes of zeros and ones
'
,
()
=>
{
const
tests
=
[
{
input
:
'
0x
'
,
result
:
BigNumber
.
from
(
200
_000
)
},
{
input
:
'
0xff
'
,
result
:
BigNumber
.
from
(
200
_000
+
16
)
},
{
input
:
'
0xff00
'
,
result
:
BigNumber
.
from
(
200
_000
+
16
+
4
)
},
{
input
:
'
0x00
'
,
result
:
BigNumber
.
from
(
200
_000
+
4
)
},
{
input
:
'
0x000000
'
,
result
:
BigNumber
.
from
(
200
_000
+
4
+
4
+
4
)
},
]
for
(
const
test
of
tests
)
{
const
result
=
migratedWithdrawalGasLimit
(
test
.
input
)
expect
(
result
).
to
.
eq
(
test
.
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