Skip to content

Commit

Permalink
typescript config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunal Arora committed Jun 29, 2023
1 parent a55617d commit 60dad87
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rust/vendor/
rust/tmp_db
rust/tmp.env
tmp.env
.DS_STORE
*/.DS_STORE

# Built Helm dependencies
**/helm/**/charts/*.tgz
Expand Down
4 changes: 0 additions & 4 deletions solidity/contracts/isms/native/AbstractNativeISM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,4 @@ abstract contract AbstractNativeISM is

return _messageSender == verifiedMessageIds[_messageId];
}

function toggleVerify(bytes32 messageId, bytes32 sender) external {
verifiedMessageIds[messageId] = sender;
}
}
35 changes: 13 additions & 22 deletions solidity/test/isms/OptimismISM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.13;

import {Test} from "forge-std/Test.sol";
import "forge-std/console.sol";

import {TypeCasts} from "../../contracts/libs/TypeCasts.sol";
import {Mailbox} from "../../contracts/Mailbox.sol";
Expand Down Expand Up @@ -67,8 +66,8 @@ contract OptimismISMTest is Test {
error NotCrossChainCall();

function setUp() public {
mainnetFork = vm.createFork(vm.rpcUrl("mainnet"));
optimismFork = vm.createFork(vm.rpcUrl("optimism"));
mainnetFork = vm.createFork(vm.rpcUrl("mainnet"), 17_586_909);
optimismFork = vm.createFork(vm.rpcUrl("optimism"), 106_233_774);

testRecipient = new TestRecipient();
}
Expand Down Expand Up @@ -120,7 +119,7 @@ contract OptimismISMTest is Test {

/* ============ hook.postDispatch ============ */

