Skip to content

Commit

Permalink
fix: throw error if contract names are not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstevens19 committed Sep 17, 2024
1 parent d0ffc73 commit 2d5d10e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/manifest/yaml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::HashSet,
env,
fs::File,
io::{Read, Write},
Expand Down Expand Up @@ -35,6 +36,9 @@ fn substitute_env_variables(contents: &str) -> Result<String, regex::Error> {

#[derive(thiserror::Error, Debug)]
pub enum ValidateManifestError {
#[error("Contract names {0} must be unique")]
ContractNameMustBeUnique(String),

#[error("Invalid network mapped to contract: network - {0} contract - {1}")]
InvalidNetworkMappedToContract(String, String),

Expand Down Expand Up @@ -70,6 +74,19 @@ fn validate_manifest(
project_path: &Path,
manifest: &Manifest,
) -> Result<(), ValidateManifestError> {
let mut seen = HashSet::new();
let duplicates_contract_names: Vec<String> = manifest
.contracts
.iter()
.filter_map(|c| if seen.insert(&c.name) { None } else { Some(c.name.clone()) })
.collect();

if !duplicates_contract_names.is_empty() {
return Err(ValidateManifestError::ContractNameMustBeUnique(
duplicates_contract_names.join(", "),
));
}

for contract in &manifest.contracts {
let events = ABIItem::read_abi_items(project_path, contract)
.map_err(|e| ValidateManifestError::InvalidABI(contract.name.clone(), e.to_string()))?;
Expand Down
1 change: 1 addition & 0 deletions documentation/docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug fixes
-------------------------------------------------
fix: throw error if contract names are not unique

### Breaking changes
-------------------------------------------------
Expand Down

0 comments on commit 2d5d10e

Please sign in to comment.