forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from lambdaclass/evm-integration-tests-new
Evm integration tests new
- Loading branch information
Showing
26 changed files
with
2,875 additions
and
44 deletions.
There are no files selected for viewing
Submodule contracts
updated
49 files
30 changes: 30 additions & 0 deletions
30
core/tests/ts-integration/contracts/create/TestEVMCreate.sol
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,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); | ||
} | ||
} |
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,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; | ||
} | ||
|
||
} |
Oops, something went wrong.