Skip to content

Commit aeb2057

Browse files
committed
fix(fuzz): explicit HostError generic on try_invoke_contract
`soroban-sdk` 22.x changed `Env::try_invoke_contract` to return `Result<Result<T, ContractError>, HostError>`. The fuzz harnesses were calling it as `env.try_invoke_contract::<T, _>(...)`, leaving the host-error type uninferred; with multiple `impl TryFromVal<...>` candidates for `Error`, rustc refused with: error[E0283]: type annotations needed --> fuzz_targets/fuzz_vault_withdraw.rs:42:13 | 42 | let _ = env.try_invoke_contract::<(), _>( | ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the error type `E` In the looping harness, the same problem cascaded — the single `.expect()` was returning `Result<u64, Error>` (the inner layer) instead of `u64`, breaking the `position_id >= 1` and `{position_id}` formatting assertions. Fix: make the second generic argument explicit as `soroban_sdk::Error` (which is the actual host-error type for the outer Result), and where `.expect()` is also used, unwrap both layers: // vault/deposit, vault/withdraw - try_invoke_contract::<(), _> + try_invoke_contract::<(), soroban_sdk::Error> // looping/open_position - try_invoke_contract::<u64, _> + try_invoke_contract::<u64, soroban_sdk::Error> - let position_id = result.expect("..."); + let position_id = result + .expect("open_position returned a host error") + .expect("open_position with valid args returned a contract error"); The rewards harness only uses `env.invoke_contract` (infallible) and needed no change.
1 parent 943fba6 commit aeb2057

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

quantara/soroban/contracts/looping/fuzz/fuzz_targets/fuzz_looping_open_position.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ fuzz_target!(|data: &[u8]| {
2727
let contract_id = env.register(LoopingContract, ());
2828
let user = Address::generate(&env);
2929

30-
let result = env.try_invoke_contract::<u64, _>(
30+
// try_invoke_contract returns `Result<Result<u64, ContractError>, HostError>`;
31+
// explicitly specify the host error type so type inference succeeds.
32+
let result = env.try_invoke_contract::<u64, soroban_sdk::Error>(
3133
&contract_id,
3234
&Symbol::new(&env, "open_position"),
3335
soroban_sdk::vec![
@@ -39,7 +41,10 @@ fuzz_target!(|data: &[u8]| {
3941
);
4042

4143
if collateral > 0 && (100..=500).contains(&leverage) {
42-
let position_id = result.expect("open_position with valid args returned error");
44+
// Unwrap the outer (host) Err first, then the inner (contract) Err.
45+
let position_id = result
46+
.expect("open_position returned a host error")
47+
.expect("open_position with valid args returned a contract error");
4348
assert!(position_id >= 1, "position_id must be >= 1, got {position_id}");
4449
}
4550
// Invalid inputs may error; no further assertion needed.

quantara/soroban/contracts/vault/fuzz/fuzz_targets/fuzz_vault_deposit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ fuzz_target!(|data: &[u8]| {
3232
let user = Address::generate(&env);
3333

3434
// Invoke deposit directly via the registered contract.
35-
let result = env.try_invoke_contract::<(), _>(
35+
// try_invoke_contract returns `Result<Result<(), ContractError>, HostError>`;
36+
// specify the host error type as soroban_sdk::Error so type inference can succeed.
37+
let result = env.try_invoke_contract::<(), soroban_sdk::Error>(
3638
&contract_id,
3739
&soroban_sdk::symbol_short!("deposit"),
3840
soroban_sdk::vec![&env, user.to_val(), amount.into_val(&env)],

quantara/soroban/contracts/vault/fuzz/fuzz_targets/fuzz_vault_withdraw.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ fuzz_target!(|data: &[u8]| {
3838
);
3939
}
4040

41-
// Attempt withdrawal.
42-
let _ = env.try_invoke_contract::<(), _>(
41+
// Attempt withdrawal. try_invoke_contract returns
42+
// `Result<Result<(), ContractError>, HostError>`; specify the host error
43+
// type to enable type inference (otherwise rustc can't pick `E`).
44+
let _ = env.try_invoke_contract::<(), soroban_sdk::Error>(
4345
&contract_id,
4446
&soroban_sdk::symbol_short!("withdraw"),
4547
soroban_sdk::vec![&env, user.to_val(), withdraw_amount.into_val(&env)],

0 commit comments

Comments
 (0)