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
c2f0632a
Unverified
Commit
c2f0632a
authored
Apr 19, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-e2e: Add helper method to send L2 transactions
parent
52698092
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
163 deletions
+124
-163
system_test.go
op-e2e/system_test.go
+49
-161
tx_helper.go
op-e2e/tx_helper.go
+75
-2
No files found.
op-e2e/system_test.go
View file @
c2f0632a
This diff is collapsed.
Click to expand it.
op-e2e/tx_helper.go
View file @
c2f0632a
package
op_e2e
import
(
"context"
"crypto/ecdsa"
"math/big"
"testing"
"time"
...
...
@@ -15,6 +17,10 @@ import (
"github.com/stretchr/testify/require"
)
// SendDepositTx creates and sends a deposit transaction.
// The L1 transaction, including sender, is configured by the l1Opts param.
// The L2 transaction options can be configured by modifying the DepositTxOps value supplied to applyL2Opts
// Will verify that the transaction is included with the expected status on L1 and L2
func
SendDepositTx
(
t
*
testing
.
T
,
cfg
SystemConfig
,
l1Client
*
ethclient
.
Client
,
l2Client
*
ethclient
.
Client
,
l1Opts
*
bind
.
TransactOpts
,
applyL2Opts
DepositTxOptsFn
)
{
l2Opts
:=
defaultDepositTxOpts
(
l1Opts
)
applyL2Opts
(
l2Opts
)
...
...
@@ -27,14 +33,14 @@ func SendDepositTx(t *testing.T, cfg SystemConfig, l1Client *ethclient.Client, l
require
.
Nil
(
t
,
err
,
"with deposit tx"
)
// Wait for transaction on L1
receipt
,
err
:=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
receipt
,
err
:=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
10
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
Nil
(
t
,
err
,
"Waiting for deposit tx on L1"
)
// Wait for transaction to be included on L2
reconstructedDep
,
err
:=
derive
.
UnmarshalDepositLogEvent
(
receipt
.
Logs
[
0
])
require
.
NoError
(
t
,
err
,
"Could not reconstruct L2 Deposit"
)
tx
=
types
.
NewTx
(
reconstructedDep
)
receipt
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l2Client
,
6
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1
BlockTime
)
*
time
.
Second
)
receipt
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l2Client
,
10
*
time
.
Duration
(
cfg
.
DeployConfig
.
L2
BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
l2Opts
.
ExpectedStatus
,
receipt
.
Status
)
}
...
...
@@ -60,3 +66,70 @@ func defaultDepositTxOpts(opts *bind.TransactOpts) *DepositTxOpts {
ExpectedStatus
:
types
.
ReceiptStatusSuccessful
,
}
}
// SendL2Tx creates and sends a transaction.
// The supplied privKey is used to specify the account to send from and the transaction is sent to the supplied l2Client
// Transaction options and expected status can be configured in the applyTxOpts function by modifying the supplied TxOpts
// Will verify that the transaction is included with the expected status on l2Client and any clients added to TxOpts.VerifyClients
func
SendL2Tx
(
t
*
testing
.
T
,
cfg
SystemConfig
,
l2Client
*
ethclient
.
Client
,
privKey
*
ecdsa
.
PrivateKey
,
applyTxOpts
TxOptsFn
)
*
types
.
Receipt
{
opts
:=
defaultTxOpts
()
applyTxOpts
(
opts
)
tx
:=
types
.
MustSignNewTx
(
privKey
,
types
.
LatestSignerForChainID
(
cfg
.
L2ChainIDBig
()),
&
types
.
DynamicFeeTx
{
ChainID
:
cfg
.
L2ChainIDBig
(),
Nonce
:
opts
.
Nonce
,
// Already have deposit
To
:
opts
.
ToAddr
,
Value
:
opts
.
Value
,
GasTipCap
:
opts
.
GasTipCap
,
GasFeeCap
:
opts
.
GasFeeCap
,
Gas
:
opts
.
Gas
,
})
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
30
*
time
.
Second
)
defer
cancel
()
err
:=
l2Client
.
SendTransaction
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
,
"Sending L2 tx"
)
receipt
,
err
:=
waitForTransaction
(
tx
.
Hash
(),
l2Client
,
10
*
time
.
Duration
(
cfg
.
DeployConfig
.
L2BlockTime
)
*
time
.
Second
)
require
.
Nil
(
t
,
err
,
"Waiting for L2 tx"
)
require
.
Equal
(
t
,
opts
.
ExpectedStatus
,
receipt
.
Status
,
"TX should have expected status"
)
for
i
,
client
:=
range
opts
.
VerifyClients
{
t
.
Logf
(
"Waiting for tx %v on verification client %d"
,
tx
.
Hash
(),
i
)
receiptVerif
,
err
:=
waitForTransaction
(
tx
.
Hash
(),
client
,
10
*
time
.
Duration
(
cfg
.
DeployConfig
.
L2BlockTime
)
*
time
.
Second
)
require
.
Nilf
(
t
,
err
,
"Waiting for L2 tx on verification client %d"
,
i
)
require
.
Equalf
(
t
,
receipt
,
receiptVerif
,
"Receipts should be the same on sequencer and verification client %d"
,
i
)
}
return
receipt
}
type
TxOptsFn
func
(
opts
*
TxOpts
)
type
TxOpts
struct
{
ToAddr
*
common
.
Address
Nonce
uint64
Value
*
big
.
Int
Gas
uint64
GasTipCap
*
big
.
Int
GasFeeCap
*
big
.
Int
Data
[]
byte
ExpectedStatus
uint64
VerifyClients
[]
*
ethclient
.
Client
}
// VerifyOnClients adds additional l2 clients that should sync the block the tx is included in
// Checks that the receipt received from these clients is equal to the receipt received from the sequencer
func
(
o
*
TxOpts
)
VerifyOnClients
(
clients
...*
ethclient
.
Client
)
{
o
.
VerifyClients
=
append
(
o
.
VerifyClients
,
clients
...
)
}
func
defaultTxOpts
()
*
TxOpts
{
return
&
TxOpts
{
ToAddr
:
nil
,
Nonce
:
0
,
Value
:
common
.
Big0
,
GasTipCap
:
big
.
NewInt
(
10
),
GasFeeCap
:
big
.
NewInt
(
200
),
Gas
:
21
_000
,
Data
:
nil
,
ExpectedStatus
:
types
.
ReceiptStatusSuccessful
,
}
}
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