Skip to content

Commit

Permalink
fix: testRecipient CLI bug (#3138)
Browse files Browse the repository at this point in the history
### Description

- we were recovering `TestRecipient` from sdk artifacts which means the
deployer won't have ownership. So, I added a optional `shouldRecover`
boolean which I turned off for TestRecipient deployer (this is only for
our artifacts, if they have their own testRecipient, it will still
recover that if provided)
- moved `TestRecipientDeployer` from cli to sdk and removed duplicated
code from infra

### Drive-by changes

None

### Related issues

- fixes hyperlane-xyz/issues#895

### Backward compatibility

Yes

### Testing

Manual (between anvil1 and optimismgoerli)
  • Loading branch information
aroralanuk authored Jan 9, 2024
1 parent d3d7ad7 commit 67a6d97
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-ears-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/infra': patch
'@hyperlane-xyz/cli': patch
'@hyperlane-xyz/sdk': patch
---

Added `shouldRecover` flag to deployContractFromFactory so that the `TestRecipientDeployer` can deploy new contracts if it's not the owner of the prior deployments (We were recovering the SDK artifacts which meant the deployer won't be able to set the ISM as they needed)
6 changes: 2 additions & 4 deletions typescript/cli/src/deploy/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
MultiProvider,
MultisigConfig,
RoutingIsmConfig,
TestRecipientConfig,
TestRecipientDeployer,
buildAgentConfig,
buildAggregationIsmConfigs,
defaultMultisigConfigs,
Expand All @@ -47,10 +49,6 @@ import {
writeJson,
} from '../utils/files.js';

import {
TestRecipientConfig,
TestRecipientDeployer,
} from './TestRecipientDeployer.js';
import {
isISMConfig,
isZODISMConfig,
Expand Down
4 changes: 1 addition & 3 deletions typescript/infra/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { Contexts } from '../config/contexts';
import { deployEnvToSdkEnv } from '../src/config/environment';
import { deployWithArtifacts } from '../src/deployment/deploy';
import { TestQuerySenderDeployer } from '../src/deployment/testcontracts/testquerysender';
import { TestRecipientDeployer } from '../src/deployment/testcontracts/testrecipient';
import { impersonateAccount, useLocalProvider } from '../src/utils/fork';

import {
Expand Down Expand Up @@ -138,8 +137,7 @@ async function main() {
);
deployer = new LiquidityLayerDeployer(multiProvider);
} else if (module === Modules.TEST_RECIPIENT) {
config = objMap(envConfig.core, (_chain) => true);
deployer = new TestRecipientDeployer(multiProvider);
throw new Error('Test recipient is not supported. Use CLI instead.');
} else if (module === Modules.TEST_QUERY_SENDER) {
// Get query router addresses
const queryAddresses = getAddresses(
Expand Down
36 changes: 0 additions & 36 deletions typescript/infra/src/deployment/testcontracts/testrecipient.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import debug from 'debug';

import { TestRecipient, TestRecipient__factory } from '@hyperlane-xyz/core';
import {
ChainName,
HyperlaneDeployer,
MultiProvider,
} from '@hyperlane-xyz/sdk';
import { Address, eqAddress } from '@hyperlane-xyz/utils';

import { HyperlaneDeployer } from '../deploy/HyperlaneDeployer';
import { MultiProvider } from '../providers/MultiProvider';
import { ChainName } from '../types';

export type TestRecipientConfig = {
interchainSecurityModule: Address;
};
Expand Down Expand Up @@ -39,7 +38,28 @@ export class TestRecipientDeployer extends HyperlaneDeployer<
chain: ChainName,
config: TestRecipientConfig,
): Promise<TestRecipientContracts> {
const testRecipient = await this.deployContract(chain, 'testRecipient', []);
const predeployed = this.readCache(
chain,
this.factories['testRecipient'],
'testRecipient',
);
let usePreviousDeployment = false;
if (
predeployed &&
eqAddress(
await predeployed.owner(),
await this.multiProvider.getSignerAddress(chain),
)
) {
usePreviousDeployment = true;
}
const testRecipient = await this.deployContract(
chain,
'testRecipient',
[],
undefined,
usePreviousDeployment,
);
try {
this.logger(`Checking ISM ${chain}`);
const ism = await testRecipient.interchainSecurityModule();
Expand All @@ -51,7 +71,11 @@ export class TestRecipientDeployer extends HyperlaneDeployer<
const tx = testRecipient.setInterchainSecurityModule(
config.interchainSecurityModule,
);
await this.multiProvider.handleTx(chain, tx);
await this.runIfOwner(
chain,
testRecipient,
async () => await this.multiProvider.handleTx(chain, tx),
);
}
} catch (error) {
this.logger(`Failed to check/update ISM for ${chain}: ${error}`);
Expand Down
29 changes: 17 additions & 12 deletions typescript/sdk/src/deploy/HyperlaneDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,23 @@ export abstract class HyperlaneDeployer<
contractName: string,
constructorArgs: Parameters<F['deploy']>,
initializeArgs?: Parameters<Awaited<ReturnType<F['deploy']>>['initialize']>,
shouldRecover = true,
): Promise<ReturnType<F['deploy']>> {
const cachedContract = this.readCache(chain, factory, contractName);
if (cachedContract) {
if (this.recoverVerificationInputs) {
const recoveredInputs = await this.recoverVerificationArtifacts(
chain,
contractName,
cachedContract,
constructorArgs,
initializeArgs,
);
this.addVerificationArtifacts(chain, recoveredInputs);
if (shouldRecover) {
const cachedContract = this.readCache(chain, factory, contractName);
if (cachedContract) {
if (this.recoverVerificationInputs) {
const recoveredInputs = await this.recoverVerificationArtifacts(
chain,
contractName,
cachedContract,
constructorArgs,
initializeArgs,
);
this.addVerificationArtifacts(chain, recoveredInputs);
}
return cachedContract;
}
return cachedContract;
}

this.logger(`Deploy ${contractName} on ${chain}`);
Expand Down Expand Up @@ -347,13 +350,15 @@ export abstract class HyperlaneDeployer<
initializeArgs?: Parameters<
Awaited<ReturnType<Factories[K]['deploy']>>['initialize']
>,
shouldRecover = true,
): Promise<HyperlaneContracts<Factories>[K]> {
const contract = await this.deployContractFromFactory(
chain,
this.factories[contractName],
contractName.toString(),
constructorArgs,
initializeArgs,
shouldRecover,
);
this.writeCache(chain, contractName, contract.address);
return contract;
Expand Down
4 changes: 4 additions & 0 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export { HyperlaneCoreDeployer } from './core/HyperlaneCoreDeployer';
export { MultiProtocolCore } from './core/MultiProtocolCore';
export { TestCoreApp } from './core/TestCoreApp';
export { TestCoreDeployer } from './core/TestCoreDeployer';
export {
TestRecipientConfig,
TestRecipientDeployer,
} from './core/TestRecipientDeployer';
export { EvmCoreAdapter } from './core/adapters/EvmCoreAdapter';
export { SealevelCoreAdapter } from './core/adapters/SealevelCoreAdapter';
export { ICoreAdapter } from './core/adapters/types';
Expand Down

0 comments on commit 67a6d97

Please sign in to comment.