From 3b838c85a7c5964dc4034e644e56c272003a9fc1 Mon Sep 17 00:00:00 2001 From: -f Date: Wed, 13 Dec 2023 13:04:04 -0500 Subject: [PATCH] rm isOwner --- solidity/test/testSendReceiver.test.ts | 40 ------------------- typescript/sdk/src/ism/HyperlaneIsmFactory.ts | 24 ++++++++--- typescript/sdk/src/ism/types.ts | 10 ++--- 3 files changed, 23 insertions(+), 51 deletions(-) delete mode 100644 solidity/test/testSendReceiver.test.ts diff --git a/solidity/test/testSendReceiver.test.ts b/solidity/test/testSendReceiver.test.ts deleted file mode 100644 index 527b968596..0000000000 --- a/solidity/test/testSendReceiver.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { expect } from 'chai'; -import { ethers } from 'hardhat'; - -import { addressToBytes32 } from '@hyperlane-xyz/utils'; - -import { TestSendReceiver__factory } from '../types'; - -describe('TestSendReceiver', () => { - it('randomly handles a message', async () => { - const [signer] = await ethers.getSigners(); - const signerAddress = await signer.getAddress(); - const recipientFactory = new TestSendReceiver__factory(signer); - const recipient = await recipientFactory.deploy(); - - // Didn't know how else to test the randomness - let successes = 0; - let failures = 0; - for (let i = 0; i < 100; i++) { - try { - // "Inject randomness" - await signer.sendTransaction({ - from: signerAddress, - to: signerAddress, - value: 1, - }); - await recipient.handle( - 0, - addressToBytes32(recipient.address), - '0x1234', - ); - successes += 1; - } catch (error) { - failures += 1; - } - } - - expect(successes).to.be.greaterThan(5); - expect(failures).to.be.greaterThan(1); - }); -}); diff --git a/typescript/sdk/src/ism/HyperlaneIsmFactory.ts b/typescript/sdk/src/ism/HyperlaneIsmFactory.ts index 7ae0c5463a..42391df177 100644 --- a/typescript/sdk/src/ism/HyperlaneIsmFactory.ts +++ b/typescript/sdk/src/ism/HyperlaneIsmFactory.ts @@ -211,12 +211,22 @@ export class HyperlaneIsmFactory extends HyperlaneApp { mailbox, ) : { - isOwner: false, domainsToUnenroll: [], domainsToEnroll: Object.keys(config.domains), }; + + const signer = this.multiProvider.getSigner(destination); + const provider = this.multiProvider.getProvider(destination); + let isOwner = false; + if (existingIsmAddress) { + const owner = await DomainRoutingIsm__factory.connect( + existingIsmAddress, + provider, + ).owner(); + isOwner = eqAddress(await signer.getAddress(), owner); + } // reconfiguring existing routing ISM - if (existingIsmAddress && delta.isOwner && !delta.mailbox) { + if (existingIsmAddress && isOwner && !delta.mailbox) { const isms: ChainMap
= {}; routingIsm = DomainRoutingIsm__factory.connect( existingIsmAddress, @@ -320,6 +330,9 @@ export class HyperlaneIsmFactory extends HyperlaneApp { (log): log is ethers.utils.LogDescription => !!log && log.name === 'ModuleDeployed', ); + if (dispatchLogs.length === 0) { + throw new Error('No ModuleDeployed event found'); + } const moduleAddress = dispatchLogs[0].args['module']; routingIsm = DomainRoutingIsm__factory.connect( moduleAddress, @@ -672,7 +685,6 @@ export async function routingModuleDelta( contracts: HyperlaneContracts, mailbox?: Address, ): Promise { - const signer = multiProvider.getSigner(destination); const provider = multiProvider.getProvider(destination); const routingIsm = DomainRoutingIsm__factory.connect(moduleAddress, provider); const owner = await routingIsm.owner(); @@ -681,7 +693,6 @@ export async function routingModuleDelta( ); const delta: RoutingIsmDelta = { - isOwner: eqAddress(await signer.getAddress(), owner), domainsToUnenroll: [], domainsToEnroll: [], }; @@ -700,8 +711,9 @@ export async function routingModuleDelta( ); // check for inclusion of domains in the config for (const [origin, subConfig] of Object.entries(config.domains)) { - if (!deployedDomains.includes(origin)) delta.domainsToEnroll.push(origin); - else { + if (!deployedDomains.includes(origin)) { + delta.domainsToEnroll.push(origin); + } else { const subModule = await routingIsm.module( multiProvider.getDomainId(origin), ); diff --git a/typescript/sdk/src/ism/types.ts b/typescript/sdk/src/ism/types.ts index f9dfabe8d9..75c759c90e 100644 --- a/typescript/sdk/src/ism/types.ts +++ b/typescript/sdk/src/ism/types.ts @@ -104,10 +104,10 @@ export type DeployedIsmType = { export type DeployedIsm = ValueOf; +// for finding the difference between the onchain deployment and the config provided export type RoutingIsmDelta = { - domainsToUnenroll: ChainName[]; - domainsToEnroll: ChainName[]; - owner?: Address; - mailbox?: Address; - isOwner: boolean; + domainsToUnenroll: ChainName[]; // new or updated isms for the domain + domainsToEnroll: ChainName[]; // isms to remove + owner?: Address; // is the owner different + mailbox?: Address; // is the mailbox different (only for fallback routing) };