@@ -2,16 +2,20 @@ package devnet_tests
22
33import (
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
1417func 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
5559func 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 ())
0 commit comments