Commit f7a591cd authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-e2e: Adopt op-chain-ops (#3649)

* op-e2e: Start adopting op-chain-ops

This PR starts the process of adopting op-chain-ops in op-e2e by porting over the `Secrets` struct we use in Hive. This lets us share wallet generation code among different projects.

Adopting op-chain-ops in op-e2e improves the following:

1. Transactions now route through the correct proxy contracts.
2. There's no need to wait for a contract deployment since conracts exist in genesis.
3. We can export the test helpers in op-e2e to enable us to run similar end-to-end tests in other applications like the indexer

This is the first in a series of stacked PRs.

* op-e2e: Migrate tests to op-chain-ops

* Updates from code review

* remove unnecessary method

* Update op-e2e/setup.go
Co-authored-by: default avatarJoshua Gutow <jgutow@optimism.io>

* CR updates

* Update op-e2e/e2eutils/secrets.go
Co-authored-by: default avatarJoshua Gutow <jgutow@optimism.io>

* Update op-e2e/e2eutils/secrets.go
Co-authored-by: default avatarJoshua Gutow <jgutow@optimism.io>

* try to fix test timeout

* fix deadlock

* fix similar case
Co-authored-by: default avatarJoshua Gutow <jgutow@optimism.io>
parent b979d861
......@@ -15,9 +15,9 @@ import (
// We prefer a mnemonic rather than direct private keys to make it easier
// to export all testing keys in external tooling for use during debugging.
var DefaultMnemonicConfig = &MnemonicConfig{
Mnemonic: "test test test test test test test test test test test junk",
Deployer: "m/44'/60'/0'/0/1",
// clique signer: removed, use engine API instead
Mnemonic: "test test test test test test test test test test test junk",
Deployer: "m/44'/60'/0'/0/1",
CliqueSigner: "m/44'/60'/0'/0/2",
Proposer: "m/44'/60'/0'/0/3",
Batcher: "m/44'/60'/0'/0/4",
SequencerP2P: "m/44'/60'/0'/0/5",
......@@ -26,11 +26,13 @@ var DefaultMnemonicConfig = &MnemonicConfig{
Mallory: "m/44'/60'/0'/0/8",
}
// MnemonicConfig configures the private keys for testing purposes.
// MnemonicConfig configures the private keys for the hive testnet.
// It's json-serializable, so we can ship it to e.g. the hardhat script client.
type MnemonicConfig struct {
Mnemonic string
Deployer string
Deployer string
CliqueSigner string
// rollup actors
Proposer string
......@@ -58,6 +60,10 @@ func (m *MnemonicConfig) Secrets() (*Secrets, error) {
if err != nil {
return nil, err
}
cliqueSigner, err := wallet.PrivateKey(account(m.CliqueSigner))
if err != nil {
return nil, err
}
proposer, err := wallet.PrivateKey(account(m.Proposer))
if err != nil {
return nil, err
......@@ -85,6 +91,7 @@ func (m *MnemonicConfig) Secrets() (*Secrets, error) {
return &Secrets{
Deployer: deployer,
CliqueSigner: cliqueSigner,
Proposer: proposer,
Batcher: batcher,
SequencerP2P: sequencerP2P,
......@@ -96,7 +103,8 @@ func (m *MnemonicConfig) Secrets() (*Secrets, error) {
// Secrets bundles secp256k1 private keys for all common rollup actors for testing purposes.
type Secrets struct {
Deployer *ecdsa.PrivateKey
Deployer *ecdsa.PrivateKey
CliqueSigner *ecdsa.PrivateKey
// rollup actors
Proposer *ecdsa.PrivateKey
......@@ -122,6 +130,7 @@ func EncodePrivKey(priv *ecdsa.PrivateKey) hexutil.Bytes {
func (s *Secrets) Addresses() *Addresses {
return &Addresses{
Deployer: crypto.PubkeyToAddress(s.Deployer.PublicKey),
CliqueSigner: crypto.PubkeyToAddress(s.CliqueSigner.PublicKey),
Proposer: crypto.PubkeyToAddress(s.Proposer.PublicKey),
Batcher: crypto.PubkeyToAddress(s.Batcher.PublicKey),
SequencerP2P: crypto.PubkeyToAddress(s.SequencerP2P.PublicKey),
......@@ -133,7 +142,8 @@ func (s *Secrets) Addresses() *Addresses {
// Addresses bundles the addresses for all common rollup addresses for testing purposes.
type Addresses struct {
Deployer common.Address
Deployer common.Address
CliqueSigner common.Address
// rollup actors
Proposer common.Address
......@@ -148,8 +158,8 @@ type Addresses struct {
func (a *Addresses) All() []common.Address {
return []common.Address{
a.Batcher,
a.Deployer,
a.CliqueSigner,
a.Proposer,
a.Batcher,
a.SequencerP2P,
......
......@@ -10,7 +10,6 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
rollupEth "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
......@@ -23,8 +22,6 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/node"
hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
)
func waitForTransaction(hash common.Hash, client *ethclient.Client, timeout time.Duration) (*types.Receipt, error) {
......@@ -75,25 +72,9 @@ func waitForBlock(number *big.Int, client *ethclient.Client, timeout time.Durati
}
}
func getGenesisInfo(client *ethclient.Client) (id rollupEth.BlockID, timestamp uint64) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
block, err := client.BlockByNumber(ctx, common.Big0)
if err != nil {
panic(err)
}
return rollupEth.BlockID{Hash: block.Hash(), Number: block.NumberU64()}, block.Time()
}
func initL1Geth(cfg *SystemConfig, wallet *hdwallet.Wallet, genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
signer := deriveAccount(wallet, cfg.CliqueSignerDerivationPath)
pk, err := wallet.PrivateKey(signer)
if err != nil {
return nil, nil, fmt.Errorf("failed to locate private key in wallet: %w", err)
}
func initL1Geth(cfg *SystemConfig, genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
ethConfig := &ethconfig.Config{
NetworkId: cfg.L1ChainID.Uint64(),
NetworkId: cfg.DeployConfig.L1ChainID,
Genesis: genesis,
}
nodeConfig := &node.Config{
......@@ -106,7 +87,7 @@ func initL1Geth(cfg *SystemConfig, wallet *hdwallet.Wallet, genesis *core.Genesi
HTTPModules: []string{"debug", "admin", "eth", "txpool", "net", "rpc", "web3", "personal", "engine"},
}
l1Node, l1Eth, err := createGethNode(false, nodeConfig, ethConfig, []*ecdsa.PrivateKey{pk})
l1Node, l1Eth, err := createGethNode(false, nodeConfig, ethConfig, []*ecdsa.PrivateKey{cfg.Secrets.CliqueSigner})
if err != nil {
return nil, nil, err
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -477,7 +477,7 @@ func (s *state) eventLoop() {
// It waits for the reset to occur. It simply unblocks the caller rather
// than fully cancelling the reset request upon a context cancellation.
func (s *state) ResetDerivationPipeline(ctx context.Context) error {
respCh := make(chan struct{})
respCh := make(chan struct{}, 1)
select {
case <-ctx.Done():
return ctx.Err()
......@@ -492,7 +492,7 @@ func (s *state) ResetDerivationPipeline(ctx context.Context) error {
}
func (s *state) SyncStatus(ctx context.Context) (*eth.SyncStatus, error) {
respCh := make(chan eth.SyncStatus)
respCh := make(chan eth.SyncStatus, 1)
select {
case <-ctx.Done():
return nil, ctx.Err()
......
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