Skip to content

Commit

Permalink
Add compilers integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy committed Dec 19, 2024
1 parent b6fc372 commit bde4b63
Show file tree
Hide file tree
Showing 11 changed files with 1,294 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

Empty file added crates/zksync/compilers/.lock
Empty file.
7 changes: 5 additions & 2 deletions crates/zksync/compilers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ eyre.workspace = true
walkdir.workspace = true
reqwest.workspace = true
yansi.workspace = true
similar-asserts.workspace = true
fd-lock = "4.0.2"
fs4 = "0.8.2"
dirs = "5"
path-slash = "0.2"

# zk
zksync_types.workspace = true

[dev-dependencies]
similar-asserts.workspace = true
fd-lock = "4.0.2"
tempfile.workspace = true
foundry-test-utils.workspace = true
1 change: 0 additions & 1 deletion crates/zksync/compilers/src/compilers/zksolc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub struct ZkSolcCompiler {
pub solc: SolcCompiler,
}

#[cfg(feature = "project-util")]
impl Default for ZkSolcCompiler {
fn default() -> Self {
let zksolc =
Expand Down
7 changes: 7 additions & 0 deletions crates/zksync/compilers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ pub mod artifacts;
pub mod compilers;
pub mod dual_compiled_contracts;
pub mod libraries;

// TODO: Used in integration tests.
// find out why cargo complains about unused dev_dependency for these cases
#[cfg(test)]
use foundry_test_utils as _;
#[cfg(test)]
use tempfile as _;
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.4.23;

import "../src/test.sol";

contract DemoTest is DSTest {
function test_this() public pure {
require(true);
}
function test_logs() public {
emit log("-- log(string)");
emit log("a string");

emit log("-- log_named_uint(string, uint)");
log_named_uint("uint", 512);

emit log("-- log_named_int(string, int)");
log_named_int("int", -512);

emit log("-- log_named_address(string, address)");
log_named_address("address", address(this));

emit log("-- log_named_bytes32(string, bytes32)");
log_named_bytes32("bytes32", "a string");

emit log("-- log_named_bytes(string, bytes)");
log_named_bytes("bytes", hex"cafefe");

emit log("-- log_named_string(string, string)");
log_named_string("string", "a string");

emit log("-- log_named_decimal_uint(string, uint, uint)");
log_named_decimal_uint("decimal uint", 1.0e18, 18);

emit log("-- log_named_decimal_int(string, int, uint)");
log_named_decimal_int("decimal int", -1.0e18, 18);
}
event log_old_named_uint(bytes32,uint);
function test_old_logs() public {
log_old_named_uint("key", 500);
log_named_bytes32("bkey", "val");
}
function test_trace() public view {
this.echo("string 1", "string 2");
}
function test_multiline() public {
emit log("a multiline\\n" "string");
emit log("a multiline " "string");
log_bytes("a string");
log_bytes("a multiline\n" "string");
log_bytes("a multiline\\n" "string");
emit log(unicode"Ώ");
logs(hex"0000");
log_named_bytes("0x0000", hex"0000");
logs(hex"ff");
}
function echo(string memory s1, string memory s2) public pure
returns (string memory, string memory)
{
return (s1, s2);
}

function prove_this(uint x) public {
log_named_uint("sym x", x);
assertGt(x + 1, 0);
}

function test_logn() public {
assembly {
log0(0x01, 0x02)
log1(0x01, 0x02, 0x03)
log2(0x01, 0x02, 0x03, 0x04)
log3(0x01, 0x02, 0x03, 0x04, 0x05)
}
}

event MyEvent(uint, uint indexed, uint, uint indexed);
function test_events() public {
emit MyEvent(1, 2, 3, 4);
}

function test_asserts() public {
string memory err = "this test has failed!";
emit log("## assertTrue(bool)\n");
assertTrue(false);
emit log("\n");
assertTrue(false, err);

emit log("\n## assertEq(address,address)\n");
assertEq(address(this), msg.sender);
emit log("\n");
assertEq(address(this), msg.sender, err);

emit log("\n## assertEq32(bytes32,bytes32)\n");
assertEq32("bytes 1", "bytes 2");
emit log("\n");
assertEq32("bytes 1", "bytes 2", err);

emit log("\n## assertEq(bytes32,bytes32)\n");
assertEq32("bytes 1", "bytes 2");
emit log("\n");
assertEq32("bytes 1", "bytes 2", err);

emit log("\n## assertEq(uint,uint)\n");
assertEq(uint(0), 1);
emit log("\n");
assertEq(uint(0), 1, err);

emit log("\n## assertEq(int,int)\n");
assertEq(-1, -2);
emit log("\n");
assertEq(-1, -2, err);

emit log("\n## assertEqDecimal(int,int,uint)\n");
assertEqDecimal(-1.0e18, -1.1e18, 18);
emit log("\n");
assertEqDecimal(-1.0e18, -1.1e18, 18, err);

emit log("\n## assertEqDecimal(uint,uint,uint)\n");
assertEqDecimal(uint(1.0e18), 1.1e18, 18);
emit log("\n");
assertEqDecimal(uint(1.0e18), 1.1e18, 18, err);

emit log("\n## assertGt(uint,uint)\n");
assertGt(uint(0), 0);
emit log("\n");
assertGt(uint(0), 0, err);

emit log("\n## assertGt(int,int)\n");
assertGt(-1, -1);
emit log("\n");
assertGt(-1, -1, err);

emit log("\n## assertGtDecimal(int,int,uint)\n");
assertGtDecimal(-2.0e18, -1.1e18, 18);
emit log("\n");
assertGtDecimal(-2.0e18, -1.1e18, 18, err);

emit log("\n## assertGtDecimal(uint,uint,uint)\n");
assertGtDecimal(uint(1.0e18), 1.1e18, 18);
emit log("\n");
assertGtDecimal(uint(1.0e18), 1.1e18, 18, err);

emit log("\n## assertGe(uint,uint)\n");
assertGe(uint(0), 1);
emit log("\n");
assertGe(uint(0), 1, err);

emit log("\n## assertGe(int,int)\n");
assertGe(-1, 0);
emit log("\n");
assertGe(-1, 0, err);

emit log("\n## assertGeDecimal(int,int,uint)\n");
assertGeDecimal(-2.0e18, -1.1e18, 18);
emit log("\n");
assertGeDecimal(-2.0e18, -1.1e18, 18, err);

emit log("\n## assertGeDecimal(uint,uint,uint)\n");
assertGeDecimal(uint(1.0e18), 1.1e18, 18);
emit log("\n");
assertGeDecimal(uint(1.0e18), 1.1e18, 18, err);

emit log("\n## assertLt(uint,uint)\n");
assertLt(uint(0), 0);
emit log("\n");
assertLt(uint(0), 0, err);

emit log("\n## assertLt(int,int)\n");
assertLt(-1, -1);
emit log("\n");
assertLt(-1, -1, err);

emit log("\n## assertLtDecimal(int,int,uint)\n");
assertLtDecimal(-1.0e18, -1.1e18, 18);
emit log("\n");
assertLtDecimal(-1.0e18, -1.1e18, 18, err);

emit log("\n## assertLtDecimal(uint,uint,uint)\n");
assertLtDecimal(uint(2.0e18), 1.1e18, 18);
emit log("\n");
assertLtDecimal(uint(2.0e18), 1.1e18, 18, err);

emit log("\n## assertLe(uint,uint)\n");
assertLe(uint(1), 0);
emit log("\n");
assertLe(uint(1), 0, err);

emit log("\n## assertLe(int,int)\n");
assertLe(0, -1);
emit log("\n");
assertLe(0, -1, err);

emit log("\n## assertLeDecimal(int,int,uint)\n");
assertLeDecimal(-1.0e18, -1.1e18, 18);
emit log("\n");
assertLeDecimal(-1.0e18, -1.1e18, 18, err);

emit log("\n## assertLeDecimal(uint,uint,uint)\n");
assertLeDecimal(uint(2.0e18), 1.1e18, 18);
emit log("\n");
assertLeDecimal(uint(2.0e18), 1.1e18, 18, err);

emit log("\n## assertEq(string,string)\n");
string memory s1 = "string 1";
string memory s2 = "string 2";
assertEq(s1, s2);
emit log("\n");
assertEq(s1, s2, err);

emit log("\n## assertEq0(bytes,bytes)\n");
assertEq0(hex"abcdef01", hex"abcdef02");
log("\n");
assertEq0(hex"abcdef01", hex"abcdef02", err);
}
}

contract DemoTestWithSetUp {
function setUp() public {
}
function test_pass() public pure {
}
}
Loading

0 comments on commit bde4b63

Please sign in to comment.