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
15626325
Commit
15626325
authored
Jul 18, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up bridge e2e tests by pre-emptively conducting a deposit & withdrawal on setup
parent
4cf0a241
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
31 deletions
+98
-31
bridge_e2e_test.go
indexer/e2e_test/bridge_e2e_test.go
+98
-31
No files found.
indexer/e2e_test/bridge_e2e_test.go
View file @
15626325
...
@@ -7,14 +7,18 @@ import (
...
@@ -7,14 +7,18 @@ import (
"time"
"time"
"github.com/ethereum-optimism/optimism/indexer/processor"
"github.com/ethereum-optimism/optimism/indexer/processor"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
op_e2e
"github.com/ethereum-optimism/optimism/op-e2e"
e2eutils
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
e2eutils
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -23,48 +27,59 @@ func TestE2EBridge(t *testing.T) {
...
@@ -23,48 +27,59 @@ func TestE2EBridge(t *testing.T) {
l1Client
:=
testSuite
.
OpSys
.
Clients
[
"l1"
]
l1Client
:=
testSuite
.
OpSys
.
Clients
[
"l1"
]
l2Client
:=
testSuite
.
OpSys
.
Clients
[
"sequencer"
]
l2Client
:=
testSuite
.
OpSys
.
Clients
[
"sequencer"
]
aliceAddr
:=
testSuite
.
OpCfg
.
Secrets
.
Addresses
()
.
Alice
l1StandardBridge
,
err
:=
bindings
.
NewL1StandardBridge
(
predeploys
.
DevL1StandardBridgeAddr
,
l1Client
)
l1StandardBridge
,
err
:=
bindings
.
NewL1StandardBridge
(
predeploys
.
DevL1StandardBridgeAddr
,
l1Client
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
_
,
err
=
bindings
.
NewL2StandardBridge
(
predeploys
.
L2StandardBridgeAddr
,
l2Client
)
l2StandardBridge
,
err
:=
bindings
.
NewL2StandardBridge
(
predeploys
.
L2StandardBridgeAddr
,
l2Client
)
require
.
NoError
(
t
,
err
)
// pre-emptively conduct a deposit & withdrawal to speed up the test
setupCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Second
)
defer
cancel
()
aliceAddr
:=
testSuite
.
OpCfg
.
Secrets
.
Addresses
()
.
Alice
l1Opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testSuite
.
OpCfg
.
Secrets
.
Alice
,
testSuite
.
OpCfg
.
L1ChainIDBig
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
l2Opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testSuite
.
OpCfg
.
Secrets
.
Alice
,
testSuite
.
OpCfg
.
L2ChainIDBig
())
require
.
NoError
(
t
,
err
)
l1Opts
.
Value
=
big
.
NewInt
(
params
.
Ether
)
l2Opts
.
Value
=
big
.
NewInt
(
params
.
Ether
)
_
,
err
=
bindings
.
NewOptimismPortal
(
predeploys
.
DevOptimismPortalAddr
,
l1Client
)
depositTx
,
err
:=
l1StandardBridge
.
DepositETH
(
l1Opts
,
200
_000
,
[]
byte
{
byte
(
1
)})
require
.
NoError
(
t
,
err
)
withdrawTx
,
err
:=
l2StandardBridge
.
Withdraw
(
l2Opts
,
processor
.
EthAddress
,
big
.
NewInt
(
params
.
Ether
),
200
_000
,
[]
byte
{
byte
(
1
)})
require
.
NoError
(
t
,
err
)
depositReceipt
,
err
:=
e2eutils
.
WaitReceiptOK
(
setupCtx
,
l1Client
,
depositTx
.
Hash
())
require
.
NoError
(
t
,
err
)
withdrawalReceipt
,
err
:=
e2eutils
.
WaitReceiptOK
(
setupCtx
,
l2Client
,
withdrawTx
.
Hash
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
t
.
Run
(
"indexes ETH deposits"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"indexes ETH deposits"
,
func
(
t
*
testing
.
T
)
{
testCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
testCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
// pause L2Processor so that we can test for finalization seperately
// Pause the L2Processor so that we can test for finalization seperately. A pause is
// required since deposit inclusion is apart of the L2 block derivation process
testSuite
.
Indexer
.
L2Processor
.
PauseForTest
()
testSuite
.
Indexer
.
L2Processor
.
PauseForTest
()
l1Opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testSuite
.
OpCfg
.
Secrets
.
Alice
,
testSuite
.
OpCfg
.
L1ChainIDBig
())
require
.
NoError
(
t
,
err
)
// Deposit 1 ETH (add some extra data for fun)
l1Opts
.
Value
=
big
.
NewInt
(
params
.
Ether
)
tx
,
err
:=
l1StandardBridge
.
DepositETH
(
l1Opts
,
200
_000
,
[]
byte
{
byte
(
1
)})
require
.
NoError
(
t
,
err
)
// (1) Test Deposit Initiation
// (1) Test Deposit Initiation
// wait for deposit to be included & processor catchup
// wait for processor catchup
depositReceipt
,
err
:=
e2eutils
.
WaitReceiptOK
(
testCtx
,
l1Client
,
tx
.
Hash
())
require
.
NoError
(
t
,
err
)
l1Height
,
err
:=
l1Client
.
BlockNumber
(
testCtx
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
e2eutils
.
WaitFor
(
testCtx
,
500
*
time
.
Millisecond
,
func
()
(
bool
,
error
)
{
require
.
NoError
(
t
,
e2eutils
.
WaitFor
(
testCtx
,
500
*
time
.
Millisecond
,
func
()
(
bool
,
error
)
{
l1Header
:=
testSuite
.
Indexer
.
L1Processor
.
LatestProcessedHeader
()
l1Header
:=
testSuite
.
Indexer
.
L1Processor
.
LatestProcessedHeader
()
return
l1Header
!=
nil
&&
l1Header
.
Number
.
Uint64
()
>=
l1Height
,
nil
return
l1Header
!=
nil
&&
l1Header
.
Number
.
Uint64
()
>=
depositReceipt
.
BlockNumber
.
Uint64
()
,
nil
}))
}))
aliceDeposits
,
err
:=
testSuite
.
DB
.
Bridge
.
DepositsByAddress
(
aliceAddr
)
aliceDeposits
,
err
:=
testSuite
.
DB
.
Bridge
.
DepositsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
aliceDeposits
,
1
)
require
.
Len
(
t
,
aliceDeposits
,
1
)
require
.
Equal
(
t
,
t
x
.
Hash
(),
aliceDeposits
[
0
]
.
L1TransactionHash
)
require
.
Equal
(
t
,
depositT
x
.
Hash
(),
aliceDeposits
[
0
]
.
L1TransactionHash
)
require
.
Empty
(
t
,
aliceDeposits
[
0
]
.
FinalizedL2TransactionHash
)
require
.
Empty
(
t
,
aliceDeposits
[
0
]
.
FinalizedL2TransactionHash
)
deposit
:=
aliceDeposits
[
0
]
.
Deposit
deposit
:=
aliceDeposits
[
0
]
.
Deposit
...
@@ -77,24 +92,21 @@ func TestE2EBridge(t *testing.T) {
...
@@ -77,24 +92,21 @@ func TestE2EBridge(t *testing.T) {
require
.
Equal
(
t
,
byte
(
1
),
deposit
.
Tx
.
Data
[
0
])
require
.
Equal
(
t
,
byte
(
1
),
deposit
.
Tx
.
Data
[
0
])
// (2) Test Deposit Finalization
// (2) Test Deposit Finalization
testSuite
.
Indexer
.
L2Processor
.
ResumeForTest
()
testSuite
.
Indexer
.
L2Processor
.
ResumeForTest
()
// finalization hash can be deterministically derived from TransactionDeposited log
// finalization hash can be deterministically derived from TransactionDeposited log
var
t
xHash
common
.
Hash
var
depositT
xHash
common
.
Hash
for
_
,
log
:=
range
depositReceipt
.
Logs
{
for
_
,
log
:=
range
depositReceipt
.
Logs
{
if
len
(
log
.
Topics
)
==
0
||
log
.
Topics
[
0
]
!=
derive
.
DepositEventABIHash
{
if
log
.
Topics
[
0
]
==
derive
.
DepositEventABIHash
{
continue
deposit
,
err
:=
derive
.
UnmarshalDepositLogEvent
(
log
)
require
.
NoError
(
t
,
err
)
depositTxHash
=
types
.
NewTx
(
deposit
)
.
Hash
()
break
}
}
depLog
,
err
:=
derive
.
UnmarshalDepositLogEvent
(
log
)
require
.
NoError
(
t
,
err
)
tx
:=
types
.
NewTx
(
depLog
)
txHash
=
tx
.
Hash
()
}
}
// wait for the l2 processor to catch this deposit in the derivation process
// wait for the l2 processor to catch this deposit in the derivation process
_
,
err
=
e2eutils
.
WaitReceiptOK
(
testCtx
,
l2Client
,
t
xHash
)
_
,
err
=
e2eutils
.
WaitReceiptOK
(
testCtx
,
l2Client
,
depositT
xHash
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
l2Height
,
err
:=
l2Client
.
BlockNumber
(
testCtx
)
l2Height
,
err
:=
l2Client
.
BlockNumber
(
testCtx
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
...
@@ -105,9 +117,64 @@ func TestE2EBridge(t *testing.T) {
...
@@ -105,9 +117,64 @@ func TestE2EBridge(t *testing.T) {
aliceDeposits
,
err
=
testSuite
.
DB
.
Bridge
.
DepositsByAddress
(
aliceAddr
)
aliceDeposits
,
err
=
testSuite
.
DB
.
Bridge
.
DepositsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
t
xHash
,
aliceDeposits
[
0
]
.
FinalizedL2TransactionHash
)
require
.
Equal
(
t
,
depositT
xHash
,
aliceDeposits
[
0
]
.
FinalizedL2TransactionHash
)
require
.
NotNil
(
t
,
aliceDeposits
[
0
]
.
Deposit
.
FinalizedL2EventGUID
)
require
.
NotNil
(
t
,
aliceDeposits
[
0
]
.
Deposit
.
FinalizedL2EventGUID
)
})
})
t
.
Run
(
"indexes ETH withdrawals"
,
func
(
t
*
testing
.
T
)
{})
t
.
Run
(
"indexes ETH withdrawals"
,
func
(
t
*
testing
.
T
)
{
testCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Minute
)
defer
cancel
()
// (1) Test Withdrawal Initiation
// wait for processor catchup
require
.
NoError
(
t
,
e2eutils
.
WaitFor
(
testCtx
,
500
*
time
.
Millisecond
,
func
()
(
bool
,
error
)
{
l2Header
:=
testSuite
.
Indexer
.
L2Processor
.
LatestProcessedHeader
()
return
l2Header
!=
nil
&&
l2Header
.
Number
.
Uint64
()
>=
withdrawalReceipt
.
BlockNumber
.
Uint64
(),
nil
}))
aliceWithdrawals
,
err
:=
testSuite
.
DB
.
Bridge
.
WithdrawalsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
aliceWithdrawals
,
1
)
require
.
Equal
(
t
,
withdrawTx
.
Hash
(),
aliceWithdrawals
[
0
]
.
L2TransactionHash
)
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
withdrawal
:=
aliceWithdrawals
[
0
]
.
Withdrawal
require
.
Nil
(
t
,
withdrawal
.
ProvenL1EventGUID
)
require
.
Nil
(
t
,
withdrawal
.
FinalizedL1EventGUID
)
require
.
Equal
(
t
,
processor
.
EthAddress
,
withdrawal
.
TokenPair
.
L1TokenAddress
)
require
.
Equal
(
t
,
processor
.
EthAddress
,
withdrawal
.
TokenPair
.
L2TokenAddress
)
require
.
Equal
(
t
,
big
.
NewInt
(
params
.
Ether
),
withdrawal
.
Tx
.
Amount
.
Int
)
require
.
Equal
(
t
,
aliceAddr
,
withdrawal
.
Tx
.
FromAddress
)
require
.
Equal
(
t
,
aliceAddr
,
withdrawal
.
Tx
.
ToAddress
)
require
.
Equal
(
t
,
byte
(
1
),
withdrawal
.
Tx
.
Data
[
0
])
// (2) Test Withdrawal Proven
// prove & wait for processor catchup
withdrawParams
,
proveReceipt
:=
op_e2e
.
ProveWithdrawal
(
t
,
*
testSuite
.
OpCfg
,
l1Client
,
testSuite
.
OpSys
.
Nodes
[
"sequencer"
],
testSuite
.
OpCfg
.
Secrets
.
Alice
,
withdrawalReceipt
)
require
.
NoError
(
t
,
e2eutils
.
WaitFor
(
testCtx
,
500
*
time
.
Millisecond
,
func
()
(
bool
,
error
)
{
l1Header
:=
testSuite
.
Indexer
.
L1Processor
.
LatestProcessedHeader
()
return
l1Header
!=
nil
&&
l1Header
.
Number
.
Uint64
()
>=
proveReceipt
.
BlockNumber
.
Uint64
(),
nil
}))
aliceWithdrawals
,
err
=
testSuite
.
DB
.
Bridge
.
WithdrawalsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
Empty
(
t
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
// (3) Test Withdrawal Finalization
// finalize & wait for processor catchup
finalizeReceipt
:=
op_e2e
.
FinalizeWithdrawal
(
t
,
*
testSuite
.
OpCfg
,
l1Client
,
testSuite
.
OpCfg
.
Secrets
.
Alice
,
withdrawalReceipt
,
withdrawParams
)
require
.
NoError
(
t
,
e2eutils
.
WaitFor
(
testCtx
,
500
*
time
.
Millisecond
,
func
()
(
bool
,
error
)
{
l1Header
:=
testSuite
.
Indexer
.
L1Processor
.
LatestProcessedHeader
()
return
l1Header
!=
nil
&&
l1Header
.
Number
.
Uint64
()
>=
finalizeReceipt
.
BlockNumber
.
Uint64
(),
nil
}))
aliceWithdrawals
,
err
=
testSuite
.
DB
.
Bridge
.
WithdrawalsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
})
}
}
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