From 49a7caee5e8a451999d178e1d6d91d633e6fb1d4 Mon Sep 17 00:00:00 2001 From: brock elmore Date: Fri, 8 Dec 2023 13:19:41 -0800 Subject: [PATCH] move tests --- .../tests}/benches/flat_comptroller.sol | 0 .../pyrometer/tests}/benches/flat_ctoken.sol | 0 .../pyrometer/tests}/challenges/apron.sol | 0 .../tests}/challenges/func_stress.sol | 0 .../challenges/reverse_bound_propogation.sol | 0 {tests => crates/pyrometer/tests}/helpers.rs | 55 ++++++++++--------- .../pyrometer/tests}/no_killed_ctxs.rs | 0 .../pyrometer/tests}/test_data/abstract.sol | 0 .../pyrometer/tests}/test_data/assembly.sol | 0 .../pyrometer/tests}/test_data/bitwise.sol | 0 .../pyrometer/tests}/test_data/cast.sol | 15 ++++- .../pyrometer/tests}/test_data/const_var.sol | 0 .../tests}/test_data/constructor.sol | 4 +- .../pyrometer/tests}/test_data/dyn_types.sol | 0 .../pyrometer/tests}/test_data/env.sol | 0 .../tests}/test_data/func_override.sol | 0 .../tests}/test_data/function_calls.sol | 0 .../pyrometer/tests}/test_data/interface.sol | 0 .../pyrometer/tests}/test_data/intrinsics.sol | 0 .../pyrometer/tests}/test_data/logical.sol | 0 .../pyrometer/tests}/test_data/loops.sol | 0 .../pyrometer/tests}/test_data/math.sol | 0 .../pyrometer/tests}/test_data/modifier.sol | 13 +++-- .../tests}/test_data/named_func_call.sol | 0 .../pyrometer/tests}/test_data/precedence.sol | 0 .../relative_imports/relative_import.sol | 0 .../tests}/test_data/remapping_import.sol | 0 .../pyrometer/tests}/test_data/remappings.txt | 0 .../pyrometer/tests}/test_data/require.sol | 0 .../pyrometer/tests}/test_data/storage.sol | 0 .../pyrometer/tests}/test_data/using.sol | 0 crates/queries/src/lib.rs | 2 +- 32 files changed, 53 insertions(+), 36 deletions(-) rename {tests => crates/pyrometer/tests}/benches/flat_comptroller.sol (100%) rename {tests => crates/pyrometer/tests}/benches/flat_ctoken.sol (100%) rename {tests => crates/pyrometer/tests}/challenges/apron.sol (100%) rename {tests => crates/pyrometer/tests}/challenges/func_stress.sol (100%) rename {tests => crates/pyrometer/tests}/challenges/reverse_bound_propogation.sol (100%) rename {tests => crates/pyrometer/tests}/helpers.rs (61%) rename {tests => crates/pyrometer/tests}/no_killed_ctxs.rs (100%) rename {tests => crates/pyrometer/tests}/test_data/abstract.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/assembly.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/bitwise.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/cast.sol (96%) rename {tests => crates/pyrometer/tests}/test_data/const_var.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/constructor.sol (96%) rename {tests => crates/pyrometer/tests}/test_data/dyn_types.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/env.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/func_override.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/function_calls.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/interface.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/intrinsics.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/logical.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/loops.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/math.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/modifier.sol (89%) rename {tests => crates/pyrometer/tests}/test_data/named_func_call.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/precedence.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/relative_imports/relative_import.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/remapping_import.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/remappings.txt (100%) rename {tests => crates/pyrometer/tests}/test_data/require.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/storage.sol (100%) rename {tests => crates/pyrometer/tests}/test_data/using.sol (100%) diff --git a/tests/benches/flat_comptroller.sol b/crates/pyrometer/tests/benches/flat_comptroller.sol similarity index 100% rename from tests/benches/flat_comptroller.sol rename to crates/pyrometer/tests/benches/flat_comptroller.sol diff --git a/tests/benches/flat_ctoken.sol b/crates/pyrometer/tests/benches/flat_ctoken.sol similarity index 100% rename from tests/benches/flat_ctoken.sol rename to crates/pyrometer/tests/benches/flat_ctoken.sol diff --git a/tests/challenges/apron.sol b/crates/pyrometer/tests/challenges/apron.sol similarity index 100% rename from tests/challenges/apron.sol rename to crates/pyrometer/tests/challenges/apron.sol diff --git a/tests/challenges/func_stress.sol b/crates/pyrometer/tests/challenges/func_stress.sol similarity index 100% rename from tests/challenges/func_stress.sol rename to crates/pyrometer/tests/challenges/func_stress.sol diff --git a/tests/challenges/reverse_bound_propogation.sol b/crates/pyrometer/tests/challenges/reverse_bound_propogation.sol similarity index 100% rename from tests/challenges/reverse_bound_propogation.sol rename to crates/pyrometer/tests/challenges/reverse_bound_propogation.sol diff --git a/tests/helpers.rs b/crates/pyrometer/tests/helpers.rs similarity index 61% rename from tests/helpers.rs rename to crates/pyrometer/tests/helpers.rs index bd69d17d..1d159513 100644 --- a/tests/helpers.rs +++ b/crates/pyrometer/tests/helpers.rs @@ -1,39 +1,33 @@ +use analyzers::ReportConfig; +use analyzers::ReportDisplay; +use analyzers::FunctionVarsBoundAnalyzer; +use shared::Search; use ariadne::sources; -use pyrometer::context::analyzers::ReportConfig; -use pyrometer::context::analyzers::{FunctionVarsBoundAnalyzer, ReportDisplay}; -use pyrometer::Analyzer; -use shared::analyzer::Search; +use pyrometer::{Analyzer, SourcePath}; use shared::NodeIdx; -use shared::{nodes::FunctionNode, Edge}; +use graph::{nodes::FunctionNode, Edge}; use std::collections::BTreeMap; use std::collections::HashMap; use std::path::PathBuf; pub fn assert_no_ctx_killed(path_str: String, sol: &str) { let mut analyzer = Analyzer::default(); - let (maybe_entry, mut all_sources) = - analyzer.parse(sol, &PathBuf::from(path_str.clone()), true); - all_sources.push((maybe_entry, path_str.clone(), sol.to_string(), 0)); + let current_path = SourcePath::SolidityFile(PathBuf::from(path_str.clone())); + let maybe_entry = analyzer.parse(sol, ¤t_path, true); let entry = maybe_entry.unwrap(); - no_ctx_killed(analyzer, entry, path_str, all_sources); + no_ctx_killed(analyzer, entry); } pub fn remapping_assert_no_ctx_killed(path_str: String, remapping_file: String, sol: &str) { let mut analyzer = Analyzer::default(); analyzer.set_remappings_and_root(remapping_file); - let (maybe_entry, mut all_sources) = - analyzer.parse(sol, &PathBuf::from(path_str.clone()), true); - all_sources.push((maybe_entry, path_str.clone(), sol.to_string(), 0)); + let current_path = SourcePath::SolidityFile(PathBuf::from(path_str.clone())); + let maybe_entry = analyzer.parse(sol, ¤t_path, true); let entry = maybe_entry.unwrap(); - no_ctx_killed(analyzer, entry, path_str, all_sources); + no_ctx_killed(analyzer, entry); } -pub fn no_ctx_killed( - mut analyzer: Analyzer, - entry: NodeIdx, - path_str: String, - all_sources: Vec<(Option, String, String, usize)>, -) { +pub fn no_ctx_killed(mut analyzer: Analyzer, entry: NodeIdx) { assert!( analyzer.expr_errs.is_empty(), "Analyzer encountered parse errors" @@ -51,14 +45,21 @@ pub fn no_ctx_killed( show_unreachables: true, show_nonreverts: true, }; - let file_mapping: BTreeMap<_, _> = vec![(0usize, path_str)].into_iter().collect(); - - let mut source_map = sources( - all_sources - .iter() - .map(|(_entry, name, src, _num)| (name.clone(), src)) - .collect::>(), - ); + let mut file_mapping: BTreeMap = BTreeMap::new(); + let mut src_map: HashMap = HashMap::new(); + for (source_path, sol, o_file_no, _o_entry) in analyzer.sources.iter() { + if let Some(file_no) = o_file_no { + file_mapping.insert( + *file_no, + source_path.path_to_solidity_source().display().to_string(), + ); + } + src_map.insert( + source_path.path_to_solidity_source().display().to_string(), + sol.to_string(), + ); + } + let mut source_map = sources(src_map); let funcs = analyzer.search_children(entry, &Edge::Func); for func in funcs.into_iter() { diff --git a/tests/no_killed_ctxs.rs b/crates/pyrometer/tests/no_killed_ctxs.rs similarity index 100% rename from tests/no_killed_ctxs.rs rename to crates/pyrometer/tests/no_killed_ctxs.rs diff --git a/tests/test_data/abstract.sol b/crates/pyrometer/tests/test_data/abstract.sol similarity index 100% rename from tests/test_data/abstract.sol rename to crates/pyrometer/tests/test_data/abstract.sol diff --git a/tests/test_data/assembly.sol b/crates/pyrometer/tests/test_data/assembly.sol similarity index 100% rename from tests/test_data/assembly.sol rename to crates/pyrometer/tests/test_data/assembly.sol diff --git a/tests/test_data/bitwise.sol b/crates/pyrometer/tests/test_data/bitwise.sol similarity index 100% rename from tests/test_data/bitwise.sol rename to crates/pyrometer/tests/test_data/bitwise.sol diff --git a/tests/test_data/cast.sol b/crates/pyrometer/tests/test_data/cast.sol similarity index 96% rename from tests/test_data/cast.sol rename to crates/pyrometer/tests/test_data/cast.sol index 4b91ecb2..78465c4e 100644 --- a/tests/test_data/cast.sol +++ b/crates/pyrometer/tests/test_data/cast.sol @@ -231,9 +231,22 @@ contract Cast { require(b == x); } + + function downcast_uint_conc() public returns (uint64) { + uint128 y = type(uint128).max; + y -= type(uint32).max; + return uint64(y); + } + + function downcast_int_conc() public returns (int64) { + int128 x = type(int128).max; + x -= type(int32).max; + return int64(x); + } + function userInt() internal { int256 x = -100; - MyUint a = MyInt.wrap(x); + MyInt a = MyInt.wrap(x); int256 b = MyInt.unwrap(a); require(b == x); } diff --git a/tests/test_data/const_var.sol b/crates/pyrometer/tests/test_data/const_var.sol similarity index 100% rename from tests/test_data/const_var.sol rename to crates/pyrometer/tests/test_data/const_var.sol diff --git a/tests/test_data/constructor.sol b/crates/pyrometer/tests/test_data/constructor.sol similarity index 96% rename from tests/test_data/constructor.sol rename to crates/pyrometer/tests/test_data/constructor.sol index ef9c2dd5..cbf4d23e 100644 --- a/tests/test_data/constructor.sol +++ b/crates/pyrometer/tests/test_data/constructor.sol @@ -46,7 +46,7 @@ abstract contract H { abstract contract I is H { H a; - function liquidateBorrowInternal(H _a) internal returns (uint, uint) { + function liquidateBorrowInternal(H _a) internal returns (uint, uint, uint) { uint b = foo(); uint b2 = _a.foo(); uint b3 = a.foo(); @@ -54,7 +54,7 @@ abstract contract I is H { if (b2 != 1) {} if (b3 != 1) {} - return (b2, b3); + return (b, b2, b3); } function foo() public virtual override returns (uint){ diff --git a/tests/test_data/dyn_types.sol b/crates/pyrometer/tests/test_data/dyn_types.sol similarity index 100% rename from tests/test_data/dyn_types.sol rename to crates/pyrometer/tests/test_data/dyn_types.sol diff --git a/tests/test_data/env.sol b/crates/pyrometer/tests/test_data/env.sol similarity index 100% rename from tests/test_data/env.sol rename to crates/pyrometer/tests/test_data/env.sol diff --git a/tests/test_data/func_override.sol b/crates/pyrometer/tests/test_data/func_override.sol similarity index 100% rename from tests/test_data/func_override.sol rename to crates/pyrometer/tests/test_data/func_override.sol diff --git a/tests/test_data/function_calls.sol b/crates/pyrometer/tests/test_data/function_calls.sol similarity index 100% rename from tests/test_data/function_calls.sol rename to crates/pyrometer/tests/test_data/function_calls.sol diff --git a/tests/test_data/interface.sol b/crates/pyrometer/tests/test_data/interface.sol similarity index 100% rename from tests/test_data/interface.sol rename to crates/pyrometer/tests/test_data/interface.sol diff --git a/tests/test_data/intrinsics.sol b/crates/pyrometer/tests/test_data/intrinsics.sol similarity index 100% rename from tests/test_data/intrinsics.sol rename to crates/pyrometer/tests/test_data/intrinsics.sol diff --git a/tests/test_data/logical.sol b/crates/pyrometer/tests/test_data/logical.sol similarity index 100% rename from tests/test_data/logical.sol rename to crates/pyrometer/tests/test_data/logical.sol diff --git a/tests/test_data/loops.sol b/crates/pyrometer/tests/test_data/loops.sol similarity index 100% rename from tests/test_data/loops.sol rename to crates/pyrometer/tests/test_data/loops.sol diff --git a/tests/test_data/math.sol b/crates/pyrometer/tests/test_data/math.sol similarity index 100% rename from tests/test_data/math.sol rename to crates/pyrometer/tests/test_data/math.sol diff --git a/tests/test_data/modifier.sol b/crates/pyrometer/tests/test_data/modifier.sol similarity index 89% rename from tests/test_data/modifier.sol rename to crates/pyrometer/tests/test_data/modifier.sol index c887f556..86aad8ff 100644 --- a/tests/test_data/modifier.sol +++ b/crates/pyrometer/tests/test_data/modifier.sol @@ -19,7 +19,6 @@ contract Modifier { require(l == 100); a += 1; _; - a = 1; a += 1; } @@ -35,19 +34,23 @@ contract Modifier { a += 1; } + function requireBoth() public RequireBefore RequireAfter { + a += 1; + } + function input(uint256 b) public Input(b) { uint256 a = b; - require(a == 1); + require(a == 2); } function input(uint256 b, uint256 q) public Input(b) Input(q) { uint256 k = b; - require(a == 2); + require(a == 4); } function internalMod(uint256 b) internal Input(b) { uint256 k = b; - require(a == 1); + require(a == 2); } function internalModPub(uint256 b) public { @@ -63,7 +66,7 @@ contract Modifier { } function inputFuncConst(uint256 x) internal Input(addOne(99)) returns (uint256) { - require(a == 1); + require(a == 2); return x; } diff --git a/tests/test_data/named_func_call.sol b/crates/pyrometer/tests/test_data/named_func_call.sol similarity index 100% rename from tests/test_data/named_func_call.sol rename to crates/pyrometer/tests/test_data/named_func_call.sol diff --git a/tests/test_data/precedence.sol b/crates/pyrometer/tests/test_data/precedence.sol similarity index 100% rename from tests/test_data/precedence.sol rename to crates/pyrometer/tests/test_data/precedence.sol diff --git a/tests/test_data/relative_imports/relative_import.sol b/crates/pyrometer/tests/test_data/relative_imports/relative_import.sol similarity index 100% rename from tests/test_data/relative_imports/relative_import.sol rename to crates/pyrometer/tests/test_data/relative_imports/relative_import.sol diff --git a/tests/test_data/remapping_import.sol b/crates/pyrometer/tests/test_data/remapping_import.sol similarity index 100% rename from tests/test_data/remapping_import.sol rename to crates/pyrometer/tests/test_data/remapping_import.sol diff --git a/tests/test_data/remappings.txt b/crates/pyrometer/tests/test_data/remappings.txt similarity index 100% rename from tests/test_data/remappings.txt rename to crates/pyrometer/tests/test_data/remappings.txt diff --git a/tests/test_data/require.sol b/crates/pyrometer/tests/test_data/require.sol similarity index 100% rename from tests/test_data/require.sol rename to crates/pyrometer/tests/test_data/require.sol diff --git a/tests/test_data/storage.sol b/crates/pyrometer/tests/test_data/storage.sol similarity index 100% rename from tests/test_data/storage.sol rename to crates/pyrometer/tests/test_data/storage.sol diff --git a/tests/test_data/using.sol b/crates/pyrometer/tests/test_data/using.sol similarity index 100% rename from tests/test_data/using.sol rename to crates/pyrometer/tests/test_data/using.sol diff --git a/crates/queries/src/lib.rs b/crates/queries/src/lib.rs index b1470cf7..3ac5e78c 100644 --- a/crates/queries/src/lib.rs +++ b/crates/queries/src/lib.rs @@ -1 +1 @@ -/// Currently Empty \ No newline at end of file +//! Currently Empty \ No newline at end of file