Skip to content

Commit

Permalink
feat: Create EvmCoreModule with create() (#3737)
Browse files Browse the repository at this point in the history
### Description
This Pull Request introduces the new EVM core module be implementing the
`create()` function. Currently, `create()` will call the existing
CoreDeployer

### Related issues

- Fixes #3575 

### Backward compatibility
Yes

### Testing
Unit Tests

---------

Signed-off-by: Paul Balaji <paul@hyperlane.xyz>
Co-authored-by: Paul Balaji <paul@hyperlane.xyz>
  • Loading branch information
ltyu and paulbalaji authored May 27, 2024
1 parent 3dabcbd commit eb23e77
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-suns-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Add create() with EvmCoreModule
9 changes: 9 additions & 0 deletions typescript/sdk/src/contracts/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export function attachContractsMapAndGetForeignDeployments<
};
}

export function attachAndConnectContracts<F extends HyperlaneFactories>(
addresses: HyperlaneAddresses<F>,
factories: F,
connection: Connection,
): HyperlaneContracts<F> {
const contracts = attachContracts(addresses, factories);
return connectContracts(contracts, connection);
}

export function connectContracts<F extends HyperlaneFactories>(
contracts: HyperlaneContracts<F>,
connection: Connection,
Expand Down
158 changes: 158 additions & 0 deletions typescript/sdk/src/core/EvmCoreModule.hardhat-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers.js';
import { expect } from 'chai';
import { constants } from 'ethers';
import hre from 'hardhat';

import {
Mailbox__factory,
ProxyAdmin__factory,
TestRecipient__factory,
TimelockController__factory,
ValidatorAnnounce__factory,
} from '@hyperlane-xyz/core';
import { objMap } from '@hyperlane-xyz/utils';

import { TestChainName } from '../consts/testChains.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { testCoreConfig } from '../test/testUtils.js';

import { EvmCoreModule } from './EvmCoreModule.js';

describe('EvmCoreModule', async () => {
const DELAY = 1892391283182;
let signer: SignerWithAddress;
let multiProvider: MultiProvider;
let evmCoreModule: EvmCoreModule;
let proxyAdminContract: any;
let mailboxContract: any;
let validatorAnnounceContract: any;
let testRecipientContract: any;
let timelockControllerContract: any;

before(async () => {
[signer] = await hre.ethers.getSigners();
multiProvider = MultiProvider.createTestMultiProvider({ signer });
const config = {
...testCoreConfig([TestChainName.test1])[TestChainName.test1],
upgrade: {
timelock: {
delay: DELAY,
roles: {
executor: signer.address,
proposer: signer.address,
},
},
},
};

evmCoreModule = await EvmCoreModule.create({
chain: TestChainName.test1,
config,
multiProvider,
});

const {
proxyAdmin,
mailbox,
validatorAnnounce,
testRecipient,
timelockController,
} = evmCoreModule.serialize();

proxyAdminContract = ProxyAdmin__factory.connect(
proxyAdmin!,
multiProvider.getProvider(TestChainName.test1),
);

mailboxContract = Mailbox__factory.connect(
mailbox!,
multiProvider.getProvider(TestChainName.test1),
);

validatorAnnounceContract = ValidatorAnnounce__factory.connect(
validatorAnnounce!,
multiProvider.getProvider(TestChainName.test1),
);

testRecipientContract = TestRecipient__factory.connect(
testRecipient!,
multiProvider.getProvider(TestChainName.test1),
);

timelockControllerContract = TimelockController__factory.connect(
timelockController!,
multiProvider.getProvider(TestChainName.test1),
);
});

describe('Create', async () => {
it('should create deploy an ICA', () => {
const { interchainAccountRouter, interchainAccountIsm } =
evmCoreModule.serialize();
expect(interchainAccountIsm).to.exist;
expect(interchainAccountRouter).to.exist;
});

it('should deploy ISM factories', () => {
// Each ISM factory
objMap(
evmCoreModule.serialize().ismFactoryFactories,
(_: any, factoryAddress: any) => {
expect(factoryAddress).to.exist;
expect(factoryAddress).to.not.equal(constants.AddressZero);
},
);
});

it('should deploy proxyAdmin', () => {
expect(evmCoreModule.serialize().proxyAdmin).to.exist;
});

it('should set proxyAdmin owner to deployer', async () => {
expect(await proxyAdminContract.owner()).to.equal(signer.address);
});

it('should deploy mailbox', () => {
expect(evmCoreModule.serialize().mailbox).to.exist;
});

it('should set mailbox owner to proxyAdmin', async () => {
expect(await mailboxContract.owner()).to.equal(
evmCoreModule.serialize().proxyAdmin,
);
});

it('should deploy mailbox default Ism', async () => {
expect(await mailboxContract.defaultIsm()).to.not.equal(
constants.AddressZero,
);
});

it('should deploy mailbox default hook', async () => {
expect(await mailboxContract.defaultHook()).to.not.equal(
constants.AddressZero,
);
});

it('should deploy mailbox required hook', async () => {
expect(await mailboxContract.requiredHook()).to.not.equal(
constants.AddressZero,
);
});

it('should deploy validatorAnnounce', async () => {
expect(evmCoreModule.serialize().validatorAnnounce).to.exist;
expect(await validatorAnnounceContract.owner()).to.equal(signer.address);
});

it('should deploy testRecipient', async () => {
expect(evmCoreModule.serialize().testRecipient).to.exist;
expect(await testRecipientContract.owner()).to.equal(signer.address);
});

it('should deploy timelock if upgrade is set', async () => {
expect(evmCoreModule.serialize().timelockController).to.exist;
expect(await timelockControllerContract.getMinDelay()).to.equal(DELAY);
});
});
});
Loading

0 comments on commit eb23e77

Please sign in to comment.