diff --git a/soroban-env-host/src/test/map.rs b/soroban-env-host/src/test/map.rs index 02e826b4c..25e7d35c5 100644 --- a/soroban-env-host/src/test/map.rs +++ b/soroban-env-host/src/test/map.rs @@ -9,8 +9,8 @@ use soroban_env_common::{ }; use crate::{ - xdr::{ScMap, ScMapEntry, ScVal, ScVec}, - Env, Error, Host, HostError, Symbol, Val, + xdr::{ScMap, ScMapEntry, ScVal, ScVec, VecM}, + Env, Error, Host, HostError, Symbol, TryFromVal, Val, }; #[test] @@ -303,6 +303,29 @@ fn map_stack_no_overflow_65536_boxed_keys_and_vals() { } } +#[test] +fn scmap_out_of_order() { + let host = Host::default(); + let bad_scmap = ScVal::Map(Some(ScMap( + VecM::try_from(vec![ + ScMapEntry { + key: ScVal::U32(2), + val: ScVal::U32(0), + }, + ScMapEntry { + key: ScVal::U32(3), + val: ScVal::U32(0), + }, + ScMapEntry { + key: ScVal::U32(1), + val: ScVal::U32(0), + }, + ]) + .unwrap(), + ))); + assert!(Val::try_from_val(&host, &bad_scmap).is_err()); +} + #[test] fn map_build_bad_element_integrity() -> Result<(), HostError> { use crate::EnvBase;