Skip to content

Commit 4b4ec35

Browse files
committed
Add end-to-end muxed-contract storage-key test; dedupe with account case
Extract the shared body of the muxed-account storage-key test into a helper `check_muxed_address_is_not_allowed_as_storage_key`, and add the CAP-0084 muxed-contract twin as a thin, feature-gated wrapper. Also record the missing observation for the `muxed_contract_storage_key_conversion` unit test.
1 parent 55e3098 commit 4b4ec35

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-",
3+
" 1 end": "cpu:15100, mem:80, prngs:-/9b4a753, objs:-/1@d3ad1bcd, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-"
4+
}

soroban-env-host/src/test/storage.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,14 @@ fn muxed_contract_storage_key_conversion() {
450450
assert!(res_non_storage.is_ok());
451451
}
452452

453-
#[test]
454-
fn test_muxed_account_is_not_allowed_as_storage_key() {
453+
// Drives an end-to-end contract call for every storage type to assert that
454+
// `muxed_address` is rejected as a storage key (directly, via `put`/`get`)
455+
// while still being usable as a stored value. Shared by the CAP-67
456+
// (muxed account) and CAP-0084 (muxed contract) cases, which differ only in
457+
// the address they feed in.
458+
fn check_muxed_address_is_not_allowed_as_storage_key(muxed_address: MuxedScAddress) {
455459
let host = Host::test_host_with_recording_footprint();
456460
let contract_id = host.register_test_contract_wasm(CONTRACT_STORAGE_WITH_VALS);
457-
let muxed_address = MuxedScAddress(ScAddress::MuxedAccount(MuxedEd25519Account {
458-
id: 123,
459-
ed25519: Uint256([10; 32]),
460-
}));
461461
let muxed_address_val = host.add_host_object(muxed_address.clone()).unwrap();
462462

463463
let run_test = |storage: &str| {
@@ -512,6 +512,30 @@ fn test_muxed_account_is_not_allowed_as_storage_key() {
512512
run_test("instance");
513513
}
514514

515+
#[test]
516+
fn test_muxed_account_is_not_allowed_as_storage_key() {
517+
check_muxed_address_is_not_allowed_as_storage_key(MuxedScAddress(ScAddress::MuxedAccount(
518+
MuxedEd25519Account {
519+
id: 123,
520+
ed25519: Uint256([10; 32]),
521+
},
522+
)));
523+
}
524+
525+
// CAP-0084: the muxed contract twin of
526+
// `test_muxed_account_is_not_allowed_as_storage_key`.
527+
#[cfg(feature = "cap_0084_muxed_contract")]
528+
#[test]
529+
fn test_muxed_contract_is_not_allowed_as_storage_key() {
530+
use crate::xdr::MuxedContract;
531+
check_muxed_address_is_not_allowed_as_storage_key(MuxedScAddress(ScAddress::MuxedContract(
532+
MuxedContract {
533+
id: 123,
534+
contract_id: ContractId([10; 32].into()),
535+
},
536+
)));
537+
}
538+
515539
#[test]
516540
fn test_storage_mix() {
517541
// This makes sure the keyspaces are not mixed between storage types.

0 commit comments

Comments
 (0)