wormhole/ethereum/forge-test/relayer/TestHelpers.sol

135 lines
5.0 KiB
Solidity
Raw Normal View History

Relayer: Ethereum folder Changes for Merging into Main (#3038) * gRelayer: surrounding files * modification to get compilation * restore devnet * remove generic relayer docker * remove wait for relayer engine * keep build time 20 * sh -> bash * sh -> bash * Remove comment * bash -> sh * Revert "bash -> sh" This reverts commit 5c37e92fa19bbdbefc79c8ee0dbceeb127c53373. * bash->sh * gRelayer: ethereum folder changes for generic-relayer-merge * add eth-devnet * Adds .github because workflow needs to install forge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * Remove unnecessary types from package.json * ts-node * gRelayer: ethereum folder changes for generic-relayer-merge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * remove these changes * Relayer: Natspec documentation in IWormholeRelayer (#3032) * WIP * Fixes * Updated interfaces * remove bash * Forward uses same refund chain id and refund address (#3034) * WIP * Fixes * Forward uses same refund chain id and refund address * Updated interfaces * Remove forge build warnings * Add note to interface for resend * via-ir on unless in Tilt * Correct IWormholeReceiver interface * Wormhole message fee now part of quoteDeliveryPrice (#3043) * Fix to PR 3043 * Remove compiler warning * Relayer/address drew review (#3060) * Fix typo in Create2Factory * Add event for contract upgrades * Prevent registering contract if it is already registered * Prevent allowing unset chainId for default delivery provider governance VAA * memory to calldata for external functions in WormholeRelayerSend * continue memory to calldata for external functions * Fix pricing in delivery provider * Sanity check new default delivery provider isn't 0 address * Don't save vaaKey as local variable * cache the length of array rather than iterate every time for vaaKeys * Replacing memory with calldata in few locations * Remove stale file DeliveryProviderMessages * Remove batch VAA sender script * Remove batch VAA from WormholeSimulator * Wait for a confirmation in deploy scripts * remove unnecessary comments * Fix Delivery Provider Pricing and add a test * remove console logs * Revert "continue memory to calldata for external functions" This reverts commit f322afb6c0bbd09e3d04ab42a90e592ff752f6bf. * Revert "memory to calldata for external functions in WormholeRelayerSend" This reverts commit 42fcaad8842d0c81506c9586d8d0fd98f6bb6ae1. * Revert "Don't save vaaKey as local variable" This reverts commit a9172379c564fd430a083645c1c42c78e014d68d. * Revert "cache the length of array rather than iterate every time for vaaKeys" This reverts commit d61380a9b0c0671e67e3bd5d874ae339e180dd34. * Revert "Replacing memory with calldata in few locations" This reverts commit 94e47b6e72eaaa52ac0ba2980c439180401fafd7. * Revert "Fix typo in Create2Factory" This reverts commit a9f7bdf461945c8abf020007d16bbc6b4301d051. * Update contract addresses for via-ir * Slight improvements to delivery provider implementation * typed errors for delivery provider * enable VIA-IR in CI and not in Tilt * correct contract address for via ir * WormholeRelayerSend and WormholeRelayerDelivery (#3082)
2023-06-13 14:01:43 -07:00
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
import {IDeliveryProvider} from "../../contracts/interfaces/relayer/IDeliveryProviderTyped.sol";
import {DeliveryProvider} from "../../contracts/relayer/deliveryProvider/DeliveryProvider.sol";
import {DeliveryProviderSetup} from
"../../contracts/relayer/deliveryProvider/DeliveryProviderSetup.sol";
import {DeliveryProviderImplementation} from
"../../contracts/relayer/deliveryProvider/DeliveryProviderImplementation.sol";
import {DeliveryProviderProxy} from
"../../contracts/relayer/deliveryProvider/DeliveryProviderProxy.sol";
import {IWormholeRelayer} from "../../contracts/interfaces/relayer/IWormholeRelayerTyped.sol";
import {WormholeRelayer} from "../../contracts/relayer/wormholeRelayer/WormholeRelayer.sol";
import {Create2Factory} from "../../contracts/relayer/create2Factory/Create2Factory.sol";
import {MockGenericRelayer} from "./MockGenericRelayer.sol";
import {MockWormhole} from "./MockWormhole.sol";
import {IWormhole} from "../../contracts/interfaces/IWormhole.sol";
import {WormholeSimulator, FakeWormholeSimulator} from "./WormholeSimulator.sol";
import "../../contracts/libraries/external/BytesLib.sol";
import "forge-std/Test.sol";
import "forge-std/console.sol";
import "forge-std/Vm.sol";
contract TestHelpers {
using BytesLib for bytes;
address private constant VM_ADDRESS =
address(bytes20(uint160(uint256(keccak256("hevm cheat code")))));
Vm public constant vm = Vm(VM_ADDRESS);
WormholeSimulator helperWormholeSimulator;
constructor() {
(, helperWormholeSimulator) = setUpWormhole(1);
}
function registerWormholeRelayerContract(
WormholeRelayer governance,
IWormhole wormhole,
uint16 currentChainId,
uint16 chainId,
bytes32 coreRelayerContractAddress
) public {
bytes32 wormholeRelayerModule =
0x0000000000000000000000000000000000576f726d686f6c6552656c61796572;
bytes memory message = abi.encodePacked(
wormholeRelayerModule, uint8(1), currentChainId, chainId, coreRelayerContractAddress
);
IWormhole.VM memory preSignedMessage = IWormhole.VM({
version: 1,
timestamp: uint32(block.timestamp),
nonce: 0,
emitterChainId: wormhole.governanceChainId(),
emitterAddress: wormhole.governanceContract(),
sequence: 0,
consistencyLevel: 200,
payload: message,
guardianSetIndex: 0,
signatures: new IWormhole.Signature[](0),
hash: bytes32("")
});
bytes memory signed = helperWormholeSimulator.encodeAndSignMessage(preSignedMessage);
governance.registerWormholeRelayerContract(signed);
}
function setUpWormhole(uint16 chainId)
public
returns (IWormhole wormholeContract, WormholeSimulator wormholeSimulator)
{
// deploy Wormhole
MockWormhole wormhole = new MockWormhole({
initChainId: chainId,
initEvmChainId: block.chainid
});
// replace Wormhole with the Wormhole Simulator contract (giving access to some nice helper methods for signing)
wormholeSimulator = new FakeWormholeSimulator(
wormhole
);
wormholeContract = wormhole;
}
function setUpDeliveryProvider(
uint16 chainId
) public returns (DeliveryProvider deliveryProvider) {
vm.prank(msg.sender);
DeliveryProviderSetup deliveryProviderSetup = new DeliveryProviderSetup();
vm.prank(msg.sender);
DeliveryProviderImplementation deliveryProviderImplementation =
new DeliveryProviderImplementation();
vm.prank(msg.sender);
DeliveryProviderProxy myDeliveryProvider = new DeliveryProviderProxy(
address(deliveryProviderSetup),
abi.encodeCall(
DeliveryProviderSetup.setup,
(
address(deliveryProviderImplementation),
chainId
)
)
);
deliveryProvider = DeliveryProvider(address(myDeliveryProvider));
}
function setUpWormholeRelayer(
IWormhole wormhole,
address defaultDeliveryProvider
) public returns (IWormholeRelayer coreRelayer) {
Create2Factory create2Factory = new Create2Factory();
address proxyAddressComputed =
create2Factory.computeProxyAddress(address(this), "0xGenericRelayer");
WormholeRelayer coreRelayerImplementation = new WormholeRelayer(address(wormhole));
bytes memory initCall =
abi.encodeCall(WormholeRelayer.initialize, (defaultDeliveryProvider));
coreRelayer = IWormholeRelayer(
create2Factory.create2Proxy(
"0xGenericRelayer", address(coreRelayerImplementation), initCall
)
);
require(
address(coreRelayer) == proxyAddressComputed, "computed must match actual proxy addr"
);
}
}