Commit 7a5eddb3 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

op-e2e: Add tests (#4435)

* Remove chain ops replace in go.mod

* Add waitForL1OriginOnL2 helper function

This makes it easier to wait for system config changes or deposits
to be included on L2.

* Add TestGasPriceOracleFeeUpdates

This test was initially written by Trail of Bits. I have modified
it to remove some helper functions & work with the new gas price
oracle configuration method (derived from L1 instead of L2).

* Add TestL2SequencerRPCDepositTx

This test was originally written by Trail of Bits. I modified it
to not use helper functions and work with the updated system.

* Add TestMixedDepositValidity

This test was originaly written by Trail of Bits. I modified the test to make
it work with the updated system & modified several components of the system
to make this test work. The largest change is now the premine is applied to
L2 in addition to L1.

* Add TestMixedWithdrawalValidity

This test was originally written by Trail of Bits. This modifies the test to
work with the new system.

* CI: Increase timeout for e2e tests

* CI: Enable parallel e2e tests again

The tests are stable enough & taking long enough without this flag that I think
it is worth making the tests parallel. We still have the option to run the
tests sequentially if we need the better output for debugging them.

* op-e2e: Increase timeout while waiting for withdrawal to finalize

* Address PR comments
parent fb498ecf
...@@ -513,8 +513,9 @@ jobs: ...@@ -513,8 +513,9 @@ jobs:
command: | command: |
# Note: We don't use circle CI test splits because we need to split by test name, not by package. There is an additional # Note: We don't use circle CI test splits because we need to split by test name, not by package. There is an additional
# constraint that gotestsum does not currently (nor likely will) accept files from different pacakges when building. # constraint that gotestsum does not currently (nor likely will) accept files from different pacakges when building.
OP_TESTLOG_DISABLE_COLOR=true OP_E2E_DISABLE_PARALLEL=true OP_E2E_USE_HTTP=<<parameters.use_http>> gotestsum \ OP_TESTLOG_DISABLE_COLOR=true OP_E2E_DISABLE_PARALLEL=false OP_E2E_USE_HTTP=<<parameters.use_http>> gotestsum \
--format=standard-verbose --junitfile=/tmp/test-results/<<parameters.module>>_http_<<parameters.use_http>>.xml ./... --format=standard-verbose --junitfile=/tmp/test-results/<<parameters.module>>_http_<<parameters.use_http>>.xml \
-- -timeout=20m
working_directory: <<parameters.module>> working_directory: <<parameters.module>>
- store_test_results: - store_test_results:
path: /tmp/test-results path: /tmp/test-results
......
...@@ -105,6 +105,7 @@ func (m *MnemonicConfig) Secrets() (*Secrets, error) { ...@@ -105,6 +105,7 @@ func (m *MnemonicConfig) Secrets() (*Secrets, error) {
Alice: alice, Alice: alice,
Bob: bob, Bob: bob,
Mallory: mallory, Mallory: mallory,
Wallet: wallet,
}, nil }, nil
} }
...@@ -123,6 +124,9 @@ type Secrets struct { ...@@ -123,6 +124,9 @@ type Secrets struct {
Alice *ecdsa.PrivateKey Alice *ecdsa.PrivateKey
Bob *ecdsa.PrivateKey Bob *ecdsa.PrivateKey
Mallory *ecdsa.PrivateKey Mallory *ecdsa.PrivateKey
// Share the wallet to be able to generate more accounts
Wallet *hdwallet.Wallet
} }
// EncodePrivKey encodes the given private key in 32 bytes // EncodePrivKey encodes the given private key in 32 bytes
......
...@@ -8,11 +8,10 @@ import ( ...@@ -8,11 +8,10 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
...@@ -22,9 +21,45 @@ import ( ...@@ -22,9 +21,45 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
) )
func waitForL1OriginOnL2(l1BlockNum uint64, client *ethclient.Client, timeout time.Duration) (*types.Block, error) {
timeoutCh := time.After(timeout)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
headChan := make(chan *types.Header, 100)
headSub, err := client.SubscribeNewHead(ctx, headChan)
if err != nil {
return nil, err
}
defer headSub.Unsubscribe()
for {
select {
case head := <-headChan:
block, err := client.BlockByNumber(ctx, head.Number)
if err != nil {
return nil, err
}
l1Info, err := derive.L1InfoDepositTxData(block.Transactions()[0].Data())
if err != nil {
return nil, err
}
if l1Info.Number >= l1BlockNum {
return block, nil
}
case err := <-headSub.Err():
return nil, fmt.Errorf("Error in head subscription: %w", err)
case <-timeoutCh:
return nil, errors.New("timeout")
}
}
}
func waitForTransaction(hash common.Hash, client *ethclient.Client, timeout time.Duration) (*types.Receipt, error) { func waitForTransaction(hash common.Hash, client *ethclient.Client, timeout time.Duration) (*types.Receipt, error) {
timeoutCh := time.After(timeout) timeoutCh := time.After(timeout)
ticker := time.NewTicker(100 * time.Millisecond) ticker := time.NewTicker(100 * time.Millisecond)
......
...@@ -2,8 +2,6 @@ module github.com/ethereum-optimism/optimism/op-e2e ...@@ -2,8 +2,6 @@ module github.com/ethereum-optimism/optimism/op-e2e
go 1.18 go 1.18
replace github.com/ethereum-optimism/optimism/op-chain-ops v0.10.0 => ../op-chain-ops
require ( require (
github.com/docker/docker v20.10.21+incompatible github.com/docker/docker v20.10.21+incompatible
github.com/docker/go-connections v0.4.0 github.com/docker/go-connections v0.4.0
...@@ -15,6 +13,7 @@ require ( ...@@ -15,6 +13,7 @@ require (
github.com/ethereum-optimism/optimism/op-proposer v0.10.4 github.com/ethereum-optimism/optimism/op-proposer v0.10.4
github.com/ethereum-optimism/optimism/op-service v0.10.4 github.com/ethereum-optimism/optimism/op-service v0.10.4
github.com/ethereum/go-ethereum v1.10.26 github.com/ethereum/go-ethereum v1.10.26
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8
github.com/libp2p/go-libp2p v0.23.3 github.com/libp2p/go-libp2p v0.23.3
github.com/stretchr/testify v1.8.1 github.com/stretchr/testify v1.8.1
) )
......
...@@ -275,6 +275,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ ...@@ -275,6 +275,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 h1:Ep/joEub9YwcjRY6ND3+Y/w0ncE540RtGatVhtZL0/Q= github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 h1:Ep/joEub9YwcjRY6ND3+Y/w0ncE540RtGatVhtZL0/Q=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
......
...@@ -267,6 +267,21 @@ func (cfg SystemConfig) Start() (*System, error) { ...@@ -267,6 +267,21 @@ func (cfg SystemConfig) Start() (*System, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
for addr, amount := range cfg.Premine {
if existing, ok := l2Genesis.Alloc[addr]; ok {
l2Genesis.Alloc[addr] = core.GenesisAccount{
Code: existing.Code,
Storage: existing.Storage,
Balance: amount,
Nonce: existing.Nonce,
}
} else {
l2Genesis.Alloc[addr] = core.GenesisAccount{
Balance: amount,
Nonce: 0,
}
}
}
makeRollupConfig := func() rollup.Config { makeRollupConfig := func() rollup.Config {
return rollup.Config{ return rollup.Config{
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment