Skip to content

Commit

Permalink
fix onAcknowledgementPacket func sig and callback
Browse files Browse the repository at this point in the history
  • Loading branch information
WenweiX committed Aug 2, 2023
1 parent 142feac commit b752e45
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ contract Dispatcher is IbcDispatcher, Ownable {
nextSequenceAck[address(receiver)][packet.src.channelId] = packet.sequence + 1;
}

receiver.onAcknowledgementPacket(packet);
receiver.onAcknowledgementPacket(packet, ackPacket);

// delete packet commitment to avoid double ack
delete sendPacketCommitment[address(receiver)][packet.src.channelId][packet.sequence];
Expand Down
2 changes: 1 addition & 1 deletion contracts/IbcReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IbcReceiver {

function onRecvPacket(IbcPacket calldata packet) external returns (AckPacket memory ackPacket);

function onAcknowledgementPacket(IbcPacket calldata packet) external;
function onAcknowledgementPacket(IbcPacket calldata packet, AckPacket calldata ack) external;

function onTimeoutPacket(IbcPacket calldata packet) external;

Expand Down
9 changes: 6 additions & 3 deletions contracts/Mars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import './IbcReceiver.sol';
import './IbcDispatcher.sol';

contract Mars is IbcReceiver, Ownable {
// received packet as chain B
IbcPacket[] public recvedPackets;
IbcPacket[] public ackPackets;
// received ack packet as chain A
AckPacket[] public ackPackets;
// received timeout packet as chain A
IbcPacket[] public timeoutPackets;
bytes32[] public connectedChannels;

Expand All @@ -19,8 +22,8 @@ contract Mars is IbcReceiver, Ownable {
return AckPacket(true, abi.encodePacked('{ "account": "account", "reply": "got the message" }'));
}

function onAcknowledgementPacket(IbcPacket calldata packet) external {
ackPackets.push(packet);
function onAcknowledgementPacket(IbcPacket calldata packet, AckPacket calldata ack) external {
ackPackets.push(ack);
}

function onTimeoutPacket(IbcPacket calldata packet) external {
Expand Down
4 changes: 4 additions & 0 deletions test/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ contract DispatcherAckPacketTest is PacketSenderTest {
vm.expectEmit(true, true, false, true, address(dispatcher));
emit Acknowledgement(address(mars), channelId, sentPacket.sequence);
dispatcher.acknowledgement(IbcReceiver(mars), sentPacket, ackPacket, validProof);
// confirm dapp recieved the ack
(bool success, bytes memory data) = mars.ackPackets(sentPacket.sequence - 1);
assertEq(success, ackPacket.success);
assertEq(data, ackPacket.data);
}
}

Expand Down

0 comments on commit b752e45

Please sign in to comment.