function testPostDispatch() public {
function testFork_PostDispatch() public {
deployAll();

vm.selectFork(mainnetFork);
Expand Down Expand Up @@ -151,7 +150,7 @@ contract OptimismISMTest is Test {
opHook.postDispatch(OPTIMISM_DOMAIN, messageId);
}

function testPostDispatch_ChainIDNotSupported() public {
function testFork_PostDispatch_RevertWhen_ChainIDNotSupported() public {
deployAll();

vm.selectFork(mainnetFork);
Expand All @@ -166,7 +165,7 @@ contract OptimismISMTest is Test {

/* ============ ISM.verifyMessageId ============ */

function testVerifyMessageId() public {
function testFork_VerifyMessageId() public {
deployAll();

vm.selectFork(optimismFork);
Expand All @@ -182,14 +181,6 @@ contract OptimismISMTest is Test {
(address(this).addressToBytes32(), messageId)
);

console.log("encoded message hook data");

console.logBytes(encodedHookData);

console.log("selector for verifyMessagId");

console.logBytes4(OptimismISM.verifyMessageId.selector);

(uint240 nonce, uint16 verison) = Encoding.decodeVersionedNonce(
l2Messenger.messageNonce()
);
Expand Down Expand Up @@ -217,9 +208,6 @@ contract OptimismISMTest is Test {
vm.expectEmit(true, false, false, false, L2_MESSENGER_ADDRESS);
emit RelayedMessage(versionedHash);

console.logBytes4(l2Messenger.relayMessage.selector);
console.log("Nonce: %s", versionedNonce);

l2Messenger.relayMessage(
versionedNonce,
address(opHook),
Expand All @@ -237,6 +225,7 @@ contract OptimismISMTest is Test {
vm.stopPrank();
}

// will get included in https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/2410
// function testverifyMessageId_WithValue() public {
// // this would fail
// deployAll();
Expand Down Expand Up @@ -276,7 +265,7 @@ contract OptimismISMTest is Test {
// vm.stopPrank();
// }

function testVerifyMessageId_NotAuthorized() public {
function testFork_VerifyMessageId_RevertWhen_NotAuthorized() public {
deployAll();

vm.selectFork(optimismFork);
Expand Down Expand Up @@ -305,7 +294,7 @@ contract OptimismISMTest is Test {

/* ============ ISM.verify ============ */

function testVerify() public {
function testFork_Verify() public {
deployAll();

vm.selectFork(optimismFork);
Expand Down Expand Up @@ -343,7 +332,8 @@ contract OptimismISMTest is Test {
assertTrue(verified);
}

function testVerify_InvalidMessage_Hyperlane() public {
// sending over invalid message
function testFork_Verify_RevertWhen_HyperlaneInvalidMessage() public {
deployAll();

vm.selectFork(optimismFork);
Expand Down Expand Up @@ -382,7 +372,8 @@ contract OptimismISMTest is Test {
assertFalse(verified);
}

function testVerify_InvalidMessageID_Optimism() public {
// invalid messageID in postDispatch
function testFork_Verify_RevertWhen_InvalidOptimismMessageID() public {
deployAll();

vm.selectFork(optimismFork);
Expand Down Expand Up @@ -421,7 +412,7 @@ contract OptimismISMTest is Test {
assertFalse(verified);
}

function testVerify_InvalidSender() public {
function testFork_Verify_RevertWhen_InvalidSender() public {
deployAll();

vm.selectFork(optimismFork);
Expand Down
1 change: 1 addition & 0 deletions typescript/infra/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ cache/
test/outputs
config/environments/test/core/
config/environments/test/igp/
config/environments/test/hook/
6 changes: 3 additions & 3 deletions typescript/infra/config/environments/test/hook/addresses.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"test1": {
"optimismISM": "0x70e0bA845a1A0F2DA3359C97E0285013525FFC49",
"optimismMessageHook": "0xfB12F7170FF298CDed84C793dAb9aBBEcc01E798"
"optimismMessageHook": "0xE2b5bDE7e80f89975f7229d78aD9259b2723d11F"
},
"test2": {
"optimismISM": "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00",
"optimismISM": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"optimismMessageHook": "0x2bdCC0de6bE1f7D2ee689a0342D76F52E8EFABa3",
"testRecipient": "0x36C02dA8a0983159322a80FFE9F24b1acfF8B570"
"testRecipient": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf"
}
}
1 change: 1 addition & 0 deletions typescript/infra/config/environments/test/igp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function getGasOracles(local: TestChains) {
export const igp: ChainMap<OverheadIgpConfig> = objMap(
owners,
(chain, owner) => {
console.log('getGasOracle: ', getGasOracles(chain));
return {
owner,
beneficiary: owner,
Expand Down
2 changes: 2 additions & 0 deletions typescript/infra/config/environments/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { agents } from './agent';
import { testConfigs } from './chains';
import { core } from './core';
import { storageGasOracleConfig } from './gas-oracle';
import { hooks } from './hooks';
import { igp } from './igp';
import { infra } from './infra';
import { owners } from './owners';
Expand All @@ -18,6 +19,7 @@ export const environment: EnvironmentConfig = {
agents,
core,
igp,
hooks,
owners,
infra,
// NOTE: Does not work from hardhat.config.ts
Expand Down
7 changes: 7 additions & 0 deletions typescript/infra/config/environments/test/owners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ const OWNER_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
export const owners: ChainMap<types.Address> = Object.fromEntries(
chainNames.map((chain) => [chain, OWNER_ADDRESS]),
);

// hooks only need test1 and test2
export const ownersForHooks: ChainMap<types.Address> = Object.fromEntries(
chainNames
.filter((chain) => chain === 'test1' || chain === 'test2')
.map((chain) => [chain, OWNER_ADDRESS]),
);
1 change: 1 addition & 0 deletions typescript/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"repository": "https://github.com/hyperlane-xyz/hyperlane-monorepo",
"scripts": {
"deploy-core": "ts-node scripts/deploy.ts -e test --context hyperlane -m core",
"deploy-core-for-hooks": "ts-node scripts/deploy.ts -e test --context hyperlane -m core -h true",
"deploy-igp": "ts-node scripts/deploy.ts -e test --context hyperlane -m igp",
"deploy-ism": "ts-node scripts/deploy.ts -e test --context hyperlane -m ism",
"deploy-hook": "ts-node scripts/deploy.ts -e test --context hyperlane -m hook",
Expand Down
39 changes: 20 additions & 19 deletions typescript/infra/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ import { readJSON } from '../src/utils/utils';

import {
Modules,
SDK_MODULES, // Sides,
SDK_MODULES,
getArgs,
getContractAddressesSdkFilepath,
getEnvironmentConfig,
getEnvironmentDirectory,
getModuleDirectory,
getRouterConfig,
withHooks,
withModuleAndFork,
} from './utils';

async function main() {
const { module, fork, environment } = await withModuleAndFork(getArgs()).argv;
const { module, fork, environment, hooks } = await withHooks(
withModuleAndFork(getArgs()),
).argv;
const envConfig = getEnvironmentConfig(environment);
console.log('environment: ', deployEnvToSdkEnv[environment]);

const multiProvider = await envConfig.getMultiProvider();

console.log('Hooks: ', hooks);

if (fork) {
await useLocalProvider(multiProvider, fork);

Expand All @@ -59,10 +62,18 @@ async function main() {

let config: ChainMap<unknown> = {};
let deployer: HyperlaneDeployer<any, any>;

console.log('FULL CONFIG: ', envConfig);
if (module === Modules.ISM_FACTORY) {
config = objMap(envConfig.core, (chain) => true);
deployer = new HyperlaneIsmFactoryDeployer(multiProvider);
} else if (module === Modules.CORE) {
}
// else if (module === Modules.CORE && hooks) {
// config['test1'] = envConfig.core.test1;
// config['test2'] = envConfig.core.test2;
// }
else if (module === Modules.CORE) {
// config = envConfig.core;
const hookProvider = new MultiProvider(testConfigs);

// anvil --fork-url https://rpc.ankr.com/optimism --chain-id 31337 --port 8546
Expand All @@ -86,8 +97,6 @@ async function main() {
config['test1'] = envConfig.core.test1;
config['test2'] = envConfig.core.test2;

// config = { ...envConfig.core.test1, ...envConfig.core.test2};

const ismFactory = HyperlaneIsmFactory.fromEnvironment(
deployEnvToSdkEnv[environment],
hookProvider,
Expand All @@ -110,18 +119,10 @@ async function main() {
opForked.getSigner('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'),
);

config = {
test1: {
nativeType: 'hook',
nativeBridge: '0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1',
remoteIsm: '0x4c5859f0f772848b2d91f1d83e2fe57935348029', // dummy
destinationDomain: 10,
},
test2: {
nativeType: 'ism',
nativeBridge: '0x4200000000000000000000000000000000000007',
},
};
if (!envConfig.hooks) {
throw new Error(`No hook config for ${environment}`);
}
config = envConfig.hooks;
deployer = new HyperlaneHookDeployer(hookProvider);
deployer;
} else if (module === Modules.INTERCHAIN_GAS_PAYMASTER) {
Expand Down
12 changes: 7 additions & 5 deletions typescript/infra/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export enum Modules {
TEST_RECIPIENT = 'testrecipient',
}

export enum Sides {
ISM = 'ism',
HOOK = 'hook',
}

export const SDK_MODULES = [
Modules.ISM_FACTORY,
Modules.CORE,
Expand Down Expand Up @@ -84,6 +79,13 @@ export function withContext<T>(args: yargs.Argv<T>) {
.demandOption('context');
}

export function withHooks<T>(args: yargs.Argv<T>) {
return args
.describe('hooks', 'hooks to deploy')
.boolean('hooks')
.alias('h', 'hook');
}

export function withAgentRole<T>(args: yargs.Argv<T>) {
return args
.describe('role', 'agent roles')
Expand Down
2 changes: 2 additions & 0 deletions typescript/infra/src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type EnvironmentConfig = {
// Each AgentConfig, keyed by the context
agents: Partial<Record<Contexts, RootAgentConfig>>;
core: ChainMap<CoreConfig>;
// make hooks optional
hooks?: ChainMap<any>;
igp: ChainMap<OverheadIgpConfig>;
owners: ChainMap<types.Address>;
infra: InfrastructureConfig;
Expand Down
8 changes: 4 additions & 4 deletions typescript/sdk/src/consts/chainMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export const bsctestnet: ChainMetadata = {
protocol: ProtocolType.Ethereum,
displayName: 'BSC Testnet',
nativeToken: bnbToken,
publicRpcUrls: [{ http: 'https://data-seed-prebsc-1-s3.binance.org:8547s' }],
publicRpcUrls: [{ http: 'https://data-seed-prebsc-1-s3.binance.org:8545s' }],
blockExplorers: [
{
name: 'BscScan',
Expand Down Expand Up @@ -697,7 +697,7 @@ export const test1: ChainMetadata = {
protocol: ProtocolType.Ethereum,
displayName: 'Test 1',
nativeToken: etherToken,
publicRpcUrls: [{ http: 'http://localhost:8546' }],
publicRpcUrls: [{ http: 'http://localhost:8545' }],
blockExplorers: [],
blocks: {
confirmations: 1,
Expand All @@ -713,7 +713,7 @@ export const test2: ChainMetadata = {
protocol: ProtocolType.Ethereum,
displayName: 'Test 2',
nativeToken: etherToken,
publicRpcUrls: [{ http: 'http://localhost:8547' }],
publicRpcUrls: [{ http: 'http://localhost:8545' }],
blockExplorers: [],
blocks: {
confirmations: 1,
Expand All @@ -729,7 +729,7 @@ export const test3: ChainMetadata = {
protocol: ProtocolType.Ethereum,
displayName: 'Test 3',
nativeToken: etherToken,
publicRpcUrls: [{ http: 'http://localhost:8547' }],
publicRpcUrls: [{ http: 'http://localhost:8545' }],
blockExplorers: [],
blocks: {
confirmations: 1,
Expand Down
1 change: 0 additions & 1 deletion typescript/sdk/src/deploy/HyperlaneDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export abstract class HyperlaneDeployer<
const signerAddress = await this.multiProvider.getSignerAddress(chain);
const fromString = signerUrl || signerAddress;
this.logger(`Deploying to ${chain} from ${fromString}`);
this.logger('test123');
this.startingBlockNumbers[chain] = await this.multiProvider
.getProvider(chain)
.getBlockNumber();
Expand Down
4 changes: 0 additions & 4 deletions typescript/sdk/src/hook/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import type { types } from '@hyperlane-xyz/utils';

import { ChainName } from '../types';

export enum NativeType {
HOOK = 'hook',
ISM = 'ism',
}

export type MessageHookConfig = {
chain: ChainName;
nativeType: NativeType.HOOK;
nativeBridge: types.Address;
remoteIsm: types.Address;
destinationDomain: number;
};

export type NoMetadataIsmConfig = {
chain: ChainName;
nativeType: NativeType.ISM;
nativeBridge: types.Address;
};
Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export { TestCoreDeployer } from './core/TestCoreDeployer';
export { CoreFactories, coreFactories } from './core/contracts';
export { HyperlaneLifecyleEvent } from './core/events';
export { CoreConfig, CoreViolationType } from './core/types';
export { HookConfig } from './hook/types';
export { HyperlaneAppChecker } from './deploy/HyperlaneAppChecker';
export { DeployerOptions, HyperlaneDeployer } from './deploy/HyperlaneDeployer';
export {
Expand Down
Loading

0 comments on commit 60dad87

Please sign in to comment.