-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into disable-gravity-bridge
Signed-off-by: yihuang <[email protected]>
- Loading branch information
Showing
53 changed files
with
1,773 additions
and
3,103 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 |
---|---|---|
@@ -1,46 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >0.6.6; | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {IBankModule} from "./src/Bank.sol"; | ||
|
||
contract TestBank is ERC20 { | ||
address constant bankContract = 0x0000000000000000000000000000000000000064; | ||
IBankModule bank = IBankModule(bankContract); | ||
|
||
constructor() public ERC20("Bitcoin MAX", "MAX") { | ||
_mint(msg.sender, 100000000000000000000000000); | ||
} | ||
function encodeMint(uint256 amount) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature("mint(address,uint256)", msg.sender, amount); | ||
} | ||
function moveToNative(uint256 amount) public { | ||
|
||
function moveToNative(uint256 amount) public returns (bool) { | ||
_burn(msg.sender, amount); | ||
(bool result, ) = bankContract.call(encodeMint(amount)); | ||
require(result, "native call"); | ||
} | ||
function encodeBurn(uint256 amount) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature("burn(address,uint256)", msg.sender, amount); | ||
return bank.mint(msg.sender, amount); | ||
} | ||
function moveFromNative(uint256 amount) public { | ||
(bool result, ) = bankContract.call(encodeBurn(amount)); | ||
|
||
function moveFromNative(uint256 amount) public returns (bool) { | ||
bool result = bank.burn(msg.sender, amount); | ||
require(result, "native call"); | ||
_mint(msg.sender, amount); | ||
return result; | ||
} | ||
function encodeBalanceOf(address addr) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature("balanceOf(address,address)", address(this), addr); | ||
} | ||
|
||
function nativeBalanceOf(address addr) public returns (uint256) { | ||
(bool result, bytes memory data) = bankContract.call(encodeBalanceOf(addr)); | ||
require(result, "native call"); | ||
return abi.decode(data, (uint256)); | ||
return bank.balanceOf(address(this), addr); | ||
} | ||
|
||
function moveToNativeRevert(uint256 amount) public { | ||
moveToNative(amount); | ||
revert("test"); | ||
} | ||
function encodeTransfer(address recipient, uint256 amount) internal view returns (bytes memory) { | ||
return abi.encodeWithSignature("transfer(address,address,uint256)", msg.sender, recipient, amount); | ||
} | ||
function nativeTransfer(address recipient, uint256 amount) public { | ||
|
||
function nativeTransfer(address recipient, uint256 amount) public returns (bool) { | ||
_transfer(msg.sender, recipient, amount); | ||
(bool result, ) = bankContract.call(encodeTransfer(recipient, amount)); | ||
require(result, "native transfer"); | ||
return bank.transfer(msg.sender, recipient, amount); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../x/cronos/events/bindings/src |
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.