Skip to content

Commit

Permalink
add dispatcher setter to uch
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed Apr 17, 2024
1 parent 221481a commit 881e47a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions contracts/core/UniversalChannelHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ contract UniversalChannelHandler is IbcReceiverBaseUpgradeable, IbcUniversalChan

function onChanOpenConfirm(bytes32 channelId) external onlyIbcDispatcher {}

function setDispatcher(IbcDispatcher _dispatcher) external onlyOwner {
dispatcher = _dispatcher;
}

function _connectChannel(bytes32 channelId, string calldata version)
internal
returns (string memory checkedVersion)
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IUniversalChannelHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ interface IUniversalChannelHandler is IbcUniversalChannelMW {
string calldata counterpartyPortIdentifier
) external;
function closeChannel(bytes32 channelId) external;
function connectedChannels(uint256) external view returns (bytes32);
function setDispatcher(IbcDispatcher dispatcher) external;
function dispatcher() external returns (IbcDispatcher dispatcher);
function connectedChannels(uint256) external view returns (bytes32 channel);
}
8 changes: 4 additions & 4 deletions contracts/interfaces/IbcReceiverUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ contract IbcReceiverBaseUpgradeable is OwnableUpgradeable {
_disableInitializers();
}

/// This function is called for plain Ether transfers, i.e. for every call with empty calldata.
// An empty function body is sufficient to receive packet fee refunds.
receive() external payable {}

/**
* @dev initializer function that takes an IbcDispatcher address and grants the IBC_ROLE to the Polymer IBC
* Dispatcher.
Expand All @@ -38,8 +42,4 @@ contract IbcReceiverBaseUpgradeable is OwnableUpgradeable {
__Ownable_init();
dispatcher = _dispatcher;
}

/// This function is called for plain Ether transfers, i.e. for every call with empty calldata.
// An empty function body is sufficient to receive packet fee refunds.
receive() external payable {}
}
23 changes: 23 additions & 0 deletions test/universal.channel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@ contract UniversalChannelPacketTest is Base, IbcMwEventsEmitter {
verifyTimeoutFlow(5, mwBitmap);
}

function test_uch_new_dispatcher_set_ok() public {
IUniversalChannelHandler uch = eth1.ucHandlerProxy();
vm.startPrank(address(eth1)); // Prank eth1 since that address is the owner
(IDispatcher newDispatcher,) = deployDispatcherProxyAndImpl("polyibc.new.", dummyConsStateManager);
assertFalse(
address(uch.dispatcher()) == address(newDispatcher), "new dispatcher in uch test not setup correctly"
);
uch.setDispatcher(newDispatcher);
assertEq(address(uch.dispatcher()), address(newDispatcher), "new dispatcher not set correctly in uch");
vm.stopPrank();
}

function test_nonOwner_cannot_set_uch_dispatcher() public {
IUniversalChannelHandler uch = eth1.ucHandlerProxy();
address notOwner = vm.addr(1);
vm.startPrank(notOwner);
(IDispatcher newDispatcher,) = deployDispatcherProxyAndImpl("polyibc.new.", dummyConsStateManager);

vm.expectRevert("Ownable: caller is not the owner");
uch.setDispatcher(newDispatcher);
vm.stopPrank();
}

/**
* Test packet flow from chain A to chain B via UniversalChannel MW and optionally other MW that sits on top of
* UniversalChannel MW.
Expand Down

0 comments on commit 881e47a

Please sign in to comment.