Skip to content

Commit

Permalink
Add aux contracts and helper functions for evm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IAvecilla committed Sep 19, 2024
1 parent ec9da1c commit 4c9e31c
Show file tree
Hide file tree
Showing 5 changed files with 841 additions and 1 deletion.
30 changes: 30 additions & 0 deletions core/tests/ts-integration/contracts/create/TestEVMCreate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IContractDeployer {
function evmCodeHash(address key) external returns (bytes32);

function createEVM(
bytes calldata _initCode
) external payable returns (address newAddress);

function create2EVM(
bytes32 _salt,
bytes calldata _initCode
) external payable returns (address);
}

/// @notice An example of a system contract that be used for local testing.
/// @dev It is not used anywhere except for testing
contract TestEVMCreate {
IContractDeployer deployer = IContractDeployer(address(0x8006));

function create(bytes calldata _code) external {
deployer.createEVM(_code);
}

function create2(bytes32 _salt, bytes calldata _code) external payable {
deployer.create2EVM{value:msg.value}(_salt, _code);
}
}
76 changes: 76 additions & 0 deletions core/tests/ts-integration/contracts/token/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

contract ERC20{
string public symbol;
string public name;
uint8 public decimals;
uint public totalSupply;

mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;

event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);

constructor() {
symbol = "TEST";
name = "Test Coin";
decimals = 18;
totalSupply = 1000000;
balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}


function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}

function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}

function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}

function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}

function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}

function safeAdd(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}

function safeSub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}

function safeMul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}

function safeDiv(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}

}
Loading

0 comments on commit 4c9e31c

Please sign in to comment.