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
d1651bb2
Unverified
Commit
d1651bb2
authored
Dec 07, 2023
by
Sebastian Stammler
Committed by
GitHub
Dec 07, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8492 from ethereum-optimism/bugfix/wait-for-balance-changes
op-e2e: Add test utility to wait for balance changes
parents
b5cd4b01
ac2a7399
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
10 deletions
+28
-10
waits.go
op-e2e/e2eutils/wait/waits.go
+17
-0
system_test.go
op-e2e/system_test.go
+11
-10
No files found.
op-e2e/e2eutils/wait/waits.go
View file @
d1651bb2
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"time"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
...
@@ -13,6 +14,22 @@ import (
...
@@ -13,6 +14,22 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient"
)
)
func
ForBalanceChange
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
address
common
.
Address
,
initial
*
big
.
Int
)
(
*
big
.
Int
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
2
*
time
.
Minute
)
defer
cancel
()
return
AndGet
[
*
big
.
Int
](
ctx
,
100
*
time
.
Millisecond
,
func
()
(
*
big
.
Int
,
error
)
{
return
client
.
BalanceAt
(
ctx
,
address
,
nil
)
},
func
(
b
*
big
.
Int
)
bool
{
return
b
.
Cmp
(
initial
)
!=
0
},
)
}
func
ForReceiptOK
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
hash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
{
func
ForReceiptOK
(
ctx
context
.
Context
,
client
*
ethclient
.
Client
,
hash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
{
return
ForReceipt
(
ctx
,
client
,
hash
,
types
.
ReceiptStatusSuccessful
)
return
ForReceipt
(
ctx
,
client
,
hash
,
types
.
ReceiptStatusSuccessful
)
}
}
...
...
op-e2e/system_test.go
View file @
d1651bb2
...
@@ -250,7 +250,8 @@ func runE2ESystemTest(t *testing.T, sys *System) {
...
@@ -250,7 +250,8 @@ func runE2ESystemTest(t *testing.T, sys *System) {
// Confirm balance
// Confirm balance
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
15
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
15
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
endBalance
,
err
:=
l2Verif
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
endBalance
,
err
:=
wait
.
ForBalanceChange
(
ctx
,
l2Verif
,
fromAddr
,
startBalance
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
diff
:=
new
(
big
.
Int
)
diff
:=
new
(
big
.
Int
)
...
@@ -1047,7 +1048,7 @@ func TestWithdrawals(t *testing.T) {
...
@@ -1047,7 +1048,7 @@ func TestWithdrawals(t *testing.T) {
// Start L2 balance
// Start L2 balance
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
startBalance
,
err
:=
l2Verif
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
startBalance
BeforeDeposit
,
err
:=
l2Verif
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
// Send deposit tx
// Send deposit tx
...
@@ -1060,17 +1061,17 @@ func TestWithdrawals(t *testing.T) {
...
@@ -1060,17 +1061,17 @@ func TestWithdrawals(t *testing.T) {
// Confirm L2 balance
// Confirm L2 balance
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
endBalance
,
err
:=
l2Verif
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
endBalance
AfterDeposit
,
err
:=
wait
.
ForBalanceChange
(
ctx
,
l2Verif
,
fromAddr
,
startBalanceBeforeDeposit
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
diff
:=
new
(
big
.
Int
)
diff
:=
new
(
big
.
Int
)
diff
=
diff
.
Sub
(
endBalance
,
startBalance
)
diff
=
diff
.
Sub
(
endBalance
AfterDeposit
,
startBalanceBeforeDeposit
)
require
.
Equal
(
t
,
mintAmount
,
diff
,
"Did not get expected balance change after mint"
)
require
.
Equal
(
t
,
mintAmount
,
diff
,
"Did not get expected balance change after mint"
)
// Start L2 balance for withdrawal
// Start L2 balance for withdrawal
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
startBalance
,
err
=
l2Seq
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
startBalance
BeforeWithdrawal
,
err
:
=
l2Seq
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
withdrawAmount
:=
big
.
NewInt
(
500
_000_000_000
)
withdrawAmount
:=
big
.
NewInt
(
500
_000_000_000
)
...
@@ -1087,11 +1088,11 @@ func TestWithdrawals(t *testing.T) {
...
@@ -1087,11 +1088,11 @@ func TestWithdrawals(t *testing.T) {
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
endBalance
,
err
=
l2Verif
.
BalanceAt
(
ctx
,
fromAddr
,
ni
l
)
endBalance
AfterWithdrawal
,
err
:=
wait
.
ForBalanceChange
(
ctx
,
l2Seq
,
fromAddr
,
startBalanceBeforeWithdrawa
l
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
// Take fee into account
// Take fee into account
diff
=
new
(
big
.
Int
)
.
Sub
(
startBalance
,
endBalance
)
diff
=
new
(
big
.
Int
)
.
Sub
(
startBalance
BeforeWithdrawal
,
endBalanceAfterWithdrawal
)
fees
:=
calcGasFees
(
receipt
.
GasUsed
,
tx
.
GasTipCap
(),
tx
.
GasFeeCap
(),
header
.
BaseFee
)
fees
:=
calcGasFees
(
receipt
.
GasUsed
,
tx
.
GasTipCap
(),
tx
.
GasFeeCap
(),
header
.
BaseFee
)
fees
=
fees
.
Add
(
fees
,
receipt
.
L1Fee
)
fees
=
fees
.
Add
(
fees
,
receipt
.
L1Fee
)
diff
=
diff
.
Sub
(
diff
,
fees
)
diff
=
diff
.
Sub
(
diff
,
fees
)
...
@@ -1100,7 +1101,7 @@ func TestWithdrawals(t *testing.T) {
...
@@ -1100,7 +1101,7 @@ func TestWithdrawals(t *testing.T) {
// Take start balance on L1
// Take start balance on L1
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
startBalance
,
err
=
l1Client
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
startBalance
BeforeFinalize
,
err
:
=
l1Client
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
proveReceipt
,
finalizeReceipt
:=
ProveAndFinalizeWithdrawal
(
t
,
cfg
,
l1Client
,
sys
.
EthInstances
[
"verifier"
],
ethPrivKey
,
receipt
)
proveReceipt
,
finalizeReceipt
:=
ProveAndFinalizeWithdrawal
(
t
,
cfg
,
l1Client
,
sys
.
EthInstances
[
"verifier"
],
ethPrivKey
,
receipt
)
...
@@ -1108,13 +1109,13 @@ func TestWithdrawals(t *testing.T) {
...
@@ -1108,13 +1109,13 @@ func TestWithdrawals(t *testing.T) {
// Verify balance after withdrawal
// Verify balance after withdrawal
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
endBalance
,
err
=
l1Client
.
BalanceAt
(
ctx
,
fromAddr
,
nil
)
endBalance
AfterFinalize
,
err
:=
wait
.
ForBalanceChange
(
ctx
,
l1Client
,
fromAddr
,
startBalanceBeforeFinalize
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
// Ensure that withdrawal - gas fees are added to the L1 balance
// Ensure that withdrawal - gas fees are added to the L1 balance
// Fun fact, the fee is greater than the withdrawal amount
// Fun fact, the fee is greater than the withdrawal amount
// NOTE: The gas fees include *both* the ProveWithdrawalTransaction and FinalizeWithdrawalTransaction transactions.
// NOTE: The gas fees include *both* the ProveWithdrawalTransaction and FinalizeWithdrawalTransaction transactions.
diff
=
new
(
big
.
Int
)
.
Sub
(
endBalance
,
startBalanc
e
)
diff
=
new
(
big
.
Int
)
.
Sub
(
endBalance
AfterFinalize
,
startBalanceBeforeFinaliz
e
)
proveFee
:=
new
(
big
.
Int
)
.
Mul
(
new
(
big
.
Int
)
.
SetUint64
(
proveReceipt
.
GasUsed
),
proveReceipt
.
EffectiveGasPrice
)
proveFee
:=
new
(
big
.
Int
)
.
Mul
(
new
(
big
.
Int
)
.
SetUint64
(
proveReceipt
.
GasUsed
),
proveReceipt
.
EffectiveGasPrice
)
finalizeFee
:=
new
(
big
.
Int
)
.
Mul
(
new
(
big
.
Int
)
.
SetUint64
(
finalizeReceipt
.
GasUsed
),
finalizeReceipt
.
EffectiveGasPrice
)
finalizeFee
:=
new
(
big
.
Int
)
.
Mul
(
new
(
big
.
Int
)
.
SetUint64
(
finalizeReceipt
.
GasUsed
),
finalizeReceipt
.
EffectiveGasPrice
)
fees
=
new
(
big
.
Int
)
.
Add
(
proveFee
,
finalizeFee
)
fees
=
new
(
big
.
Int
)
.
Add
(
proveFee
,
finalizeFee
)
...
...
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