From bab958e716933df1afaa8035031ae42cda4a9f14 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Wed, 12 Apr 2023 12:01:09 -0600 Subject: [PATCH] test refactoring --- Cargo.lock | 1 + crates/analyzer/tests/analysis.rs | 3 - crates/codegen/src/yul/isel/test.rs | 3 +- crates/library/std/src/evm.fe | 1 - crates/mir/tests/lowering.rs | 3 - .../fixtures/features/address_bytes10_map.fe | 11 -- .../fixtures/features/array_repeat.fe | 14 --- crates/test-files/fixtures/features/arrays.fe | 12 -- .../fixtures/features/base_tuple.fe | 5 - .../test-files/fixtures/features/call_fn.fe | 11 -- crates/test-runner/src/lib.rs | 29 +++-- crates/tests-legacy/src/features.rs | 109 ------------------ crates/tests/Cargo.toml | 1 + .../fixtures/files/address_bytes10_map.fe | 43 +++++++ crates/tests/fixtures/files/array_repeat.fe | 19 +++ crates/tests/fixtures/files/arrays.fe | 102 ++++++++++++++++ .../fixtures/files}/associated_fns.fe | 7 ++ crates/tests/fixtures/files/base_tuple.fe | 10 ++ crates/tests/fixtures/files/call_fn.fe | 52 +++++++++ crates/tests/src/lib.rs | 19 ++- 20 files changed, 266 insertions(+), 189 deletions(-) delete mode 100644 crates/test-files/fixtures/features/address_bytes10_map.fe delete mode 100644 crates/test-files/fixtures/features/array_repeat.fe delete mode 100644 crates/test-files/fixtures/features/arrays.fe delete mode 100644 crates/test-files/fixtures/features/base_tuple.fe delete mode 100644 crates/test-files/fixtures/features/call_fn.fe create mode 100644 crates/tests/fixtures/files/address_bytes10_map.fe create mode 100644 crates/tests/fixtures/files/array_repeat.fe create mode 100644 crates/tests/fixtures/files/arrays.fe rename crates/{test-files/fixtures/features => tests/fixtures/files}/associated_fns.fe (72%) create mode 100644 crates/tests/fixtures/files/base_tuple.fe create mode 100644 crates/tests/fixtures/files/call_fn.fe diff --git a/Cargo.lock b/Cargo.lock index 2ed8a2d7ca..312d01957f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -764,6 +764,7 @@ name = "fe-compiler-tests" version = "0.22.0" dependencies = [ "dir-test", + "fe-common", "fe-driver", "fe-test-runner", ] diff --git a/crates/analyzer/tests/analysis.rs b/crates/analyzer/tests/analysis.rs index 9d4ee524d7..b68e1b5454 100644 --- a/crates/analyzer/tests/analysis.rs +++ b/crates/analyzer/tests/analysis.rs @@ -184,12 +184,9 @@ test_analysis! { erc20_token, "demos/erc20_token.fe"} test_analysis! { guest_book, "demos/guest_book.fe"} test_analysis! { simple_open_auction, "demos/simple_open_auction.fe"} test_analysis! { uniswap, "demos/uniswap.fe"} -test_analysis! { address_bytes10_map, "features/address_bytes10_map.fe"} test_analysis! { abi_decode_complex, "features/abi_decode_complex.fe"} test_analysis! { assert, "features/assert.fe"} -test_analysis! { associated_fns, "features/associated_fns.fe"} test_analysis! { aug_assign, "features/aug_assign.fe"} -test_analysis! { base_tuple, "features/base_tuple.fe"} test_analysis! { call_statement_with_args, "features/call_statement_with_args.fe"} test_analysis! { call_statement_with_args_2, "features/call_statement_with_args_2.fe"} test_analysis! { call_statement_without_args, "features/call_statement_without_args.fe"} diff --git a/crates/codegen/src/yul/isel/test.rs b/crates/codegen/src/yul/isel/test.rs index b040d352f0..9fe6186933 100644 --- a/crates/codegen/src/yul/isel/test.rs +++ b/crates/codegen/src/yul/isel/test.rs @@ -14,6 +14,7 @@ pub fn lower_test(db: &dyn CodegenDb, test: FunctionId) -> yul::Object { .into_iter() .map(yul::Statement::FunctionDefinition) .collect(); + let dep_contracts = context.resolve_contract_dependency(db); let runtime_funcs: Vec<_> = context .runtime .collect_definitions() @@ -34,7 +35,7 @@ pub fn lower_test(db: &dyn CodegenDb, test: FunctionId) -> yul::Object { let object = yul::Object { name, code, - objects: vec![], + objects: dep_contracts, data: dep_constants, }; diff --git a/crates/library/std/src/evm.fe b/crates/library/std/src/evm.fe index c223c85b90..f77bda3824 100644 --- a/crates/library/std/src/evm.fe +++ b/crates/library/std/src/evm.fe @@ -212,7 +212,6 @@ pub unsafe fn mload(offset p: u256) -> u256 { pub unsafe fn mstore(offset p: u256, value v: u256) { __mstore(p, v) } - pub unsafe fn mstore8(offset p: u256, value v: u256) { __mstore8(p, v) } diff --git a/crates/mir/tests/lowering.rs b/crates/mir/tests/lowering.rs index 6e1781aa8e..1658e3ae59 100644 --- a/crates/mir/tests/lowering.rs +++ b/crates/mir/tests/lowering.rs @@ -53,11 +53,8 @@ fn mir_lower_std_lib() { test_lowering! { mir_erc20_token, "demos/erc20_token.fe"} test_lowering! { mir_guest_book, "demos/guest_book.fe"} test_lowering! { mir_uniswap, "demos/uniswap.fe"} -test_lowering! { mir_address_bytes10_map, "features/address_bytes10_map.fe"} test_lowering! { mir_assert, "features/assert.fe"} -test_lowering! { mir_associated_fns, "features/associated_fns.fe"} test_lowering! { mir_aug_assign, "features/aug_assign.fe"} -test_lowering! { mir_base_tuple, "features/base_tuple.fe"} test_lowering! { mir_call_statement_with_args, "features/call_statement_with_args.fe"} test_lowering! { mir_call_statement_with_args_2, "features/call_statement_with_args_2.fe"} test_lowering! { mir_call_statement_without_args, "features/call_statement_without_args.fe"} diff --git a/crates/test-files/fixtures/features/address_bytes10_map.fe b/crates/test-files/fixtures/features/address_bytes10_map.fe deleted file mode 100644 index b008731a5c..0000000000 --- a/crates/test-files/fixtures/features/address_bytes10_map.fe +++ /dev/null @@ -1,11 +0,0 @@ -contract Foo { - bar: Map> - - pub fn read_bar(self, key: address) -> Array { - return self.bar[key].to_mem() - } - - pub fn write_bar(mut self, key: address, value: Array) { - self.bar[key] = value - } -} diff --git a/crates/test-files/fixtures/features/array_repeat.fe b/crates/test-files/fixtures/features/array_repeat.fe deleted file mode 100644 index 0ff87ec8dd..0000000000 --- a/crates/test-files/fixtures/features/array_repeat.fe +++ /dev/null @@ -1,14 +0,0 @@ -contract Foo { - pub fn foo() -> Array { - let mut my_array: Array = [8; 4] - my_array[1] = 42 - return my_array - } - - pub fn bar() { - let mut my_array: Array<(u256, u256), 2> = [(1, 0); 2] - my_array[0].item0 = 4 - assert my_array[0].item0 == 4 - assert my_array[1].item0 == 1 - } -} \ No newline at end of file diff --git a/crates/test-files/fixtures/features/arrays.fe b/crates/test-files/fixtures/features/arrays.fe deleted file mode 100644 index cbd81d2c1d..0000000000 --- a/crates/test-files/fixtures/features/arrays.fe +++ /dev/null @@ -1,12 +0,0 @@ -contract Foo { - my_array: Array - - pub fn get_from_storage(self, index: u256) -> u256 { - return self.my_array[index] - } - - pub fn get_from_memory(index: u256) -> u256 { - let my_array: Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - return my_array[index] - } -} diff --git a/crates/test-files/fixtures/features/base_tuple.fe b/crates/test-files/fixtures/features/base_tuple.fe deleted file mode 100644 index d4b6920cab..0000000000 --- a/crates/test-files/fixtures/features/base_tuple.fe +++ /dev/null @@ -1,5 +0,0 @@ -contract Foo { - pub fn bar(my_num: u256, my_bool: bool) -> (u256, bool) { - return (my_num, my_bool) - } -} diff --git a/crates/test-files/fixtures/features/call_fn.fe b/crates/test-files/fixtures/features/call_fn.fe deleted file mode 100644 index 5b44dce524..0000000000 --- a/crates/test-files/fixtures/features/call_fn.fe +++ /dev/null @@ -1,11 +0,0 @@ -contract Foo { - pub fn __call__(self) { - unsafe { - if __calldataload(0) == 1 { - __revert(0, 0) - } else { - __return(0, 0) - } - } - } -} diff --git a/crates/test-runner/src/lib.rs b/crates/test-runner/src/lib.rs index c7d423d048..4b69691563 100644 --- a/crates/test-runner/src/lib.rs +++ b/crates/test-runner/src/lib.rs @@ -1,9 +1,6 @@ use bytes::Bytes; use colored::Colorize; -use revm::{ - interpreter::{instruction_result::SuccessOrHalt, Contract, DummyHost, Interpreter}, - primitives::{Bytecode, Env, LatestSpec, B160, U256}, -}; +use revm::primitives::{AccountInfo, Bytecode, Env, TransactTo, B160, U256}; use std::fmt::Display; #[derive(Debug, Default)] @@ -69,24 +66,26 @@ impl Display for TestSink { } pub fn execute(name: &str, bytecode: &str, sink: &mut TestSink) -> bool { - let input = Bytes::new(); let bytecode = Bytecode::new_raw(Bytes::copy_from_slice(&hex::decode(bytecode).unwrap())); - let address = B160::from(26); - let caller = B160::from(42); - let value = U256::ZERO; - let contract = Contract::new::(input, bytecode, address, caller, value); - let mut host = DummyHost::new(Env::default()); - let mut interpreter = Interpreter::new(contract, u64::MAX, false); + let mut database = revm::InMemoryDB::default(); + let test_address = B160::from(42); + let test_info = AccountInfo::new(U256::ZERO, 0, bytecode); + database.insert_account_info(test_address, test_info); - let result = interpreter.run::(&mut host); - let reverted = matches!(SuccessOrHalt::from(result), SuccessOrHalt::Success(_)); + let mut env = Env::default(); + env.tx.transact_to = TransactTo::Call(test_address); - if reverted { + let mut evm = revm::new(); + evm.env = env; + evm.database(&mut database); + let result = evm.transact_commit().expect("evm failure"); + + if result.is_success() { sink.inc_success_count(); } else { sink.insert_failure(name, &format!("{result:?}")); }; - reverted + result.is_success() } diff --git a/crates/tests-legacy/src/features.rs b/crates/tests-legacy/src/features.rs index f13fc9382a..bd67755518 100644 --- a/crates/tests-legacy/src/features.rs +++ b/crates/tests-legacy/src/features.rs @@ -234,37 +234,6 @@ fn test_assert() { }) } -#[test] -fn test_arrays() { - with_executor(&|mut executor| { - let harness = deploy_contract(&mut executor, "arrays.fe", "Foo", &[]); - - harness.test_function( - &mut executor, - "get_from_memory", - &[uint_token(9)], - Some(&uint_token(10)), - ); - - validate_revert( - harness.capture_call(&mut executor, "get_from_memory", &[uint_token(10)]), - &encoded_panic_out_of_bounds(), - ); - - harness.test_function( - &mut executor, - "get_from_storage", - &[uint_token(9)], - Some(&uint_token(0)), - ); - - validate_revert( - harness.capture_call(&mut executor, "get_from_storage", &[uint_token(10)]), - &encoded_panic_out_of_bounds(), - ); - }) -} - macro_rules! test_method_return { ($name:ident, $path:expr, $input:expr, $expected:expr) => { #[test] @@ -447,7 +416,6 @@ test_method_return! { radix_octal, "radix_octal.fe", &[], uint_token(0o70) } test_method_return! { radix_binary, "radix_binary.fe", &[], uint_token(0b10) } test_method_return! { map_tuple, "map_tuple.fe", &[uint_token(1234)], uint_token(1234) } test_method_return! { int_literal_coercion, "int_literal_coercion.fe", &[], uint_token(300) } -test_method_return! { associated_fns, "associated_fns.fe", &[uint_token(12)], uint_token(144) } test_method_return! { struct_fns, "struct_fns.fe", &[uint_token(10), uint_token(20)], uint_token(100) } test_method_return! { cast_address_to_u256, "cast_address_to_u256.fe", &[address_token(SOME_ADDRESS)], address_token(SOME_ADDRESS) } test_method_return! { for_loop_with_complex_elem_array, "for_loop_with_complex_elem_array.fe", &[], int_token(222) } @@ -538,37 +506,6 @@ fn test_map(fixture_file: &str) { }) } -#[test] -fn address_bytes10_map() { - with_executor(&|mut executor| { - let harness = deploy_contract(&mut executor, "address_bytes10_map.fe", "Foo", &[]); - - let address1 = address_token("0000000000000000000000000000000000000001"); - let bytes1 = bytes_token("ten bytes1"); - - let address2 = address_token("0000000000000000000000000000000000000002"); - let bytes2 = bytes_token("ten bytes2"); - - harness.test_function( - &mut executor, - "write_bar", - &[address1.clone(), bytes1.clone()], - None, - ); - - harness.test_function( - &mut executor, - "write_bar", - &[address2.clone(), bytes2.clone()], - None, - ); - - harness.test_function(&mut executor, "read_bar", &[address1], Some(&bytes1)); - harness.test_function(&mut executor, "read_bar", &[address2], Some(&bytes2)); - assert_harness_gas_report!(harness); - }) -} - #[test] fn return_builtin_attributes() { let gas_price = 123; @@ -1757,20 +1694,6 @@ fn aug_assign(target: u64, op: &str, value: u64, expected: u64) { }); } -#[test] -fn base_tuple() { - with_executor(&|mut executor| { - let harness = deploy_contract(&mut executor, "base_tuple.fe", "Foo", &[]); - harness.test_function( - &mut executor, - "bar", - &[uint_token(42), bool_token(true)], - Some(&tuple_token(&[uint_token(42), bool_token(true)])), - ); - assert_harness_gas_report!(harness); - }); -} - #[test] fn tuple_destructuring() { with_executor(&|mut executor| { @@ -2104,23 +2027,6 @@ fn intrinsics() { }); } -#[test] -fn call_fn() { - with_executor(&|mut executor| { - let harness = deploy_contract(&mut executor, "call_fn.fe", "Foo", &[]); - - let mut calldata = vec![0; 32]; - - calldata[31] = 1; - harness.test_call_reverts(&mut executor, calldata.clone(), &[]); - - calldata[31] = 0; - harness.test_call_returns(&mut executor, calldata, &[]); - - assert_harness_gas_report!(harness); - }); -} - #[rstest( method, params, @@ -2231,18 +2137,3 @@ fn execution_tests(fixture_file: &str) { assert_harness_gas_report!(harness, fixture_file); }) } - -#[test] -fn array_repeat() { - with_executor(&|mut executor| { - let harness = deploy_contract(&mut executor, "array_repeat.fe", "Foo", &[]); - harness.test_function( - &mut executor, - "foo", - &[], - Some(&uint_array_token(&[8, 42, 8, 8])), - ); - - harness.test_function(&mut executor, "bar", &[], None); - }); -} diff --git a/crates/tests/Cargo.toml b/crates/tests/Cargo.toml index c22b504429..7d4c1ba87e 100644 --- a/crates/tests/Cargo.toml +++ b/crates/tests/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/ethereum/fe" [dependencies] fe-test-runner = {path = "../test-runner", version = "^0.22.0"} fe-driver = {path = "../driver", version = "^0.22.0"} +fe-common = {path = "../common", version = "^0.22.0"} dir-test = "^0.1" [features] diff --git a/crates/tests/fixtures/files/address_bytes10_map.fe b/crates/tests/fixtures/files/address_bytes10_map.fe new file mode 100644 index 0000000000..f0669ec8a6 --- /dev/null +++ b/crates/tests/fixtures/files/address_bytes10_map.fe @@ -0,0 +1,43 @@ +type Bytes10 = Array + +contract Foo { + bar: Map + + pub fn read_bar(self, key: address) -> Bytes10 { + return self.bar[key].to_mem() + } + + pub fn write_bar(mut self, key: address, value: Bytes10) { + self.bar[key] = value + } +} + +#test +unsafe fn test_foo() { + let mut ctx: Context = Context() + let mut foo: Foo = Foo.create(ctx, 0) + + let address1: address = address(0x01) + let address2: address = address(0x02) + let bytes1: Bytes10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + let bytes2: Bytes10 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] + + foo.write_bar(key: address1, value: bytes1) + foo.write_bar(key: address2, value: bytes2) + + assert bytes10_eq(foo.read_bar(key: address1), bytes1) + assert bytes10_eq(foo.read_bar(key: address2), bytes2) +} + +fn bytes10_eq(_ a: Bytes10, _ b: Bytes10) -> bool { + let mut i: u256 = 0 + + while i < 10 { + if a[i] != b[i] { + return false + } + i += 1 + } + + return true +} \ No newline at end of file diff --git a/crates/tests/fixtures/files/array_repeat.fe b/crates/tests/fixtures/files/array_repeat.fe new file mode 100644 index 0000000000..cbb312b941 --- /dev/null +++ b/crates/tests/fixtures/files/array_repeat.fe @@ -0,0 +1,19 @@ +#test +fn foo() { + let mut my_array: Array = [8; 4] + my_array[1] = 42 + assert my_array[0] == 8 + assert my_array[1] == 42 + assert my_array[2] == 8 + assert my_array[3] == 8 +} + +#test +fn bar() { + let mut my_array: Array<(u256, u256), 2> = [(1, 0); 2] + my_array[0].item0 = 4 + assert my_array[0].item0 == 4 + assert my_array[0].item1 == 0 + assert my_array[1].item0 == 1 + assert my_array[2].item1 == 0 +} \ No newline at end of file diff --git a/crates/tests/fixtures/files/arrays.fe b/crates/tests/fixtures/files/arrays.fe new file mode 100644 index 0000000000..578ed75044 --- /dev/null +++ b/crates/tests/fixtures/files/arrays.fe @@ -0,0 +1,102 @@ +use std::evm + +contract Foo { + my_array: Array + + pub fn __init__(mut self) { + self.my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + } + + pub fn get_from_storage(self, index: u256) -> u256 { + return self.my_array[index] + } + + pub fn get_from_memory(index: u256) -> u256 { + let my_array: Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + return my_array[index] + } +} + +#test +unsafe fn test_foo() { + let mut ctx: Context = Context() + let foo: Foo = Foo.create(ctx, 0) + assert foo.get_from_storage(index: 3) == 3 + assert Foo::get_from_memory(index: 3) == 4 +} + +contract ArrayIndexOobDyn { + pub unsafe fn __call__() { + let index: u256 = evm::call_data_load(offset: 0) + let mut my_array: Array = [0, 1, 2, 3] + evm::sstore(offset: 0, value: my_array[index]) + } +} + +const FREE_MEM_PTR: u256 = 1024 +const CALL_GAS: u256 = 100000 + +#test +unsafe fn test_array_oob_dyn() { + let mut ctx: Context = Context() + let array_index_oob: ArrayIndexOobDyn = ArrayIndexOobDyn.create(ctx, value: 0) + let expected_revert_data: Array = [78, 72, 123, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50] + + // store index value + evm::mstore(offset: FREE_MEM_PTR, value: 26) + + // verify that the call reverts + assert evm::call( + gas: CALL_GAS, + addr: address(array_index_oob), + value: 0, + input_offset: FREE_MEM_PTR, + input_len: 32, + output_offset: FREE_MEM_PTR, + output_len: 36 + ) == 0 + + // check the revert data + let mut offset: u256 = FREE_MEM_PTR + + for expected_byte in expected_revert_data { + assert evm::shr(248, evm::mload(offset)) == expected_byte + offset += 1 + } +} + +// The following tests does not pass due absent runtime check. +// Obviously this couild also be a compile-time check. +// +// contract ArrayIndexOobStatic { +// pub unsafe fn __call__() { +// let mut my_array: Array = [0, 1, 2, 3] +// evm::sstore(offset: 0, value: my_array[26]) +// } +// } + +// #test +// unsafe fn test_array_oob_static() { +// let mut ctx: Context = Context() +// let array_index_oob: ArrayIndexOobStatic = ArrayIndexOobStatic.create(ctx, value: 0) +// let expected_revert_data: Array = [78, 72, 123, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50] + +// // verify that the call reverts +// assert evm::call( +// gas: CALL_GAS, +// addr: address(array_index_oob), +// value: 0, +// input_offset: 0, +// input_len: 0, +// output_offset: FREE_MEM_PTR, +// output_len: 36 +// ) == 0 + +// // check the revert data +// let mut offset: u256 = FREE_MEM_PTR + +// for expected_byte in expected_revert_data { +// assert evm::shr(248, evm::mload(offset)) == expected_byte +// offset += 1 +// } +// } diff --git a/crates/test-files/fixtures/features/associated_fns.fe b/crates/tests/fixtures/files/associated_fns.fe similarity index 72% rename from crates/test-files/fixtures/features/associated_fns.fe rename to crates/tests/fixtures/files/associated_fns.fe index 6218813343..da0cfa60a0 100644 --- a/crates/test-files/fixtures/features/associated_fns.fe +++ b/crates/tests/fixtures/files/associated_fns.fe @@ -20,3 +20,10 @@ contract Foo { return Lib::square(x: self.my_struct.x) } } + +#test +unsafe fn test_foo() { + let mut ctx: Context = Context() + let mut foo: Foo = Foo.create(ctx, 0) + assert foo.bar(val: 12) == 144 +} \ No newline at end of file diff --git a/crates/tests/fixtures/files/base_tuple.fe b/crates/tests/fixtures/files/base_tuple.fe new file mode 100644 index 0000000000..e2fcc7924c --- /dev/null +++ b/crates/tests/fixtures/files/base_tuple.fe @@ -0,0 +1,10 @@ +fn bar(_ my_num: u256, _ my_bool: bool) -> (u256, bool) { + return (my_num, my_bool) +} + +#test +fn test_bar() { + let my_tuple: (u256, bool) = bar(42, true) + assert my_tuple.item0 == 42 + assert my_tuple.item1 +} \ No newline at end of file diff --git a/crates/tests/fixtures/files/call_fn.fe b/crates/tests/fixtures/files/call_fn.fe new file mode 100644 index 0000000000..ea905db3e6 --- /dev/null +++ b/crates/tests/fixtures/files/call_fn.fe @@ -0,0 +1,52 @@ +use std::evm + +const FREE_MEM_PTR_BIG: u256 = 1024 +const FREE_MEM_PTR_SMALL: u256 = 128 +const CALL_GAS: u256 = 100000 + +contract Foo { + pub unsafe fn __call__(self, ctx: Context) { + if ctx.msg_sig() == 0x01 { + evm::mstore(offset: FREE_MEM_PTR_SMALL, value: 0x02) + } else if ctx.msg_sig() == 0x03{ + evm::mstore(offset: FREE_MEM_PTR_SMALL, value: 0x04) + } else { + // unknown selector + revert + } + + evm::return_mem(offset: FREE_MEM_PTR_SMALL, len: 32) + } +} + +#test +unsafe fn test_foo() { + let mut ctx: Context = Context() + let foo: Foo = Foo.create(ctx, 0) + + // 0x01 selector call + evm::mstore8(offset: FREE_MEM_PTR_BIG + 3, value: 0x01) + assert evm::call( + gas: CALL_GAS, + addr: address(foo), + value: 0, + input_offset: FREE_MEM_PTR_BIG, + input_len: 32, + output_offset: FREE_MEM_PTR_BIG, + output_len: 32 + ) == 1 + assert evm::mload(offset: FREE_MEM_PTR_BIG) == 0x02 + + // 0x03 selector call + evm::mstore8(offset: FREE_MEM_PTR_BIG + 3, value: 0x03) + assert evm::call( + gas: CALL_GAS, + addr: address(foo), + value: 0, + input_offset: FREE_MEM_PTR_BIG, + input_len: 32, + output_offset: FREE_MEM_PTR_BIG, + output_len: 32 + ) == 1 + assert evm::mload(offset: FREE_MEM_PTR_BIG) == 0x04 +} \ No newline at end of file diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index fdd475567c..b60caca5d7 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -1,15 +1,26 @@ #![cfg(feature = "solc-backend")] #![allow(dead_code)] use dir_test::{dir_test, Fixture}; +use fe_common::diagnostics::print_diagnostics; use fe_test_runner::TestSink; #[dir_test(dir: "$CARGO_MANIFEST_DIR/fixtures/files", glob: "*.fe")] fn single_file_test_run(fixture: Fixture<&str>) { let mut db = fe_driver::Db::default(); - let tests = - fe_driver::compile_single_file_tests(&mut db, fixture.path(), fixture.content(), true) - .expect("failed to compile tests") - .1; + + let tests = match fe_driver::compile_single_file_tests( + &mut db, + fixture.path(), + fixture.content(), + true, + ) { + Ok((_, tests)) => tests, + Err(error) => { + eprintln!("Unable to compile {}.", fixture.path()); + print_diagnostics(&db, &error.0); + panic!("failed to compile tests") + } + }; let mut test_sink = TestSink::default();