Skip to content

Commit

Permalink
comment out close channel support
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopernas committed Feb 19, 2024
1 parent 6e381f5 commit 20b7284
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
41 changes: 21 additions & 20 deletions contracts/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,27 @@ contract Dispatcher is IbcDispatcher, IbcEventsEmitter, Ownable, Ibc {
* The dApp's onCloseIbcChannel callback is invoked.
* dApp should throw an error if the channel should not be closed.
*/
function onCloseIbcChannel(address portAddress, bytes32 channelId, Ics23Proof calldata proof) external {
// verify VIBC/IBC hub chain has processed ChanCloseConfirm event
consensusStateManager.verifyMembership(
proof,
bytes('channel/path/to/be/added/here'),
bytes('expected channel bytes constructed from params. Channel.State = {Closed(_Pending?)}')
);

// ensure port owns channel
Channel memory channel = portChannelMap[portAddress][channelId];
if (channel.counterpartyChannelId == bytes32(0)) {
revert channelNotOwnedByPortAddress();
}

// confirm with dApp by calling its callback
IbcChannelReceiver reciever = IbcChannelReceiver(portAddress);
reciever.onCloseIbcChannel(channelId, channel.counterpartyPortId, channel.counterpartyChannelId);
delete portChannelMap[portAddress][channelId];
emit CloseIbcChannel(portAddress, channelId);
}
// FIXME this is commented out to make the contract size smaller. We need to optimise for size
// function onCloseIbcChannel(address portAddress, bytes32 channelId, Ics23Proof calldata proof) external {
// // verify VIBC/IBC hub chain has processed ChanCloseConfirm event
// consensusStateManager.verifyMembership(
// proof,
// bytes('channel/path/to/be/added/here'),
// bytes('expected channel bytes constructed from params. Channel.State = {Closed(_Pending?)}')
// );
//
// // ensure port owns channel
// Channel memory channel = portChannelMap[portAddress][channelId];
// if (channel.counterpartyChannelId == bytes32(0)) {
// revert channelNotOwnedByPortAddress();
// }
//
// // confirm with dApp by calling its callback
// IbcChannelReceiver reciever = IbcChannelReceiver(portAddress);
// reciever.onCloseIbcChannel(channelId, channel.counterpartyPortId, channel.counterpartyChannelId);
// delete portChannelMap[portAddress][channelId];
// emit CloseIbcChannel(portAddress, channelId);
// }

//
// IBC Packet methods
Expand Down
59 changes: 30 additions & 29 deletions test/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,35 +219,36 @@ contract ChannelOpenTestBase is Base {
}
}

contract DispatcherCloseChannelTest is ChannelOpenTestBase {
function test_closeChannelInit_success() public {
vm.expectEmit(true, true, true, true);
emit CloseIbcChannel(address(mars), channelId);
mars.triggerChannelClose(channelId);
}

function test_closeChannelInit_mustOwner() public {
Mars earth = new Mars(dispatcher);
vm.expectRevert(abi.encodeWithSignature('channelNotOwnedBySender()'));
earth.triggerChannelClose(channelId);
}

function test_closeChannelConfirm_success() public {
vm.expectEmit(true, true, true, true);
emit CloseIbcChannel(address(mars), channelId);
dispatcher.onCloseIbcChannel(address(mars), channelId, validProof);
}

function test_closeChannelConfirm_mustOwner() public {
vm.expectRevert(abi.encodeWithSignature('channelNotOwnedByPortAddress()'));
dispatcher.onCloseIbcChannel(address(mars), 'channel-999', validProof);
}

function test_closeChannelConfirm_invalidProof() public {
vm.expectRevert('Invalid dummy membership proof');
dispatcher.onCloseIbcChannel(address(mars), channelId, invalidProof);
}
}
// FIXME this is commented out to make the contract size smaller. We need to optimise for size
// contract DispatcherCloseChannelTest is ChannelOpenTestBase {
// function test_closeChannelInit_success() public {
// vm.expectEmit(true, true, true, true);
// emit CloseIbcChannel(address(mars), channelId);
// mars.triggerChannelClose(channelId);
// }
//
// function test_closeChannelInit_mustOwner() public {
// Mars earth = new Mars(dispatcher);
// vm.expectRevert(abi.encodeWithSignature('channelNotOwnedBySender()'));
// earth.triggerChannelClose(channelId);
// }
//
// function test_closeChannelConfirm_success() public {
// vm.expectEmit(true, true, true, true);
// emit CloseIbcChannel(address(mars), channelId);
// dispatcher.onCloseIbcChannel(address(mars), channelId, validProof);
// }
//
// function test_closeChannelConfirm_mustOwner() public {
// vm.expectRevert(abi.encodeWithSignature('channelNotOwnedByPortAddress()'));
// dispatcher.onCloseIbcChannel(address(mars), 'channel-999', validProof);
// }
//
// function test_closeChannelConfirm_invalidProof() public {
// vm.expectRevert('Invalid dummy membership proof');
// dispatcher.onCloseIbcChannel(address(mars), channelId, invalidProof);
// }
// }

contract DispatcherSendPacketTest is ChannelOpenTestBase {
// default params
Expand Down

0 comments on commit 20b7284

Please sign in to comment.