-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from hyperledger-labs/mock-app
Introduce Mock app and fix commitment of `nextSequenceRecv` Signed-off-by: Jun Kimura <[email protected]>
- Loading branch information
Showing
14 changed files
with
873 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.9; | ||
|
||
import "../commons/IBCAppBase.sol"; | ||
import "../../core/05-port/IIBCModule.sol"; | ||
import "../../core/25-handler/IBCHandler.sol"; | ||
import "./IBCMockLib.sol"; | ||
|
||
contract IBCMockApp is IBCAppBase { | ||
IBCHandler ibcHandler; | ||
|
||
constructor(IBCHandler ibcHandler_) { | ||
ibcHandler = ibcHandler_; | ||
} | ||
|
||
function ibcAddress() public view virtual override returns (address) { | ||
return address(ibcHandler); | ||
} | ||
|
||
function sendPacket( | ||
string calldata message, | ||
string calldata sourcePort, | ||
string calldata sourceChannel, | ||
Height.Data calldata timeoutHeight, | ||
uint64 timeoutTimestamp | ||
) external { | ||
ibcHandler.sendPacket(sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, bytes(message)); | ||
} | ||
|
||
function onRecvPacket(Packet.Data calldata packet, address) | ||
external | ||
override | ||
onlyIBC | ||
returns (bytes memory acknowledgement) | ||
{ | ||
if (keccak256(packet.data) == keccak256(IBCMockLib.MOCK_PACKET_DATA)) { | ||
return IBCMockLib.SUCCESSFUL_ACKNOWLEDGEMENT_JSON; | ||
} else if (keccak256(packet.data) == keccak256(IBCMockLib.MOCK_ASYNC_PACKET_DATA)) { | ||
return bytes(""); | ||
} else { | ||
return IBCMockLib.FAILED_ACKNOWLEDGEMENT_JSON; | ||
} | ||
} | ||
|
||
function onAcknowledgementPacket(Packet.Data calldata packet, bytes calldata acknowledgement, address) | ||
external | ||
virtual | ||
override | ||
onlyIBC | ||
{ | ||
if (keccak256(packet.data) == keccak256(IBCMockLib.MOCK_PACKET_DATA)) { | ||
require(keccak256(acknowledgement) == keccak256(IBCMockLib.SUCCESSFUL_ACKNOWLEDGEMENT_JSON)); | ||
} else if (keccak256(packet.data) == keccak256(IBCMockLib.MOCK_ASYNC_PACKET_DATA)) { | ||
require(acknowledgement.length == 0); | ||
} else { | ||
require(keccak256(acknowledgement) == keccak256(IBCMockLib.FAILED_ACKNOWLEDGEMENT_JSON)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.9; | ||
|
||
library IBCMockLib { | ||
bytes public constant MOCK_PACKET_DATA = bytes("mock packet data"); | ||
bytes public constant MOCK_FAIL_PACKET_DATA = bytes("mock failed packet data"); | ||
bytes public constant MOCK_ASYNC_PACKET_DATA = bytes("mock async packet data"); | ||
|
||
bytes public constant SUCCESSFUL_ACKNOWLEDGEMENT_JSON = bytes('{"result":"bW9jayBhY2tub3dsZWRnZW1lbnQ="}'); | ||
bytes public constant FAILED_ACKNOWLEDGEMENT_JSON = bytes('{"error":"mock failed acknowledgement"}'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.