From 02656e6e23f45f8140e5454510f137ab73dba204 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Wed, 18 Sep 2024 13:17:34 -0400 Subject: [PATCH] Add e2e tests to cover unsupported Wasm upload failure. (#1461) ### 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 --- soroban-env-host/src/test/e2e_tests.rs | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/soroban-env-host/src/test/e2e_tests.rs b/soroban-env-host/src/test/e2e_tests.rs index bc37aea52..8a136ea3e 100644 --- a/soroban-env-host/src/test/e2e_tests.rs +++ b/soroban-env-host/src/test/e2e_tests.rs @@ -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); @@ -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(