Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage tests for much of solc-expressions #89

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions crates/pyrometer/tests/no_killed_ctxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ use std::env;
mod helpers;
use helpers::*;

#[test]
fn test_assign() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/assign.sol");
let sol = include_str!("./test_data/assign.sol");
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_bitwise() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -10,6 +18,14 @@ fn test_bitwise() {
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_binop() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/bin_op.sol");
let sol = include_str!("./test_data/bin_op.sol");
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_cast() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -18,6 +34,21 @@ fn test_cast() {
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_condop() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/cond_op.sol");
assert_no_parse_errors(path_str);
}

#[test]
fn test_delete() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/delete.sol");
let sol = include_str!("./test_data/delete.sol");
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_dyn_types() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -42,6 +73,14 @@ fn test_function_calls() {
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_literals() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/literals.sol");
let sol = include_str!("./test_data/literals.sol");
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_logical() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand Down Expand Up @@ -82,6 +121,13 @@ fn test_require() {
assert_no_ctx_killed(path_str, sol);
}

#[test]
fn test_require_with_killed() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/require_with_killed.sol");
assert_no_parse_errors(path_str);
}

#[test]
fn test_using() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand Down Expand Up @@ -184,3 +230,11 @@ fn test_repros() {
assert_no_parse_errors(path_str);
}
}

#[test]
fn test_variable() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path_str = format!("{manifest_dir}/tests/test_data/variable.sol");
let sol = include_str!("./test_data/variable.sol");
assert_no_ctx_killed(path_str, sol);
}
20 changes: 20 additions & 0 deletions crates/pyrometer/tests/test_data/assign.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.8.0;

contract Assign {

function doAssignment() public {
// Multi-value LHS (tuple)
(uint x, uint y) = (uint16(1), 2);

// Single value RHS
uint z = 3;

(x, y) = (z, z);

// uint[2] memory a = [uint(1), uint(2)];
// uint[2] memory b = [uint(3), uint(4)];


// (a, b) = (b, a);
}
}
10 changes: 10 additions & 0 deletions crates/pyrometer/tests/test_data/bin_op.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.8.0;

contract BinOp {

function testBinOp(int y) public {
int x = 1;
int z = 5 + x;
int a = x * y;
}
}
10 changes: 10 additions & 0 deletions crates/pyrometer/tests/test_data/cmp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.8.0;

contract Cmp {

function testCmp(int x) public {
uint a = 5;
bool b = (5 < 6) || (5 == 6 && 0 < 1); // Correct the tuple comparison

}
}
53 changes: 53 additions & 0 deletions crates/pyrometer/tests/test_data/cond_op.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pragma solidity ^0.8.0;

contract CondOp {

function if_both_possible(uint x) public returns (uint) {
if (x > 100) {
return 1;
} else {
return 2;
}
}

function if_first_possible() public returns (uint) {
uint x = 101;
if (x > 100) {
return 1;
} else {
return 2;
}
}

function if_second_possible() public returns (uint) {
uint x = 99;
if (x > 100) {
return 1;
} else {
return 2;
}
}

function if_neither_possible(uint x) public returns (uint) {
if (x > 100) {
require(x < 100); // not possible
return 1;
} else {
require(x > 100); // not possible
return 2;
}
return 0;
}


function ternaryParam(uint x) public returns (uint) {
uint y = x > 2 ? 1 : 2;
return y;
}

function ternaryLiteral() public returns (uint) {
uint y = 1 > 2 ? 1 : 2;
"pyro::variable::y::range::[2,2]";
return y;
}
}
Loading
Loading