From ff59808938a0ec75af51588b340dd20e7735ae07 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 14 Jul 2023 18:57:56 -0400 Subject: [PATCH 1/2] Make `del_contract_data` no-op for removing non-existent instance storage key. This was inconsistent with persistent/temp storage, which doesn't return error for non-existent keys. --- soroban-env-host/src/host.rs | 15 +++------------ soroban-env-host/src/test/storage.rs | 7 +++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index 1d7e5df8c..b8ce13f48 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -2108,18 +2108,9 @@ impl VmCallerEnv for Host { } StorageType::Instance => { self.with_mut_instance_storage(|s| { - s.map = s - .map - .remove(&k, self)? - .ok_or_else(|| { - self.err( - ScErrorType::Storage, - ScErrorCode::MissingValue, - "key is missing from instance storage", - &[k], - ) - })? - .0; + if let Some((new_map, _)) = s.map.remove(&k, self)? { + s.map = new_map; + } Ok(()) })?; } diff --git a/soroban-env-host/src/test/storage.rs b/soroban-env-host/src/test/storage.rs index cd2b0699d..64591cf54 100644 --- a/soroban-env-host/src/test/storage.rs +++ b/soroban-env-host/src/test/storage.rs @@ -149,6 +149,13 @@ fn test_storage(host: &Host, contract_id: AddressObject, storage: &str) { host_vec![host, key_1].into(), ) .unwrap(); + // Delete again - that's a no-op, but it should fail either. + host.call( + contract_id, + storage_fn_name(host, "del", storage), + host_vec![host, key_1].into(), + ) + .unwrap(); // Only the second key is now present assert_eq!( bool::try_from_val( From b7671a4d3ec19c401d7e58afad09c0864227bd56 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 14 Jul 2023 19:36:06 -0400 Subject: [PATCH 2/2] Update soroban-env-host/src/test/storage.rs Co-authored-by: Siddharth Suresh --- soroban-env-host/src/test/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soroban-env-host/src/test/storage.rs b/soroban-env-host/src/test/storage.rs index 64591cf54..26ad1634f 100644 --- a/soroban-env-host/src/test/storage.rs +++ b/soroban-env-host/src/test/storage.rs @@ -149,7 +149,7 @@ fn test_storage(host: &Host, contract_id: AddressObject, storage: &str) { host_vec![host, key_1].into(), ) .unwrap(); - // Delete again - that's a no-op, but it should fail either. + // Delete again - that's a no-op, but it shouldn't fail either. host.call( contract_id, storage_fn_name(host, "del", storage),