Skip to content

Commit

Permalink
Add testcase for out-of-order scmaps, fix #223.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Jul 5, 2023
1 parent 8b423d0 commit fb99378
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 @@ -302,3 +302,26 @@ 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());
}

0 comments on commit fb99378

Please sign in to comment.