Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse inline config with solang #7431

Merged
merged 7 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ debug = 1
# Solc and artifacts
foundry-compilers.opt-level = 3
solang-parser.opt-level = 3
lalrpop-util.opt-level = 3
serde_json.opt-level = 3

# EVM
Expand Down
2 changes: 2 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ alloy-chains = { workspace = true, features = ["serde"] }
alloy-primitives = { workspace = true, features = ["serde"] }
revm-primitives = { workspace = true, default-features = false, features = ["std"] }

solang-parser.workspace = true

dirs-next = "2"
dunce = "1"
eyre.workspace = true
Expand Down
28 changes: 5 additions & 23 deletions crates/config/src/inline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use conf_parser::{parse_config_bool, parse_config_u32, validate_profiles, In
pub use error::{InlineConfigError, InlineConfigParserError};
pub use natspec::NatSpec;
use once_cell::sync::Lazy;
use std::{borrow::Cow, collections::HashMap};
use std::collections::HashMap;

mod conf_parser;
mod error;
Expand All @@ -25,22 +25,14 @@ static INLINE_CONFIG_PREFIX_SELECTED_PROFILE: Lazy<String> = Lazy::new(|| {
pub struct InlineConfig<T> {
/// Maps a (test-contract, test-function) pair
/// to a specific configuration provided by the user.
configs: HashMap<InlineConfigKey<'static>, T>,
configs: HashMap<(String, String), T>,
}

impl<T> InlineConfig<T> {
/// Returns an inline configuration, if any, for a test function.
/// Configuration is identified by the pair "contract", "function".
pub fn get<C, F>(&self, contract_id: C, fn_name: F) -> Option<&T>
where
C: Into<String>,
F: Into<String>,
{
// TODO use borrow
let key = InlineConfigKey {
contract: Cow::Owned(contract_id.into()),
function: Cow::Owned(fn_name.into()),
};
pub fn get(&self, contract_id: &str, fn_name: &str) -> Option<&T> {
let key = (contract_id.to_string(), fn_name.to_string());
self.configs.get(&key)
}

Expand All @@ -51,21 +43,11 @@ impl<T> InlineConfig<T> {
C: Into<String>,
F: Into<String>,
{
let key = InlineConfigKey {
contract: Cow::Owned(contract_id.into()),
function: Cow::Owned(fn_name.into()),
};
let key = (contract_id.into(), fn_name.into());
self.configs.insert(key, config);
}
}

/// Represents a (test-contract, test-function) pair
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct InlineConfigKey<'a> {
contract: Cow<'a, str>,
function: Cow<'a, str>,
}

pub(crate) fn remove_whitespaces(s: &str) -> String {
s.chars().filter(|c| !c.is_whitespace()).collect()
}
Loading
Loading