@@ -21,6 +21,8 @@ import { ethers } from 'ethers';
2121
2222import TestWETH9 from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/test/TestWETH9.sol/TestWETH9.json' ;
2323
24+ import { arbOwnerPrepareTransactionRequest } from '../arbOwnerPrepareTransactionRequest' ;
25+ import { arbOwnerReadContract } from '../arbOwnerReadContract' ;
2426import { registerCustomParentChain } from '../chains' ;
2527import {
2628 rollupCreatorABI ,
@@ -175,6 +177,42 @@ async function getNitroTestnodeStyleValidators(
175177 return validators ;
176178}
177179
180+ async function ensureChainOwner ( params : {
181+ publicClient : PublicClient < Transport , Chain > ;
182+ chainOwner : PrivateKeyAccountWithPrivateKey ;
183+ newChainOwner : Address ;
184+ } ) {
185+ const { publicClient, chainOwner, newChainOwner } = params ;
186+
187+ const isAlreadyChainOwner = await arbOwnerReadContract ( publicClient , {
188+ functionName : 'isChainOwner' ,
189+ args : [ newChainOwner ] ,
190+ } ) ;
191+
192+ if ( isAlreadyChainOwner ) {
193+ return ;
194+ }
195+
196+ const transactionRequest = await arbOwnerPrepareTransactionRequest ( publicClient , {
197+ functionName : 'addChainOwner' ,
198+ args : [ newChainOwner ] ,
199+ upgradeExecutor : false ,
200+ account : chainOwner . address ,
201+ } ) ;
202+
203+ const transactionHash = await publicClient . sendRawTransaction ( {
204+ serializedTransaction : await chainOwner . signTransaction ( transactionRequest ) ,
205+ } ) ;
206+
207+ const receipt = await publicClient . waitForTransactionReceipt ( {
208+ hash : transactionHash ,
209+ } ) ;
210+
211+ if ( receipt . status !== 'success' ) {
212+ throw new Error ( `Failed to add chain owner ${ newChainOwner } ` ) ;
213+ }
214+ }
215+
178216export function dehydrateAnvilTestStack ( env : AnvilTestStack ) : InjectedAnvilTestStack {
179217 return {
180218 ...env ,
@@ -714,6 +752,12 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
714752 } ,
715753 } ,
716754 } ) ;
755+
756+ await ensureChainOwner ( {
757+ publicClient : l3Client ,
758+ chainOwner : harnessDeployer ,
759+ newChainOwner : tokenBridgeContracts . orbitChainContracts . upgradeExecutor ,
760+ } ) ;
717761 console . log ( 'L3 token bridge contracts deployed on L2\n' ) ;
718762
719763 initializedEnv = {
0 commit comments