forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
94 lines (81 loc) · 3.16 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
mod runner;
pub use runner::{ContractRunner, TestKind, TestKindGas, TestResult};
mod multi_runner;
pub use multi_runner::{MultiContractRunner, MultiContractRunnerBuilder};
pub trait TestFilter {
fn matches_test(&self, test_name: impl AsRef<str>) -> bool;
fn matches_contract(&self, contract_name: impl AsRef<str>) -> bool;
fn matches_path(&self, path: impl AsRef<str>) -> bool;
}
#[cfg(test)]
pub mod test_helpers {
use super::*;
use ethers::{
prelude::Lazy,
solc::{AggregatedCompilerOutput, Project, ProjectPathsConfig},
types::U256,
};
use evm_adapters::{
evm_opts::{Env, EvmOpts, EvmType},
sputnik::helpers::VICINITY,
FAUCET_ACCOUNT,
};
use sputnik::backend::MemoryBackend;
pub static COMPILED: Lazy<AggregatedCompilerOutput> = Lazy::new(|| {
// NB: should we add a test-helper function that makes creating these
// ephemeral projects easier?
let paths =
ProjectPathsConfig::builder().root("testdata").sources("testdata").build().unwrap();
let project = Project::builder().paths(paths).ephemeral().no_artifacts().build().unwrap();
project.compile().unwrap().output()
});
pub static EVM_OPTS: Lazy<EvmOpts> = Lazy::new(|| EvmOpts {
env: Env { gas_limit: 18446744073709551615, chain_id: Some(99), ..Default::default() },
initial_balance: U256::MAX,
evm_type: EvmType::Sputnik,
..Default::default()
});
pub static BACKEND: Lazy<MemoryBackend<'static>> = Lazy::new(|| {
let mut backend = MemoryBackend::new(&*VICINITY, Default::default());
// max out the balance of the faucet
let faucet = backend.state_mut().entry(*FAUCET_ACCOUNT).or_insert_with(Default::default);
faucet.balance = U256::MAX;
backend
});
pub mod filter {
use super::*;
use regex::Regex;
pub struct Filter {
test_regex: Regex,
contract_regex: Regex,
path_regex: Regex,
}
impl Filter {
pub fn new(test_pattern: &str, contract_pattern: &str, path_pattern: &str) -> Self {
Filter {
test_regex: Regex::new(test_pattern).unwrap(),
contract_regex: Regex::new(contract_pattern).unwrap(),
path_regex: Regex::new(path_pattern).unwrap(),
}
}
pub fn matches_all() -> Self {
Filter {
test_regex: Regex::new(".*").unwrap(),
contract_regex: Regex::new(".*").unwrap(),
path_regex: Regex::new(".*").unwrap(),
}
}
}
impl TestFilter for Filter {
fn matches_test(&self, test_name: impl AsRef<str>) -> bool {
self.test_regex.is_match(test_name.as_ref())
}
fn matches_contract(&self, contract_name: impl AsRef<str>) -> bool {
self.contract_regex.is_match(contract_name.as_ref())
}
fn matches_path(&self, path: impl AsRef<str>) -> bool {
self.path_regex.is_match(path.as_ref())
}
}
}
}