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

proptest based differential contract testing #578

Merged
merged 2 commits into from
Oct 28, 2021
Merged
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
33 changes: 33 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ docker-wasm-test:

.PHONY: coverage
coverage:
cargo tarpaulin --workspace --all-features --verbose --timeout 120 --exclude-files 'tests/*' --exclude-files 'main.rs' --out xml html
cargo tarpaulin --workspace --all-features --verbose --timeout 120 --exclude-files 'tests/*' --exclude-files 'main.rs' --out xml html -- --skip differential::

.PHONY: clippy
clippy:
Expand Down
43 changes: 43 additions & 0 deletions crates/test-files/fixtures/differential/math_i8.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
contract Foo:

pub fn add(val1: i8, val2: i8) -> i8:
return val1 + val2

pub fn subtract(val1: i8, val2: i8) -> i8:
return val1 - val2

pub fn multiply(val1: i8, val2: i8) -> i8:
return val1 * val2

pub fn divide(val1: i8, val2: i8) -> i8:
return val1 / val2

pub fn pow(val1: i8, val2: u8) -> i8:
return val1 ** val2

pub fn modulo(val1: i8, val2: i8) -> i8:
return val1 % val2

pub fn rightshift(val1: i8, val2: u8) -> i8:
return val1 >> val2

pub fn leftshift(val1: i8, val2: u8) -> i8:
return val1 << val2

pub fn invert(val1: i8) -> i8:
return ~val1

pub fn cast1(val1: i8) -> u8:
return u8(val1)

pub fn cast2(val1: i8) -> u16:
return u16(u8(val1))

pub fn cast3(val1: i8) -> u16:
return u16(i16(val1))

pub fn order_of_operation(val1: i8, val2: i8, val3: u8) -> i8:
return val1 - val2 * (val1 + val2 / 4 * val1 - val2**val3) + val1

pub fn negate(val1: i8) -> i8:
return -val1
58 changes: 58 additions & 0 deletions crates/test-files/fixtures/differential/math_i8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
contract Foo {

function add(int8 val1, int8 val2) public pure returns (int8){
return val1 + val2;
}

function subtract(int8 val1, int8 val2) public pure returns (int8){
return val1 - val2;
}

function multiply(int8 val1, int8 val2) public pure returns (int8){
return val1 * val2;
}

function divide(int8 val1, int8 val2) public pure returns (int8){
return val1 / val2;
}

function pow(int8 val1, uint8 val2) public pure returns (int8) {
return int8(uint8(val1) ** val2);
}

function modulo(int8 val1, int8 val2) public pure returns (int8){
return val1 % val2;
}

function leftshift(int8 val1, uint8 val2) public pure returns (int8){
return val1 << val2;
}

function rightshift(int8 val1, uint8 val2) public pure returns (int8){
return val1 >> val2;
}

function invert(int8 val1) public pure returns (int8){
return ~val1;
}

function cast1(int8 val1) public pure returns (uint8){
return uint8(val1);
}

function cast2(int8 val1) public pure returns (uint16){
return uint16(uint8(val1));
}

function cast3(int8 val1) public pure returns (uint16){
return uint16(int16(val1));
}

function order_of_operation(int8 val1, int8 val2, uint8 val3) public pure returns (int8) {
return val1 - val2 * (val1 + val2 / 4 * val1 - val2**val3) + val1;
}

function negate(int8 val1) public pure returns (int8){
return -val1;
}
}
49 changes: 49 additions & 0 deletions crates/test-files/fixtures/differential/math_u8.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
contract Foo:

pub fn add(val1: u8, val2: u8) -> u8:
return val1 + val2

pub fn subtract(val1: u8, val2: u8) -> u8:
return val1 - val2

pub fn multiply(val1: u8, val2: u8) -> u8:
return val1 * val2

pub fn divide(val1: u8, val2: u8) -> u8:
return val1 / val2

pub fn pow(val1: u8, val2: u8) -> u8:
return val1 ** val2

pub fn modulo(val1: u8, val2: u8) -> u8:
return val1 % val2

pub fn rightshift(val1: u8, val2: u8) -> u8:
return val1 >> val2

pub fn leftshift(val1: u8, val2: u8) -> u8:
return val1 << val2

pub fn invert(val1: u8) -> u8:
return ~val1

pub fn bit_and(val1: u8, val2: u8) -> u8:
return val1 & val2

pub fn bit_or(val1: u8, val2: u8) -> u8:
return val1 | val2

pub fn bit_xor(val1: u8, val2: u8) -> u8:
return val1 ^ val2

pub fn cast1(val1: u8) -> i8:
return i8(val1)

pub fn cast2(val1: u8) -> i16:
return i16(i8(val1))

pub fn cast3(val1: u8) -> i16:
return i16(u16(val1))

pub fn order_of_operation(val1: u8, val2: u8) -> u8:
return val1 - val2 * (val1 + val2 / 4 * val1 - val2**val1) + val1
66 changes: 66 additions & 0 deletions crates/test-files/fixtures/differential/math_u8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
contract Foo {

function add(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 + val2;
}

function subtract(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 - val2;
}

function multiply(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 * val2;
}

function divide(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 / val2;
}

function pow(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 ** val2;
}

function modulo(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 % val2;
}

function leftshift(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 << val2;
}

function rightshift(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 >> val2;
}

function invert(uint8 val1) public pure returns (uint8){
return ~val1;
}

function bit_and(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 & val2;
}

function bit_or(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 | val2;
}

function bit_xor(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 ^ val2;
}

function cast1(uint8 val1) public pure returns (int8){
return int8(val1);
}

function cast2(uint8 val1) public pure returns (int16){
return int16(int8(val1));
}

function cast3(uint8 val1) public pure returns (int16){
return int16(uint16(val1));
}

function order_of_operation(uint8 val1, uint8 val2) public pure returns (uint8){
return val1 - val2 * (val1 + val2 / 4 * val1 - val2**val1) + val1;
}
}
8 changes: 8 additions & 0 deletions crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ wasm-bindgen-test = "0.3.24"

[features]
solc-backend = ["fe-yulc/solc-backend"]

[dev-dependencies.proptest]
version = "1.0.0"
# The default feature set includes things like process forking which are not
# supported in Web Assembly.
default-features = false
# Enable using the `std` crate.
features = ["std"]
8 changes: 8 additions & 0 deletions crates/tests/proptest-regressions/differential.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 71897591107cbd3f0d248e1ecbece406820f797206e4f43ea02d53a1ebc5ad92 # shrinks to val = 0, val2 = 0, val3 = 128, val4 = 0
cc 6f70182204124ed76e435a25baf2365d922abac6cb4647dcb86cdd4b339fab31 # shrinks to val = -128, val2 = 0, val3 = 0, val4 = 0
Loading