Skip to content

Commit

Permalink
Add testcase for out-of-order scmaps, fix #223. (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon authored Jul 5, 2023
1 parent 2f3a7f3 commit dace962
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions soroban-env-host/src/test/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dace962

Please sign in to comment.