-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: no stateful precompiled contract for ica (#1163)
* register ica * send tx add doc * test send tx * emit event fix decode * pass converter * gen binding * ica event * choose default decorder * Apply suggestions from code review * emit res * adjust emit * pass encode proto msg * fix lint * test * add seq * Revert "add seq" This reverts commit af97a1a. * Revert "pass encode proto msg" This reverts commit 766071f. * avoid fork ibc-go cleanup * test timeout_duration * Update integration_tests/test_upgrade.py Signed-off-by: mmsqe <[email protected]> * test ica rly * cleanup * test multi types * make proto-all * Apply suggestions from code review * test readonly call * fix lint * allow control by contract * pack output * point to log fix * fix call ica * make use of binding rm dup sol * add last seq * cleanup * seq as uint64 * Apply suggestions from code review * update rly * pass raw data into precompile * fix py lint * fix packet data * fix resolve --------- Signed-off-by: mmsqe <[email protected]> Co-authored-by: HuangYi <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,189 additions
and
272 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
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
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
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
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,95 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import {IICAModule} from "./src/ICA.sol"; | ||
|
||
contract TestICA { | ||
address constant icaContract = 0x0000000000000000000000000000000000000066; | ||
IICAModule ica = IICAModule(icaContract); | ||
address account; | ||
uint64 lastAckSeq; | ||
|
||
function encodeRegister(string memory connectionID, string memory version) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature( | ||
"registerAccount(string,string)", | ||
connectionID, msg.sender, version | ||
); | ||
} | ||
|
||
function callRegister(string memory connectionID, string memory version) public returns (bool) { | ||
require(account == address(0) || account == msg.sender, "register fail"); | ||
bool result = ica.registerAccount(connectionID, version); | ||
require(result, "call failed"); | ||
account = msg.sender; | ||
} | ||
|
||
function getAccount() public view returns (address) { | ||
return account; | ||
} | ||
|
||
function delegateRegister(string memory connectionID, string memory version) public returns (bool) { | ||
(bool result,) = icaContract.delegatecall(encodeRegister(connectionID, version)); | ||
require(result, "call failed"); | ||
return true; | ||
} | ||
|
||
function staticRegister(string memory connectionID, string memory version) public returns (bool) { | ||
(bool result,) = icaContract.staticcall(encodeRegister(connectionID, version)); | ||
require(result, "call failed"); | ||
return true; | ||
} | ||
|
||
function encodeQueryAccount(string memory connectionID, address addr) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature( | ||
"queryAccount(string,address)", | ||
connectionID, addr | ||
); | ||
} | ||
|
||
function callQueryAccount(string memory connectionID, address addr) public returns (string memory) { | ||
return ica.queryAccount(connectionID, addr); | ||
} | ||
|
||
function delegateQueryAccount(string memory connectionID, address addr) public returns (string memory) { | ||
(bool result, bytes memory data) = icaContract.delegatecall(encodeQueryAccount(connectionID, addr)); | ||
require(result, "call failed"); | ||
return abi.decode(data, (string)); | ||
} | ||
|
||
function staticQueryAccount(string memory connectionID, address addr) public returns (string memory) { | ||
(bool result, bytes memory data) = icaContract.staticcall(encodeQueryAccount(connectionID, addr)); | ||
require(result, "call failed"); | ||
return abi.decode(data, (string)); | ||
} | ||
|
||
function encodeSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature( | ||
"submitMsgs(string,bytes,uint256)", | ||
connectionID, msg.sender, data, timeout | ||
); | ||
} | ||
|
||
function callSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) { | ||
require(account == msg.sender, "not authorized"); | ||
lastAckSeq = ica.submitMsgs(connectionID, data, timeout); | ||
return lastAckSeq; | ||
} | ||
|
||
function delegateSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) { | ||
(bool result, bytes memory data) = icaContract.delegatecall(encodeSubmitMsgs(connectionID, data, timeout)); | ||
require(result, "call failed"); | ||
lastAckSeq = abi.decode(data, (uint64)); | ||
return lastAckSeq; | ||
} | ||
|
||
function staticSubmitMsgs(string memory connectionID, bytes memory data, uint256 timeout) public returns (uint64) { | ||
(bool result, bytes memory data) = icaContract.staticcall(encodeSubmitMsgs(connectionID, data, timeout)); | ||
require(result, "call failed"); | ||
lastAckSeq = abi.decode(data, (uint64)); | ||
return lastAckSeq; | ||
} | ||
|
||
function getLastAckSeq() public view returns (uint256) { | ||
return lastAckSeq; | ||
} | ||
} |
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
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.