Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayz22 committed Jun 17, 2024
1 parent a289bad commit 65f9268
Show file tree
Hide file tree
Showing 37 changed files with 480 additions and 52 deletions.
34 changes: 33 additions & 1 deletion soroban-env-host/src/test/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
budget::AsBudget, events::HostEvent, test::observe::ObservedHost, xdr::ScErrorType,
ContractFunctionSet, Error, Host, HostError, Symbol, Tag,
};
use soroban_test_wasms::{ADD_I32, ALLOC, ERR, INVOKE_CONTRACT, VEC};
use soroban_test_wasms::{ADD_I32, ALLOC, ERR, INVOKE_CONTRACT, STORAGE_LIST, VEC};

#[test]
fn invoke_single_contract_function() -> Result<(), HostError> {
Expand Down Expand Up @@ -44,6 +44,38 @@ fn invoke_single_contract_function() -> Result<(), HostError> {
Ok(())
}

#[test]
fn invoke_storage_list() -> Result<(), HostError> {
let host = observe_host!(Host::test_host_with_recording_footprint());
let contract_id_obj = host.register_test_contract_wasm(STORAGE_LIST);
let a = 4i32;
let b = 7i32;
let c = 0x7fffffff_i32;

let res = host.call(
contract_id_obj,
Symbol::try_from_small_str("add")?,
host.test_vec_obj(&[a, b])?,
)?;
assert_eq!(i32::try_from_val(&*host, &res)?, a + b);
// overflow
let res = host.call(
contract_id_obj,
Symbol::try_from_small_str("add")?,
host.test_vec_obj(&[a, c])?,
);
let code = (ScErrorType::WasmVm, ScErrorCode::InvalidAction);

eprintln!(
"time ellapsed in nano-seconds for VmInstantiation: {}",
host.as_budget()
.get_time(ContractCostType::VmInstantiation)?
);

assert!(HostError::result_matches_err(res, code));
Ok(())
}

#[test]
fn invoke_alloc() -> Result<(), HostError> {
let host = observe_host!(Host::test_host_with_recording_footprint());
Expand Down
2 changes: 2 additions & 0 deletions soroban-test-wasms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ mod curr {

pub const INCREMENT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/increment.wasm").as_slice();
pub const STORAGE_LIST: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/storage_list.wasm").as_slice();
}
Loading

0 comments on commit 65f9268

Please sign in to comment.