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

Remove RawForgeConfig abstraction #2514

Open
kkawula opened this issue Sep 25, 2024 · 0 comments
Open

Remove RawForgeConfig abstraction #2514

kkawula opened this issue Sep 25, 2024 · 0 comments

Comments

@kkawula
Copy link
Collaborator

kkawula commented Sep 25, 2024

Which components does the task require to be changed? (think hard pls)

snforge

Description

Config got from Scarb.toml is stored in ForgeConfigFromScarb struct, but firstly toml is mapped into RawForgeConfig, partially validated, and then mapped into ForgeConfigFromScarb. It can be done without RawForgeConfig abstraction by implementing Deserialize Trait for ForgeConfigFromScarb, ForkTarget, and so on.

Flow that should be refactored:

let raw_config = serde_json::from_value::<RawForgeConfig>(config.clone())?;
raw_config
.try_into()
.context("Invalid config in Scarb.toml: ")
}

Validation for ForkTarget that should be implemented in the deserialize method:

fn validate_raw_fork_config(raw_config: RawForgeConfig) -> Result<RawForgeConfig> {
let forks = &raw_config.fork;
let names: Vec<_> = forks.iter().map(|fork| &fork.name).collect();
let removed_duplicated_names: HashSet<_> = names.iter().collect();
if names.len() != removed_duplicated_names.len() {
bail!("Some fork names are duplicated");
}
for fork in forks {
let block_id_item = fork.block_id.iter().exactly_one();
let Ok((block_id_key, block_id_value)) = block_id_item else {
bail!("block_id should be set once per fork");
};
if !["number", "hash", "tag"].contains(&&**block_id_key) {
bail!("block_id = {block_id_key} is not valid. Possible values are = \"number\", \"hash\" and \"tag\"");
}
if block_id_key == "tag" && block_id_value != "latest" {
bail!("block_id.tag can only be equal to latest");
}
}

ForkTarget::new should be replaced, by creation from deserializing json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

1 participant