From 3abea564ab9b1b2b7163f1806e756a24b9d011fe Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Sat, 20 Apr 2024 10:07:05 +0200 Subject: [PATCH] Fix borrow checker in commented out unit test --- ethcontract-common/src/artifact.rs | 49 ++++++++++++--------- ethcontract-generate/src/generate/events.rs | 10 ++++- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ethcontract-common/src/artifact.rs b/ethcontract-common/src/artifact.rs index d67f70fb..1ed72049 100644 --- a/ethcontract-common/src/artifact.rs +++ b/ethcontract-common/src/artifact.rs @@ -192,8 +192,9 @@ impl Deref for ContractMut<'_> { impl Drop for ContractMut<'_> { fn drop(&mut self) { // The ABI might have gotten mutated while this guard was alive. - // Because we compute a bunch of data from the ABI we need to recompute - // it in case the recomputed data would also have changed due to the update. + // Since we compute pre-compute and cache a few values based on the ABI + // as a performance optimization we need to recompute those cached values + // with the new ABI once the user is done updating the mutable contract. let abi = self.0.interface.abi.clone(); let interface = Interface::from(abi); *Arc::make_mut(&mut self.0.interface) = interface; @@ -210,35 +211,41 @@ mod test { contract } - // #[test] - // fn insert() { - // let mut artifact = Artifact::new(); + #[test] + fn insert() { + let mut artifact = Artifact::new(); - // assert_eq!(artifact.len(), 0); + assert_eq!(artifact.len(), 0); - // let insert_res = artifact.insert(make_contract("C1")); + { + let insert_res = artifact.insert(make_contract("C1")); - // assert_eq!(insert_res.inserted_contract.name, "C1"); - // assert!(insert_res.old_contract.is_none()); + assert_eq!(insert_res.inserted_contract.name, "C1"); + assert!(insert_res.old_contract.is_none()); + } - // assert_eq!(artifact.len(), 1); - // assert!(artifact.contains("C1")); + assert_eq!(artifact.len(), 1); + assert!(artifact.contains("C1")); - // let insert_res = artifact.insert(make_contract("C2")); + { + let insert_res = artifact.insert(make_contract("C2")); - // assert_eq!(insert_res.inserted_contract.name, "C2"); - // assert!(insert_res.old_contract.is_none()); + assert_eq!(insert_res.inserted_contract.name, "C2"); + assert!(insert_res.old_contract.is_none()); + } - // assert_eq!(artifact.len(), 2); - // assert!(artifact.contains("C2")); + assert_eq!(artifact.len(), 2); + assert!(artifact.contains("C2")); - // let insert_res = artifact.insert(make_contract("C1")); + { + let insert_res = artifact.insert(make_contract("C1")); - // assert_eq!(insert_res.inserted_contract.name, "C1"); - // assert!(insert_res.old_contract.is_some()); + assert_eq!(insert_res.inserted_contract.name, "C1"); + assert!(insert_res.old_contract.is_some()); + } - // assert_eq!(artifact.len(), 2); - // } + assert_eq!(artifact.len(), 2); + } #[test] fn remove() { diff --git a/ethcontract-generate/src/generate/events.rs b/ethcontract-generate/src/generate/events.rs index 6f0affd1..53e52948 100644 --- a/ethcontract-generate/src/generate/events.rs +++ b/ethcontract-generate/src/generate/events.rs @@ -799,7 +799,15 @@ mod tests { contract.interface = Arc::new(abi.into()); let context = Context::from_builder(&contract, ContractBuilder::new()).unwrap(); - let foo_signature = expand_hash(context.contract.interface.abi.event("Foo").unwrap().signature()); + let foo_signature = expand_hash( + context + .contract + .interface + .abi + .event("Foo") + .unwrap() + .signature(), + ); let invalid_data = expand_invalid_data(); assert_quote!(expand_event_parse_log(&context), {