Skip to content

Commit

Permalink
Make del_contract_data no-op for removing non-existent instance sto…
Browse files Browse the repository at this point in the history
…rage key.

This was inconsistent with persistent/temp storage, which doesn't return error for non-existent keys.
  • Loading branch information
dmkozh committed Jul 14, 2023
1 parent d099f93 commit ff59808
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 3 additions & 12 deletions soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
})?;
}
Expand Down
7 changes: 7 additions & 0 deletions soroban-env-host/src/test/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ff59808

Please sign in to comment.