Skip to content

Commit

Permalink
Fix bug for multiple packages (#18)
Browse files Browse the repository at this point in the history
* Fix bug for multiple packages

* Add assert for new package
  • Loading branch information
corydickson authored Apr 2, 2024
1 parent 3ebb646 commit 556d68f
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ impl Contract {
&author,
&LookupMap::new(PrefixKeys::Manifest)
);

log_str(&format!("Creating storage..."));
}

if !self.packages.get(&author).unwrap().contains_key(&package_name) {
let mut manifests = self.packages.get(&author).unwrap();
manifests.insert(&package_name, &mut Vec::new());
}
Expand Down Expand Up @@ -331,6 +333,56 @@ mod tests {
);
}

#[test]
fn set_multiple_manifest() {
let context = get_context(false);
testing_env!(context.clone());
let cid = "QmPK1s3pNYLi9ERiq3BDxKa4XosgWwFRQUydHUtz4YgpqB".to_string();
let name = "test-package".to_string();
let version = "0.0.1".to_string();
let content_type = "ipfs".to_string();

let mut contract = Contract::default();
contract.create_manifest(
name.clone(),
version.clone(),
content_type.clone(),
cid.clone(),
false
);

contract.create_manifest(
"new_package".to_string(),
version.clone(),
content_type.clone(),
cid.clone(),
false
);

contract.create_manifest(
name.clone(),
"0.0.2".to_string(),
content_type.clone(),
cid.clone(),
false
);

assert_eq!(
contract.get_manifest(context.signer_account_id.clone(), name.clone(), version.clone()),
cid.clone()
);

assert_eq!(
contract.get_manifest(context.signer_account_id.clone(), name.clone(), "0.0.2".to_string()),
cid.clone()
);

assert_eq!(
contract.get_manifest(context.signer_account_id.clone(), "new_package".to_string(), version.to_string()),
cid.clone()
);
}

#[test]
fn update_existing_manifest() {
let context = get_context(false);
Expand Down

0 comments on commit 556d68f

Please sign in to comment.