Skip to content

Commit

Permalink
Rename test files
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Mar 9, 2021
1 parent ed7e699 commit 0d7b317
Show file tree
Hide file tree
Showing 100 changed files with 182 additions and 132 deletions.
2 changes: 2 additions & 0 deletions compiler/tests/compile_errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Tests for contracts that should cause compile errors

#![cfg(feature = "solc-backend")]

use rstest::rstest;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
152 changes: 20 additions & 132 deletions compiler/tests/evm_contracts.rs → compiler/tests/features.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Simple contract tests that narrowly test a given feature

#![cfg(feature = "solc-backend")]
use evm_runtime::Handler;
use primitive_types::{
Expand All @@ -13,6 +15,24 @@ use fe_common::utils::keccak;
use utils::ToBeBytes;
use utils::*;

pub fn deploy_contract(
executor: &mut Executor,
fixture: &str,
contract_name: &str,
init_params: &[ethabi::Token],
) -> ContractHarness {
utils::deploy_contract(
executor,
&format!("features/{}", fixture),
contract_name,
init_params,
)
}

pub fn load_contract(address: H160, fixture: &str, contract_name: &str) -> ContractHarness {
utils::load_contract(address, &format!("features/{}", fixture), contract_name)
}

#[test]
fn test_to_2s_complement() {
let minus_three = U256::from_dec_str(
Expand Down Expand Up @@ -896,138 +916,6 @@ fn math() {
});
}

#[test]
fn data_copying_stress() {
with_executor(&|mut executor| {
let harness = deploy_contract(&mut executor, "data_copying_stress.fe", "Foo", &[]);

harness.test_function(
&mut executor,
"set_my_vals",
&[
string_token("my string"),
string_token("my other string"),
uint_token(26),
uint_token(42),
],
None,
);

harness.test_function(&mut executor, "emit_my_event", &[], None);

harness.test_function(&mut executor, "set_to_my_other_vals", &[], None);

harness.test_function(&mut executor, "emit_my_event", &[], None);

let my_array = u256_array_token(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let my_mutated_array = u256_array_token(&[1, 2, 3, 5, 5, 6, 7, 8, 9, 10]);

let my_addrs = address_array_token(&["0", "1", "2"]);
let my_second_addr = address_token("1");

harness.test_function(
&mut executor,
"mutate_and_return",
&[my_array.clone()],
Some(&my_mutated_array),
);

harness.test_function(
&mut executor,
"multiple_references_shared_memory",
&[my_array.clone()],
None,
);

harness.test_function(
&mut executor,
"clone_and_return",
&[my_array.clone()],
Some(&my_array),
);

harness.test_function(
&mut executor,
"clone_mutate_and_return",
&[my_array.clone()],
Some(&my_array),
);

harness.test_function(
&mut executor,
"assign_my_nums_and_return",
&[],
Some(&u256_array_token(&[42, 26, 0, 1, 255])),
);

harness.test_function(&mut executor, "set_my_addrs", &[my_addrs], None);
harness.test_function(
&mut executor,
"get_my_second_addr",
&[],
Some(&my_second_addr),
);

harness.events_emitted(
executor,
&[
("MyEvent", &[string_token("my string"), uint_token(26)]),
(
"MyEvent",
&[string_token("my other string"), uint_token(42)],
),
],
);
});
}

#[test]
fn abi_encoding_stress() {
with_executor(&|mut executor| {
let harness = deploy_contract(&mut executor, "abi_encoding_stress.fe", "Foo", &[]);

let my_addrs = address_array_token(&["a", "b", "c", "d", "e"]);
let my_u128 = uint_token(42);
let my_string = string_token("my string");
let my_u8s = u256_array_token(&(0..255).collect::<Vec<_>>());
let my_bool = bool_token(true);
let my_bytes = bytes_token(
iter::repeat("ten bytes.")
.take(10)
.collect::<String>()
.as_str(),
);

harness.test_function(&mut executor, "set_my_addrs", &[my_addrs.clone()], None);
harness.test_function(&mut executor, "get_my_addrs", &[], Some(&my_addrs));

harness.test_function(&mut executor, "set_my_u128", &[my_u128.clone()], None);
harness.test_function(&mut executor, "get_my_u128", &[], Some(&my_u128));

harness.test_function(&mut executor, "set_my_string", &[my_string.clone()], None);
harness.test_function(&mut executor, "get_my_string", &[], Some(&my_string));

harness.test_function(&mut executor, "set_my_u8s", &[my_u8s.clone()], None);
harness.test_function(&mut executor, "get_my_u8s", &[], Some(&my_u8s));

harness.test_function(&mut executor, "set_my_bool", &[my_bool.clone()], None);
harness.test_function(&mut executor, "get_my_bool", &[], Some(&my_bool));

harness.test_function(&mut executor, "set_my_bytes", &[my_bytes.clone()], None);
harness.test_function(&mut executor, "get_my_bytes", &[], Some(&my_bytes));

harness.test_function(&mut executor, "emit_my_event", &[], None);

harness.events_emitted(
executor,
&[(
"MyEvent",
&[my_addrs, my_u128, my_string, my_u8s, my_bool, my_bytes],
)],
);
});
}

#[test]
fn two_contracts() {
with_executor(&|mut executor| {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions compiler/tests/evm_runtime.rs → compiler/tests/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Tests for the Fe runtime

#![cfg(feature = "solc-backend")]
use fe_compiler::yul::runtime::functions;
use yultsur::*;
Expand Down
158 changes: 158 additions & 0 deletions compiler/tests/stress.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//! Stress tests that test broad behavior

#![cfg(feature = "solc-backend")]
use primitive_types::H160;
use std::iter;

mod utils;
use utils::*;

pub fn deploy_contract(
executor: &mut Executor,
fixture: &str,
contract_name: &str,
init_params: &[ethabi::Token],
) -> ContractHarness {
utils::deploy_contract(
executor,
&format!("stress/{}", fixture),
contract_name,
init_params,
)
}

pub fn load_contract(address: H160, fixture: &str, contract_name: &str) -> ContractHarness {
utils::load_contract(address, &format!("stress/{}", fixture), contract_name)
}

#[test]
fn data_copying_stress() {
with_executor(&|mut executor| {
let harness = deploy_contract(&mut executor, "data_copying_stress.fe", "Foo", &[]);

harness.test_function(
&mut executor,
"set_my_vals",
&[
string_token("my string"),
string_token("my other string"),
uint_token(26),
uint_token(42),
],
None,
);

harness.test_function(&mut executor, "emit_my_event", &[], None);

harness.test_function(&mut executor, "set_to_my_other_vals", &[], None);

harness.test_function(&mut executor, "emit_my_event", &[], None);

let my_array = u256_array_token(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let my_mutated_array = u256_array_token(&[1, 2, 3, 5, 5, 6, 7, 8, 9, 10]);

let my_addrs = address_array_token(&["0", "1", "2"]);
let my_second_addr = address_token("1");

harness.test_function(
&mut executor,
"mutate_and_return",
&[my_array.clone()],
Some(&my_mutated_array),
);

harness.test_function(
&mut executor,
"multiple_references_shared_memory",
&[my_array.clone()],
None,
);

harness.test_function(
&mut executor,
"clone_and_return",
&[my_array.clone()],
Some(&my_array),
);

harness.test_function(
&mut executor,
"clone_mutate_and_return",
&[my_array.clone()],
Some(&my_array),
);

harness.test_function(
&mut executor,
"assign_my_nums_and_return",
&[],
Some(&u256_array_token(&[42, 26, 0, 1, 255])),
);

harness.test_function(&mut executor, "set_my_addrs", &[my_addrs], None);
harness.test_function(
&mut executor,
"get_my_second_addr",
&[],
Some(&my_second_addr),
);

harness.events_emitted(
executor,
&[
("MyEvent", &[string_token("my string"), uint_token(26)]),
(
"MyEvent",
&[string_token("my other string"), uint_token(42)],
),
],
);
});
}

#[test]
fn abi_encoding_stress() {
with_executor(&|mut executor| {
let harness = deploy_contract(&mut executor, "abi_encoding_stress.fe", "Foo", &[]);

let my_addrs = address_array_token(&["a", "b", "c", "d", "e"]);
let my_u128 = uint_token(42);
let my_string = string_token("my string");
let my_u8s = u256_array_token(&(0..255).collect::<Vec<_>>());
let my_bool = bool_token(true);
let my_bytes = bytes_token(
iter::repeat("ten bytes.")
.take(10)
.collect::<String>()
.as_str(),
);

harness.test_function(&mut executor, "set_my_addrs", &[my_addrs.clone()], None);
harness.test_function(&mut executor, "get_my_addrs", &[], Some(&my_addrs));

harness.test_function(&mut executor, "set_my_u128", &[my_u128.clone()], None);
harness.test_function(&mut executor, "get_my_u128", &[], Some(&my_u128));

harness.test_function(&mut executor, "set_my_string", &[my_string.clone()], None);
harness.test_function(&mut executor, "get_my_string", &[], Some(&my_string));

harness.test_function(&mut executor, "set_my_u8s", &[my_u8s.clone()], None);
harness.test_function(&mut executor, "get_my_u8s", &[], Some(&my_u8s));

harness.test_function(&mut executor, "set_my_bool", &[my_bool.clone()], None);
harness.test_function(&mut executor, "get_my_bool", &[], Some(&my_bool));

harness.test_function(&mut executor, "set_my_bytes", &[my_bytes.clone()], None);
harness.test_function(&mut executor, "get_my_bytes", &[], Some(&my_bytes));

harness.test_function(&mut executor, "emit_my_event", &[], None);

harness.events_emitted(
executor,
&[(
"MyEvent",
&[my_addrs, my_u128, my_string, my_u8s, my_bool, my_bytes],
)],
);
});
}

0 comments on commit 0d7b317

Please sign in to comment.