Skip to content

Commit

Permalink
move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Dec 8, 2023
1 parent ac945ca commit 49a7cae
Show file tree
Hide file tree
Showing 32 changed files with 53 additions and 36 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 28 additions & 27 deletions tests/helpers.rs → crates/pyrometer/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -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, &current_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, &current_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<NodeIdx>, String, String, usize)>,
) {
pub fn no_ctx_killed(mut analyzer: Analyzer, entry: NodeIdx) {
assert!(
analyzer.expr_errs.is_empty(),
"Analyzer encountered parse errors"
Expand All @@ -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::<HashMap<_, _>>(),
);
let mut file_mapping: BTreeMap<usize, String> = BTreeMap::new();
let mut src_map: HashMap<String, String> = 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() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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();
if (b != 1) {}
if (b2 != 1) {}
if (b3 != 1) {}

return (b2, b3);
return (b, b2, b3);
}

function foo() public virtual override returns (uint){
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.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ contract Modifier {
require(l == 100);
a += 1;
_;
a = 1;
a += 1;
}

Expand All @@ -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 {
Expand All @@ -63,7 +66,7 @@ contract Modifier {
}

function inputFuncConst(uint256 x) internal Input(addOne(99)) returns (uint256) {
require(a == 1);
require(a == 2);
return x;
}

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.
2 changes: 1 addition & 1 deletion crates/queries/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// Currently Empty
//! Currently Empty

0 comments on commit 49a7cae

Please sign in to comment.