Skip to content

Commit

Permalink
Add e2e tests to cover unsupported Wasm upload failure. (#1461)
Browse files Browse the repository at this point in the history
### What

Add e2e tests to cover unsupported Wasm upload failure.

While we do cover this at a lower level, it's nice to have an e2e test
that makes sure that VM configuration is correct. We also do have e2e
tests for completely malformed Wasm failures, this scenario is different
because Wasm is not malformed.

### Why

Improving test coverage

### Known limitations

N/A
  • Loading branch information
dmkozh authored Sep 18, 2024
1 parent fa8f615 commit 02656e6
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions soroban-env-host/src/test/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,32 @@ fn test_wasm_upload_success() {
assert!(res.budget.get_mem_bytes_consumed().unwrap() > 0);
}

#[test]
fn test_wasm_upload_failure_due_to_unsupported_wasm_features() {
let ledger_key = get_wasm_key(ADD_F32);
let ledger_info = default_ledger_info();

let res = invoke_host_function_helper(
false,
&upload_wasm_host_fn(ADD_F32),
&resources(10_000_000, vec![], vec![ledger_key.clone()]),
&get_account_id([123; 32]),
vec![],
&ledger_info,
vec![],
&prng_seed(),
)
.unwrap();
assert!(res.budget.get_cpu_insns_consumed().unwrap() > 0);
assert!(res.budget.get_mem_bytes_consumed().unwrap() > 0);

assert!(res.invoke_result.is_err());
assert!(HostError::result_matches_err(
res.invoke_result,
(ScErrorType::WasmVm, ScErrorCode::InvalidAction)
));
}

#[test]
fn test_wasm_upload_success_in_recording_mode() {
let ledger_key = get_wasm_key(ADD_I32);
Expand Down Expand Up @@ -702,6 +728,29 @@ fn test_wasm_upload_failure_in_recording_mode() {
);
}

#[test]
fn test_unsupported_wasm_upload_failure_in_recording_mode() {
let ledger_info = default_ledger_info();

let res = invoke_host_function_recording_helper(
true,
&upload_wasm_host_fn(ADD_F32),
&get_account_id([123; 32]),
None,
&ledger_info,
vec![],
&prng_seed(),
None,
)
.unwrap();
assert!(res.diagnostic_events.len() >= 1);
assert!(res.contract_events.is_empty());
assert!(HostError::result_matches_err(
res.invoke_result,
(ScErrorType::WasmVm, ScErrorCode::InvalidAction)
));
}

#[test]
fn test_wasm_upload_success_using_simulation() {
let res = invoke_host_function_using_simulation_with_signers(
Expand Down

0 comments on commit 02656e6

Please sign in to comment.