-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Migrate forge create tests to cargo (#551)
* Migrate forge create tests to cargo * Forge fmt --------- Co-authored-by: Jrigada <[email protected]>
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use foundry_test_utils::{forgetest_async, util, ZkSyncNode}; | ||
|
||
forgetest_async!(forge_zk_can_deploy_erc20, |prj, cmd| { | ||
util::initialize(prj.root()); | ||
prj.add_source("ERC20.sol", include_str!("../../../../../testdata/zk/ERC20.sol")).unwrap(); | ||
|
||
let node = ZkSyncNode::start(); | ||
let url = node.url(); | ||
|
||
let private_key = | ||
ZkSyncNode::rich_wallets().next().map(|(_, pk, _)| pk).expect("No rich wallets available"); | ||
|
||
cmd.forge_fuse().args([ | ||
"create", | ||
"--zk-startup", | ||
"./src/ERC20.sol:MyToken", | ||
"--rpc-url", | ||
url.as_str(), | ||
"--private-key", | ||
private_key, | ||
]); | ||
|
||
let (stdout, _) = cmd.output_lossy(); | ||
assert!(stdout.contains("Deployer: ")); | ||
assert!(stdout.contains("Deployed to: ")); | ||
}); | ||
|
||
forgetest_async!(forge_zk_can_deploy_token_receiver, |prj, cmd| { | ||
util::initialize(prj.root()); | ||
prj.add_source( | ||
"TokenReceiver.sol", | ||
include_str!("../../../../../testdata/zk/TokenReceiver.sol"), | ||
) | ||
.unwrap(); | ||
|
||
let node = ZkSyncNode::start(); | ||
let url = node.url(); | ||
|
||
let private_key = | ||
ZkSyncNode::rich_wallets().next().map(|(_, pk, _)| pk).expect("No rich wallets available"); | ||
|
||
cmd.forge_fuse().args([ | ||
"create", | ||
"--zk-startup", | ||
"./src/TokenReceiver.sol:TokenReceiver", | ||
"--rpc-url", | ||
url.as_str(), | ||
"--private-key", | ||
private_key, | ||
]); | ||
|
||
let (stdout, _) = cmd.output_lossy(); | ||
assert!(stdout.contains("Deployer: ")); | ||
assert!(stdout.contains("Deployed to: ")); | ||
}); |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
mod basic; | ||
mod cheats; | ||
mod contracts; | ||
mod create; | ||
mod factory; | ||
mod factory_deps; | ||
mod fork; | ||
|
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,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
contract MyToken { | ||
string public owner; | ||
string public constant name = "MyToken"; | ||
string public constant symbol = "MTK"; | ||
uint8 public constant decimals = 18; | ||
uint256 public totalSupply = 1000000 * (10 ** uint256(decimals)); | ||
mapping(address => uint256) public balanceOf; | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
constructor() { | ||
balanceOf[msg.sender] = totalSupply; | ||
} | ||
|
||
function setTotalSupply(uint256 amount) public { | ||
totalSupply = amount; | ||
} | ||
|
||
function transfer(address to, uint256 amount) public returns (bool) { | ||
require(balanceOf[msg.sender] >= amount, "Not enough tokens"); | ||
balanceOf[msg.sender] -= amount; | ||
balanceOf[to] += amount; | ||
emit Transfer(msg.sender, to, amount); | ||
return true; | ||
} | ||
} |
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,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
interface IMyToken { | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
} | ||
|
||
contract TokenReceiver { | ||
function receiveAndHoldToken(address token, uint256 amount) external { | ||
IMyToken(token).transfer(msg.sender, amount); | ||
} | ||
} |