Skip to content

Commit

Permalink
add test for recursive depth
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 28, 2024
1 parent 001c76d commit 4de2df4
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 209 deletions.
25 changes: 23 additions & 2 deletions x/evm/contracts/counter/Counter.go

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions x/evm/contracts/counter/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.24;

import "../i_ibc_async_callback/IIBCAsyncCallback.sol";
import "../i_cosmos/ICosmos.sol";
import "../strings/Strings.sol";

contract Counter is IIBCAsyncCallback {
uint256 public count;
Expand Down Expand Up @@ -39,4 +40,36 @@ contract Counter is IIBCAsyncCallback {
function get_blockhash(uint64 n) external view returns (bytes32) {
return blockhash(n);
}

function recursive(uint64 n) public {
if (n == 0) {
return;
}

COSMOS_CONTRACT.execute_cosmos(_recursive(n));

// to test branching
COSMOS_CONTRACT.execute_cosmos(_recursive(n));
}

function _recursive(uint64 n) internal returns (string memory message) {
message = string(
abi.encodePacked(
'{"@type": "/minievm.evm.v1.MsgCall",',
'"sender": "',
COSMOS_CONTRACT.to_cosmos_address(address(this)),
'",',
'"contract_addr": "',
Strings.toHexString(address(this)),
'",',
'"input": "',
Strings.toHexString(
abi.encodePacked(this.recursive.selector, abi.encode(n - 1))
),
'",',
'"value": "0",',
'"access_list": []}'
)
);
}
}
2 changes: 1 addition & 1 deletion x/evm/contracts/erc20_wrapper/ERC20Wrapper.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "../util/Strings.sol";
import "../strings/Strings.sol";
import "../i_cosmos/ICosmos.sol";
import "../erc20_factory/ERC20Factory.sol";
import "../i_erc20/IERC20.sol";
Expand Down
203 changes: 203 additions & 0 deletions x/evm/contracts/strings/Strings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ library Strings {
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);

// uint256 to hex string
function toHexString(
uint256 value,
uint256 length
Expand All @@ -28,6 +29,19 @@ library Strings {
return string(buffer);
}

// bytes to hex string
function toHexString(bytes memory buffer) internal pure returns (string memory) {
bytes memory converted = new bytes(buffer.length * 2);
bytes memory _base = "0123456789abcdef";

for (uint256 i = 0; i < buffer.length; i++) {
converted[i * 2] = _base[uint8(buffer[i]) / _base.length];
converted[i * 2 + 1] = _base[uint8(buffer[i]) % _base.length];
}

return string(abi.encodePacked("0x", converted));
}

function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
Expand Down
Loading

0 comments on commit 4de2df4

Please sign in to comment.