Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jun 28, 2024
1 parent 6d15952 commit d7d530f
Show file tree
Hide file tree
Showing 26 changed files with 1,071 additions and 65 deletions.
1 change: 0 additions & 1 deletion contracts/prototypes/zevm/GatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ contract GatewayZEVM is Initializable, OwnableUpgradeable, UUPSUpgradeable {
emit Call(msg.sender, receiver, message);
}


// Deposit foreign coins into ZRC20
function deposit(
address zrc20,
Expand Down
19 changes: 19 additions & 0 deletions contracts/prototypes/zevm/TestZContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../zevm/interfaces/zContract.sol";

contract TestZContract is zContract {
event ContextData(bytes origin, address sender, uint256 chainID, address msgSender, string message);

function onCrossChainCall(
zContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external override {
string memory decodedMessage = abi.decode(message, (string));
emit ContextData(context.origin, context.sender, context.chainID, msg.sender, decodedMessage);
}
}
9 changes: 8 additions & 1 deletion contracts/zevm/ZRC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ contract ZRC20 is IZRC20, IZRC20Metadata, ZRC20Errors {
CoinType public immutable COIN_TYPE;
/// @notice System contract address.
address public SYSTEM_CONTRACT_ADDRESS;
/// @notice Gateway contract address.
address public GATEWAY_CONTRACT_ADDRESS;
/// @notice Gas limit.
uint256 public GAS_LIMIT;
/// @notice Protocol flat fee.
Expand Down Expand Up @@ -76,6 +78,11 @@ contract ZRC20 is IZRC20, IZRC20Metadata, ZRC20Errors {
SYSTEM_CONTRACT_ADDRESS = systemContractAddress_;
}

// TODO: discuss
function setGatewayContractAddress(address gateway) external {
GATEWAY_CONTRACT_ADDRESS = gateway;
}

/**
* @dev ZRC20 name
* @return name as string
Expand Down Expand Up @@ -223,7 +230,7 @@ contract ZRC20 is IZRC20, IZRC20Metadata, ZRC20Errors {
* @return true/false if succeeded/failed.
*/
function deposit(address to, uint256 amount) external override returns (bool) {
if (msg.sender != FUNGIBLE_MODULE_ADDRESS && msg.sender != SYSTEM_CONTRACT_ADDRESS) revert InvalidSender();
if (msg.sender != FUNGIBLE_MODULE_ADDRESS && msg.sender != SYSTEM_CONTRACT_ADDRESS && msg.sender != GATEWAY_CONTRACT_ADDRESS) revert InvalidSender();
_mint(to, amount);
emit Deposit(abi.encodePacked(FUNGIBLE_MODULE_ADDRESS), to, amount);
return true;
Expand Down
2 changes: 2 additions & 0 deletions contracts/zevm/interfaces/IZRC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface IZRC20 {

function PROTOCOL_FLAT_FEE() external view returns (uint256);

function setGatewayContractAddress(address gateway) external;

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Deposit(bytes from, address indexed to, uint256 value);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/prototypes/zevm/sender.sol/sender.go

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

Loading

0 comments on commit d7d530f

Please sign in to comment.