Skip to content

Commit

Permalink
Update according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed May 23, 2024
1 parent 02c8c67 commit c9ff695
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 145 deletions.
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
87 changes: 57 additions & 30 deletions typescript/sdk/src/core/EvmCoreModule.hardhat-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers.js';
import { expect } from 'chai';
import { ethers } from 'ethers';
import { constants } from 'ethers';
import hre from 'hardhat';

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

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

Expand All @@ -16,18 +21,48 @@ describe('EvmCoreModule', async () => {
let signer: SignerWithAddress;
let multiProvider: MultiProvider;
let evmCoreModule: EvmCoreModule;
let proxyAdminContract: any;
let mailboxContract: any;
let validatorAnnounceContract: any;
let testRecipientContract: any;

before(async () => {
[signer] = await hre.ethers.getSigners();
multiProvider = MultiProvider.createTestMultiProvider({ signer });
const config = testCoreConfig([TestChainName.test1])[TestChainName.test1];

evmCoreModule = await EvmCoreModule.create({
chain: TestChainName.test1,
config: testCoreConfig([]) as CoreConfig,
config,
multiProvider,
});

const { proxyAdmin, mailbox, validatorAnnounce, testRecipient } =
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),
);
});

describe('Create', async () => {
it('should create deploy an ICA', () => {
console.log('evmCoreModule.serialize();', evmCoreModule.serialize());
const { interchainAccountRouter, interchainAccountIsm } =
evmCoreModule.serialize();
expect(interchainAccountIsm).to.exist;
Expand All @@ -37,72 +72,64 @@ describe('EvmCoreModule', async () => {
it('should deploy ISM factories', () => {
// Each ISM factory
objMap(
evmCoreModule.serialize().ismFactoryFactories,
(_: any, contract: any) => {
expect(contract.address).to.exist;
evmCoreModule.serialize().deployedIsmFactoryFactories,
(_: any, factoryAddress: any) => {
expect(factoryAddress).to.exist;
expect(factoryAddress).to.not.equal(constants.AddressZero);
},
);
});

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit c9ff695

Please sign in to comment.