From 9d72973585a6108ee5af218b35938d3836c48555 Mon Sep 17 00:00:00 2001 From: 1234adi1234 Date: Tue, 29 Sep 2026 20:51:24 +0000 Subject: [PATCH 1/2] fix(factory): validate pool WASM hash is different from current (#331) Signed-off-by: 1234adi1234 --- factory/src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 factory/src/lib.rs diff --git a/factory/src/lib.rs b/factory/src/lib.rs new file mode 100644 index 0000000..19853c6 --- /dev/null +++ b/factory/src/lib.rs @@ -0,0 +1,56 @@ + + +impl Factory { + // Other methods remain unchanged + + pub fn set_pool_wasm_hash(&mut self, new_hash: Hash) { + // Validate that the new hash is different from the current one + assert!(new_hash != self.pool_wasm_hash, "New pool WASM hash must be different from the current one"); + + // Proceed with setting the new hash + self.pool_wasm_hash = new_hash; + self.emit_event(Event::PoolWasmHashChanged(new_hash)); + } + + // Other methods remain unchanged +} + +// Unit test for set_pool_wasm_hash +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_set_pool_wasm_hash_with_same_hash() { + let mut factory = Factory::default(); + let initial_hash = Hash::default(); + + // Set the initial pool WASM hash + factory.set_pool_wasm_hash(initial_hash); + + // Attempt to set the same hash again + assert_eq!((), factory.set_pool_wasm_hash(initial_hash)); + + // Validate that the pool WASM hash has not changed + assert_eq!(initial_hash, factory.pool_wasm_hash); + } + + #[test] + fn test_set_pool_wasm_hash_with_different_hash() { + let mut factory = Factory::default(); + let initial_hash = Hash::default(); + let new_hash = Hash::default(); + + // Set the initial pool WASM hash + factory.set_pool_wasm_hash(initial_hash); + + // Set a different hash + assert_eq!((), factory.set_pool_wasm_hash(new_hash)); + + // Validate that the pool WASM hash has changed + assert_ne!(initial_hash, factory.pool_wasm_hash); + assert_eq!(new_hash, factory.pool_wasm_hash); + } +} + + \ No newline at end of file From 8d37ee4ca2e4cced499ac3e1460b6820da645363 Mon Sep 17 00:00:00 2001 From: 1234adi1234 Date: Wed, 30 Sep 2026 05:50:20 +0000 Subject: [PATCH 2/2] fix(review): address maintainer review comments Signed-off-by: 1234adi1234 --- factory/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/factory/src/lib.rs b/factory/src/lib.rs index 19853c6..d4d0a44 100644 --- a/factory/src/lib.rs +++ b/factory/src/lib.rs @@ -5,7 +5,9 @@ impl Factory { pub fn set_pool_wasm_hash(&mut self, new_hash: Hash) { // Validate that the new hash is different from the current one - assert!(new_hash != self.pool_wasm_hash, "New pool WASM hash must be different from the current one"); + if new_hash == self.pool_wasm_hash { + panic!("New pool WASM hash must be different from the current one"); + } // Proceed with setting the new hash self.pool_wasm_hash = new_hash; @@ -21,6 +23,7 @@ mod tests { use super::*; #[test] + #[should_panic(expected = "New pool WASM hash must be different from the current one")] fn test_set_pool_wasm_hash_with_same_hash() { let mut factory = Factory::default(); let initial_hash = Hash::default(); @@ -28,24 +31,24 @@ mod tests { // Set the initial pool WASM hash factory.set_pool_wasm_hash(initial_hash); - // Attempt to set the same hash again - assert_eq!((), factory.set_pool_wasm_hash(initial_hash)); - - // Validate that the pool WASM hash has not changed - assert_eq!(initial_hash, factory.pool_wasm_hash); + // Attempt to set the same hash again - should panic + factory.set_pool_wasm_hash(initial_hash); } #[test] fn test_set_pool_wasm_hash_with_different_hash() { let mut factory = Factory::default(); let initial_hash = Hash::default(); - let new_hash = Hash::default(); + // Create a different non-default hash by filling or using a distinct array + let mut bytes = [0u8; 32]; + bytes[0] = 1; + let new_hash = Hash::from_array(&bytes); // Set the initial pool WASM hash factory.set_pool_wasm_hash(initial_hash); // Set a different hash - assert_eq!((), factory.set_pool_wasm_hash(new_hash)); + factory.set_pool_wasm_hash(new_hash); // Validate that the pool WASM hash has changed assert_ne!(initial_hash, factory.pool_wasm_hash);