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
b6d252fe
Unverified
Commit
b6d252fe
authored
Apr 08, 2021
by
Georgios Konstantopoulos
Committed by
GitHub
Apr 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add native eth test (#41)
parent
4f42a808
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
202 additions
and
0 deletions
+202
-0
native-eth.spec.ts
integration-tests/test/native-eth.spec.ts
+202
-0
No files found.
integration-tests/test/native-eth.spec.ts
0 → 100644
View file @
b6d252fe
import
{
expect
}
from
'
chai
'
import
{
BigNumber
,
Contract
,
Wallet
,
constants
,
providers
}
from
'
ethers
'
import
{
getContractInterface
,
getContractFactory
,
}
from
'
@eth-optimism/contracts
'
import
{
Watcher
}
from
'
@eth-optimism/core-utils
'
import
{
Direction
,
initWatcher
,
waitForXDomainTransaction
,
}
from
'
./shared/watcher-utils
'
import
{
l1Provider
,
l2Provider
,
l1Wallet
,
l2Wallet
,
getGateway
,
getAddressManager
,
getOvmEth
,
PROXY_SEQUENCER_ENTRYPOINT_ADDRESS
,
}
from
'
./shared/utils
'
describe
(
'
Native ETH Integration Tests
'
,
async
()
=>
{
let
OVM_L1ETHGateway
:
Contract
let
OVM_ETH
:
Contract
let
AddressManager
:
Contract
let
watcher
:
Watcher
const
BOB_PRIV_KEY
=
'
0x1234123412341234123412341234123412341234123412341234123412341234
'
const
l1bob
=
new
Wallet
(
BOB_PRIV_KEY
,
l1Provider
)
const
l2bob
=
new
Wallet
(
BOB_PRIV_KEY
,
l2Provider
)
const
getBalances
=
async
()
=>
{
const
l1UserBalance
=
await
l1Wallet
.
getBalance
()
const
l2UserBalance
=
await
l2Wallet
.
getBalance
()
const
l1BobBalance
=
await
l1bob
.
getBalance
()
const
l2BobBalance
=
await
l2bob
.
getBalance
()
const
sequencerBalance
=
await
OVM_ETH
.
balanceOf
(
PROXY_SEQUENCER_ENTRYPOINT_ADDRESS
)
const
l1GatewayBalance
=
await
l1Provider
.
getBalance
(
OVM_L1ETHGateway
.
address
)
return
{
l1UserBalance
,
l2UserBalance
,
l1BobBalance
,
l2BobBalance
,
l1GatewayBalance
,
sequencerBalance
,
}
}
before
(
async
()
=>
{
AddressManager
=
getAddressManager
(
l1Wallet
)
OVM_L1ETHGateway
=
await
getGateway
(
l1Wallet
,
AddressManager
)
OVM_ETH
=
getOvmEth
(
l2Wallet
)
watcher
=
await
initWatcher
(
l1Provider
,
l2Provider
,
AddressManager
)
})
it
(
'
deposit
'
,
async
()
=>
{
const
depositAmount
=
10
const
preBalances
=
await
getBalances
()
const
{
tx
,
receipt
}
=
await
waitForXDomainTransaction
(
watcher
,
OVM_L1ETHGateway
.
deposit
({
value
:
depositAmount
,
}),
Direction
.
L1ToL2
)
const
l1FeePaid
=
receipt
.
gasUsed
.
mul
(
tx
.
gasPrice
)
const
postBalances
=
await
getBalances
()
expect
(
postBalances
.
l1GatewayBalance
).
to
.
deep
.
eq
(
preBalances
.
l1GatewayBalance
.
add
(
depositAmount
)
)
expect
(
postBalances
.
l2UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l2UserBalance
.
add
(
depositAmount
)
)
expect
(
postBalances
.
l1UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l1UserBalance
.
sub
(
l1FeePaid
.
add
(
depositAmount
))
)
})
it
(
'
depositTo
'
,
async
()
=>
{
const
depositAmount
=
10
const
preBalances
=
await
getBalances
()
const
depositReceipts
=
await
waitForXDomainTransaction
(
watcher
,
OVM_L1ETHGateway
.
depositTo
(
l2bob
.
address
,
{
value
:
depositAmount
,
}),
Direction
.
L1ToL2
)
const
l1FeePaid
=
depositReceipts
.
receipt
.
gasUsed
.
mul
(
depositReceipts
.
tx
.
gasPrice
)
const
postBalances
=
await
getBalances
()
expect
(
postBalances
.
l1GatewayBalance
).
to
.
deep
.
eq
(
preBalances
.
l1GatewayBalance
.
add
(
depositAmount
)
)
expect
(
postBalances
.
l2BobBalance
).
to
.
deep
.
eq
(
preBalances
.
l2BobBalance
.
add
(
depositAmount
)
)
expect
(
postBalances
.
l1UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l1UserBalance
.
sub
(
l1FeePaid
.
add
(
depositAmount
))
)
})
it
(
'
withdraw
'
,
async
()
=>
{
const
withdrawAmount
=
3
const
preBalances
=
await
getBalances
()
expect
(
preBalances
.
l2UserBalance
.
gt
(
0
),
'
Cannot run withdrawal test before any deposits...
'
)
await
waitForXDomainTransaction
(
watcher
,
OVM_ETH
.
withdraw
(
withdrawAmount
),
Direction
.
L2ToL1
)
const
postBalances
=
await
getBalances
()
expect
(
postBalances
.
l1GatewayBalance
).
to
.
deep
.
eq
(
preBalances
.
l1GatewayBalance
.
sub
(
withdrawAmount
)
)
expect
(
postBalances
.
l2UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l2UserBalance
.
sub
(
withdrawAmount
)
)
expect
(
postBalances
.
l1UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l1UserBalance
.
add
(
withdrawAmount
)
)
})
it
(
'
withdrawTo
'
,
async
()
=>
{
const
withdrawAmount
=
3
const
preBalances
=
await
getBalances
()
expect
(
preBalances
.
l2UserBalance
.
gt
(
0
),
'
Cannot run withdrawal test before any deposits...
'
)
await
waitForXDomainTransaction
(
watcher
,
OVM_ETH
.
withdrawTo
(
l1bob
.
address
,
withdrawAmount
),
Direction
.
L2ToL1
)
const
postBalances
=
await
getBalances
()
expect
(
postBalances
.
l1GatewayBalance
).
to
.
deep
.
eq
(
preBalances
.
l1GatewayBalance
.
sub
(
withdrawAmount
)
)
expect
(
postBalances
.
l2UserBalance
).
to
.
deep
.
eq
(
preBalances
.
l2UserBalance
.
sub
(
withdrawAmount
)
)
expect
(
postBalances
.
l1BobBalance
).
to
.
deep
.
eq
(
preBalances
.
l1BobBalance
.
add
(
withdrawAmount
)
)
})
it
(
'
deposit, transfer, withdraw
'
,
async
()
=>
{
const
roundTripAmount
=
3
const
preBalances
=
await
getBalances
()
await
waitForXDomainTransaction
(
watcher
,
OVM_L1ETHGateway
.
deposit
({
value
:
roundTripAmount
,
}),
Direction
.
L1ToL2
)
await
OVM_ETH
.
transfer
(
l2bob
.
address
,
roundTripAmount
)
await
waitForXDomainTransaction
(
watcher
,
OVM_ETH
.
connect
(
l2bob
).
withdraw
(
roundTripAmount
),
Direction
.
L2ToL1
)
const
postBalances
=
await
getBalances
()
expect
(
postBalances
.
l1BobBalance
).
to
.
deep
.
eq
(
preBalances
.
l1BobBalance
.
add
(
roundTripAmount
)
)
})
})
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