From cbfc544cf12bbfc75c70d5ac54a869e3bcc59301 Mon Sep 17 00:00:00 2001 From: evgenidefi Date: Thu, 19 Dec 2024 17:55:52 +0100 Subject: [PATCH] create deployTransceiver script use migrate function to update immutable specialRelayerAddr of deployed Transceiver contract --- evm/script/DeployTransceiver.s.sol | 35 +++++++++++++++++++ .../WormholeTransceiverState.sol | 4 +++ evm/test/Upgrades.t.sol | 21 +++++++++++ 3 files changed, 60 insertions(+) create mode 100644 evm/script/DeployTransceiver.s.sol diff --git a/evm/script/DeployTransceiver.s.sol b/evm/script/DeployTransceiver.s.sol new file mode 100644 index 000000000..3f96ca2a3 --- /dev/null +++ b/evm/script/DeployTransceiver.s.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: Apache 2 +pragma solidity >=0.8.8 <0.9.0; + +import {Script, console2} from "forge-std/Script.sol"; +import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol"; +import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + +contract DeployWormholeTransceiver is Script { + function run( + address nttManager, + address wormholeCoreBridge, + address wormholeRelayerAddr, + address specialRelayerAddr, + uint8 consistencyLevel, + uint256 gasLimit + ) public { + vm.startBroadcast(); + + WormholeTransceiver implementation = new WormholeTransceiver( + nttManager, + wormholeCoreBridge, + wormholeRelayerAddr, + specialRelayerAddr, + consistencyLevel, + gasLimit + ); + + WormholeTransceiver transceiver = + WormholeTransceiver(address(implementation)); + + console2.log("WormholeTransceiver address:", address(transceiver)); + + vm.stopBroadcast(); + } +} diff --git a/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol b/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol index b58db7dc2..21078fdd5 100644 --- a/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol +++ b/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol @@ -75,6 +75,10 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce _initializeTransceiver(); } + function _migrate() internal virtual override { + _setMigratesImmutables(true); + } + function _initializeTransceiver() internal { TransceiverStructs.TransceiverInit memory init = TransceiverStructs.TransceiverInit({ transceiverIdentifier: WH_TRANSCEIVER_INIT_PREFIX, diff --git a/evm/test/Upgrades.t.sol b/evm/test/Upgrades.t.sol index 6819ee279..d1ce9f3ae 100644 --- a/evm/test/Upgrades.t.sol +++ b/evm/test/Upgrades.t.sol @@ -389,6 +389,27 @@ contract TestUpgrades is Test, IRateLimiterEvents { ); } + function test_specialRelayerMigration() public { + WormholeTransceiver newImplementation = new MockWormholeTransceiverImmutableAllow( + address(nttManagerChain1), + address(wormhole), + address(relayer), + address(0x8C56eE9cd232d23541a697C0eBd3cA597DE3c88D), // new specialRelayer address + FAST_CONSISTENCY_LEVEL, + GAS_LIMIT + ); + + // Perform upgrade which will trigger migration + wormholeTransceiverChain1.upgrade(address(newImplementation)); + + // Verify specialRelayer was set to the expected address + require( + address(wormholeTransceiverChain1.specialRelayer()) == 0x8C56eE9cd232d23541a697C0eBd3cA597DE3c88D, + "SpecialRelayer not set to expected address" + ); + } + + function test_authNttManager() public { // User not owner so this should fail vm.prank(userA);