From 7117bed012aa9d1eb2a70a05bbc6cb7d15c8d706 Mon Sep 17 00:00:00 2001 From: Cory Dickson Date: Tue, 2 Apr 2024 16:40:28 -0400 Subject: [PATCH 1/2] Fix bug for multiple packages --- src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bb9acb2..bc0ce1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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()); } @@ -331,6 +333,51 @@ 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() + ); + } + #[test] fn update_existing_manifest() { let context = get_context(false); From 416f3b23457bbe6bbd3fd9d4728337956cb9c4ca Mon Sep 17 00:00:00 2001 From: Cory Dickson Date: Tue, 2 Apr 2024 16:44:59 -0400 Subject: [PATCH 2/2] Add assert for new package --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bc0ce1d..8bbe7b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -376,6 +376,11 @@ mod tests { 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]