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
e0948eb9
Unverified
Commit
e0948eb9
authored
Mar 17, 2023
by
Mark Tyneway
Committed by
GitHub
Mar 17, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5104 from ethereum-optimism/feat/bridge-e2e-test
op-e2e: bridge erc20 test
parents
bf4708de
78c31ae0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
0 deletions
+120
-0
bridge_test.go
op-e2e/bridge_test.go
+120
-0
No files found.
op-e2e/bridge_test.go
0 → 100644
View file @
e0948eb9
package
op_e2e
import
(
"math"
"math/big"
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)
// TestERC20BridgeDeposits tests the the L1StandardBridge bridge ERC20
// functionality.
func
TestERC20BridgeDeposits
(
t
*
testing
.
T
)
{
parallel
(
t
)
if
!
verboseGethNodes
{
log
.
Root
()
.
SetHandler
(
log
.
DiscardHandler
())
}
cfg
:=
DefaultSystemConfig
(
t
)
sys
,
err
:=
cfg
.
Start
()
require
.
Nil
(
t
,
err
,
"Error starting up system"
)
defer
sys
.
Close
()
log
:=
testlog
.
Logger
(
t
,
log
.
LvlInfo
)
log
.
Info
(
"genesis"
,
"l2"
,
sys
.
RollupConfig
.
Genesis
.
L2
,
"l1"
,
sys
.
RollupConfig
.
Genesis
.
L1
,
"l2_time"
,
sys
.
RollupConfig
.
Genesis
.
L2Time
)
l1Client
:=
sys
.
Clients
[
"l1"
]
l2Client
:=
sys
.
Clients
[
"sequencer"
]
opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
sys
.
cfg
.
Secrets
.
Alice
,
cfg
.
L1ChainIDBig
())
require
.
Nil
(
t
,
err
)
// Deploy WETH9
weth9Address
,
tx
,
WETH9
,
err
:=
bindings
.
DeployWETH9
(
opts
,
l1Client
)
require
.
NoError
(
t
,
err
)
_
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
,
"Waiting for deposit tx on L1"
)
// Get some WETH
opts
.
Value
=
big
.
NewInt
(
params
.
Ether
)
tx
,
err
=
WETH9
.
Fallback
(
opts
,
[]
byte
{})
require
.
NoError
(
t
,
err
)
_
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
opts
.
Value
=
nil
wethBalance
,
err
:=
WETH9
.
BalanceOf
(
&
bind
.
CallOpts
{},
opts
.
From
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
big
.
NewInt
(
params
.
Ether
),
wethBalance
)
// Deploy L2 WETH9
l2Opts
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
sys
.
cfg
.
Secrets
.
Alice
,
cfg
.
L2ChainIDBig
())
require
.
NoError
(
t
,
err
)
optimismMintableTokenFactory
,
err
:=
bindings
.
NewOptimismMintableERC20Factory
(
predeploys
.
OptimismMintableERC20FactoryAddr
,
l2Client
)
require
.
NoError
(
t
,
err
)
tx
,
err
=
optimismMintableTokenFactory
.
CreateOptimismMintableERC20
(
l2Opts
,
weth9Address
,
"L2-WETH"
,
"L2-WETH"
)
require
.
NoError
(
t
,
err
)
_
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l2Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L2BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
// Get the deployment event to have access to the L2 WETH9 address
it
,
err
:=
optimismMintableTokenFactory
.
FilterOptimismMintableERC20Created
(
&
bind
.
FilterOpts
{
Start
:
0
},
nil
,
nil
)
require
.
NoError
(
t
,
err
)
var
event
*
bindings
.
OptimismMintableERC20FactoryOptimismMintableERC20Created
for
it
.
Next
()
{
event
=
it
.
Event
}
require
.
NotNil
(
t
,
event
)
// Approve WETH9 with the bridge
tx
,
err
=
WETH9
.
Approve
(
opts
,
predeploys
.
DevL1StandardBridgeAddr
,
new
(
big
.
Int
)
.
SetUint64
(
math
.
MaxUint64
))
require
.
NoError
(
t
,
err
)
_
,
err
=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
// Bridge the WETH9
l1StandardBridge
,
err
:=
bindings
.
NewL1StandardBridge
(
predeploys
.
DevL1StandardBridgeAddr
,
l1Client
)
require
.
NoError
(
t
,
err
)
tx
,
err
=
l1StandardBridge
.
BridgeERC20
(
opts
,
weth9Address
,
event
.
LocalToken
,
big
.
NewInt
(
100
),
100000
,
[]
byte
{})
require
.
NoError
(
t
,
err
)
depositReceipt
,
err
:=
waitForTransaction
(
tx
.
Hash
(),
l1Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L1BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
t
.
Log
(
"Deposit through L1StandardBridge"
,
"gas used"
,
depositReceipt
.
GasUsed
)
// compute the deposit transaction hash + poll for it
portal
,
err
:=
bindings
.
NewOptimismPortal
(
predeploys
.
DevOptimismPortalAddr
,
l1Client
)
require
.
NoError
(
t
,
err
)
depIt
,
err
:=
portal
.
FilterTransactionDeposited
(
&
bind
.
FilterOpts
{
Start
:
0
},
nil
,
nil
,
nil
)
require
.
NoError
(
t
,
err
)
var
depositEvent
*
bindings
.
OptimismPortalTransactionDeposited
for
depIt
.
Next
()
{
depositEvent
=
depIt
.
Event
}
require
.
NotNil
(
t
,
depositEvent
)
depositTx
,
err
:=
derive
.
UnmarshalDepositLogEvent
(
&
depositEvent
.
Raw
)
require
.
NoError
(
t
,
err
)
_
,
err
=
waitForTransaction
(
types
.
NewTx
(
depositTx
)
.
Hash
(),
l2Client
,
3
*
time
.
Duration
(
cfg
.
DeployConfig
.
L2BlockTime
)
*
time
.
Second
)
require
.
NoError
(
t
,
err
)
// Ensure that the deposit went through
optimismMintableToken
,
err
:=
bindings
.
NewOptimismMintableERC20
(
event
.
LocalToken
,
l2Client
)
require
.
NoError
(
t
,
err
)
// Should have balance on L2
l2Balance
,
err
:=
optimismMintableToken
.
BalanceOf
(
&
bind
.
CallOpts
{},
opts
.
From
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
l2Balance
,
big
.
NewInt
(
100
))
}
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