Skip to content

Commit ea41968

Browse files
Get private key of batch authenticator owner from .env.
1 parent c4ab04c commit ea41968

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

espresso/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ OPERATOR_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
3737
# BatchAuthenticator owner address for contract ownership (index 3 from mnemonic)
3838
# cast wallet address --mnemonic "test test ... junk" --hd-path "m/44'/60'/0'/0/3"
3939
BATCH_AUTHENTICATOR_OWNER_ADDRESS=0x90F79bf6EB2c4f870365E785982E1f101E93b906
40+
# cast wallet private-key --mnemonic "test test ... junk" --hd-path "m/44'/60'/0'/0/3"
41+
BATCH_AUTHENTICATOR_OWNER_PRIVATE_KEY=0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
4042

4143
# cast wallet address --mnemonic "test test ... junk" --hd-path "m/44'/60'/0'/0/1"
4244
PROPOSER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8

espresso/devnet-tests/devnet_tools.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"math/big"
1010
"os"
1111
"os/exec"
12+
"path/filepath"
1213
"reflect"
1314
"strconv"
1415
"strings"
@@ -27,6 +28,7 @@ import (
2728
"github.com/ethereum/go-ethereum/crypto"
2829
"github.com/ethereum/go-ethereum/ethclient"
2930
"github.com/ethereum/go-ethereum/log"
31+
"github.com/joho/godotenv"
3032

3133
env "github.com/ethereum-optimism/optimism/espresso/environment"
3234
"github.com/ethereum-optimism/optimism/op-e2e/config/secrets"
@@ -44,6 +46,18 @@ type Devnet struct {
4446
L2VerifRollup *sources.RollupClient
4547
}
4648

49+
// LoadEnvFile loads environment variables from a .env file
50+
func LoadEnvFile(filename string) error {
51+
return godotenv.Load(filename)
52+
}
53+
54+
// LoadDevnetEnv loads the espresso/.env file for devnet tests
55+
func LoadDevnetEnv() error {
56+
// Get the path to the espresso/.env file relative to the test directory
57+
envPath := filepath.Join("..", ".env")
58+
return LoadEnvFile(envPath)
59+
}
60+
4761
func NewDevnet(ctx context.Context, t *testing.T) *Devnet {
4862

4963
if testing.Short() {

espresso/devnet-tests/key_rotation_test.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ package devnet_tests
22

33
import (
44
"context"
5+
"os"
6+
"strings"
57
"testing"
68

79
"github.com/ethereum-optimism/optimism/op-batcher/bindings"
810
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
911
"github.com/ethereum-optimism/optimism/op-service/eth"
1012
"github.com/ethereum/go-ethereum/accounts/abi/bind"
13+
"github.com/ethereum/go-ethereum/crypto"
1114
"github.com/stretchr/testify/require"
1215
)
1316

1417
func TestRotateBatcherKey(t *testing.T) {
18+
1519
ctx, cancel := context.WithCancel(context.Background())
1620
defer cancel()
1721

@@ -53,6 +57,10 @@ func TestRotateBatcherKey(t *testing.T) {
5357
}
5458

5559
func TestChangeBatchInboxOwner(t *testing.T) {
60+
// Load environment variables from .env file
61+
err := LoadDevnetEnv()
62+
require.NoError(t, err, "Failed to load .env file")
63+
5664
ctx, cancel := context.WithCancel(context.Background())
5765
defer cancel()
5866

@@ -80,36 +88,34 @@ func TestChangeBatchInboxOwner(t *testing.T) {
8088
// Check current owner first
8189
currentOwner, err := batchAuthenticator.Owner(&bind.CallOpts{})
8290
require.NoError(t, err)
83-
t.Logf("Current BatchAuthenticator owner: %s", currentOwner.Hex())
84-
t.Logf("Deployer address: %s", d.secrets.Addresses().Deployer.Hex())
85-
t.Logf("Bob address: %s", d.secrets.Addresses().Bob.Hex())
8691

87-
// Use deployer key to sign the transaction
88-
deployerOpts, err := bind.NewKeyedTransactorWithChainID(d.secrets.Deployer, l1ChainID)
92+
// Check that the new owner is different from the current one
93+
bobAddress := d.secrets.Addresses().Bob
94+
require.NotEqual(t, currentOwner, bobAddress)
95+
96+
// Use batch authenticator owner key to sign the transaction
97+
batchAuthenticatorPrivateKeyHex := os.Getenv("BATCH_AUTHENTICATOR_OWNER_PRIVATE_KEY")
98+
require.NotEmpty(t, batchAuthenticatorPrivateKeyHex, "BATCH_AUTHENTICATOR_OWNER_PRIVATE_KEY must be set")
99+
t.Logf("Using BATCH_AUTHENTICATOR_OWNER_PRIVATE_KEY from environment: %s...", batchAuthenticatorPrivateKeyHex[:10])
100+
101+
batchAuthenticatorKey, err := crypto.HexToECDSA(strings.TrimPrefix(batchAuthenticatorPrivateKeyHex, "0x"))
89102
require.NoError(t, err)
90103

91-
// Verify we're transferring to the right address
92-
bobAddress := d.secrets.Addresses().Bob
93-
t.Logf("Attempting to transfer ownership from %s to %s", currentOwner.Hex(), bobAddress.Hex())
104+
batchAuthenticatorOwnerOpts, err := bind.NewKeyedTransactorWithChainID(batchAuthenticatorKey, l1ChainID)
105+
require.NoError(t, err)
94106

95107
// Call TransferOwnership
96-
tx, err := batchAuthenticator.TransferOwnership(deployerOpts, bobAddress)
108+
tx, err := batchAuthenticator.TransferOwnership(batchAuthenticatorOwnerOpts, bobAddress)
97109
require.NoError(t, err)
98-
t.Logf("TransferOwnership transaction hash: %s", tx.Hash().Hex())
99110

100111
// Wait for transaction receipt and check if it succeeded
101-
receipt, err := wait.ForReceiptOK(ctx, d.L1, tx.Hash())
112+
_, err = wait.ForReceiptOK(ctx, d.L1, tx.Hash())
102113
require.NoError(t, err)
103-
t.Logf("TransferOwnership transaction receipt status: %d", receipt.Status)
104-
t.Logf("TransferOwnership transaction gas used: %d", receipt.GasUsed)
105-
t.Logf("TransferOwnership transaction completed successfully")
106114

107115
// Ensure the owner has been changed
108116
newOwner, err := batchAuthenticator.Owner(&bind.CallOpts{})
109117
require.NoError(t, err)
110-
t.Logf("New owner after transfer: %s", newOwner.Hex())
111-
t.Logf("Expected Bob address: %s", d.secrets.Addresses().Bob.Hex())
112-
require.Equal(t, newOwner, d.secrets.Addresses().Bob)
118+
require.Equal(t, newOwner, bobAddress)
113119

114120
// Check that everything still functions
115121
require.NoError(t, d.RunSimpleL2Burn())

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ require (
7979
gopkg.in/yaml.v3 v3.0.1
8080
)
8181

82+
require github.com/joho/godotenv v1.5.1 // indirect
83+
8284
require (
8385
codeberg.org/go-fonts/liberation v0.5.0 // indirect
8486
codeberg.org/go-latex/latex v0.1.0 // indirect
@@ -106,7 +108,6 @@ require (
106108
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
107109
github.com/cockroachdb/redact v1.1.5 // indirect
108110
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
109-
github.com/coder/websocket v1.8.13
110111
github.com/consensys/bavard v0.1.27 // indirect
111112
github.com/containerd/cgroups v1.1.0 // indirect
112113
github.com/containerd/log v0.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl
473473
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
474474
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
475475
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
476+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
477+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
476478
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
477479
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
478480
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=

0 commit comments

Comments
 (0)