From 9a153d1881d8e0e1734e82281e075f8e67a71b5f Mon Sep 17 00:00:00 2001 From: Manuel Guilherme Date: Fri, 14 Aug 2026 21:55:35 -0300 Subject: [PATCH] test: cover Bool returned as SC_SPEC_TYPE_VAL Adds a regression test for #2438: a contract fn returning `Val` whose runtime value is ScVal::Bool must render via xdr_to_json instead of panicking. The defect itself was already resolved on main by the generic-Val arm added in #2469; existing Val-type coverage handled Bytes, Map and Vec but not Bool. Both booleans exercise the same arm. --- cmd/crates/soroban-spec-tools/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/crates/soroban-spec-tools/src/lib.rs b/cmd/crates/soroban-spec-tools/src/lib.rs index a12d5821b8..10865784b2 100644 --- a/cmd/crates/soroban-spec-tools/src/lib.rs +++ b/cmd/crates/soroban-spec-tools/src/lib.rs @@ -2493,6 +2493,23 @@ mod tests { ); } + #[test] + fn test_xdr_to_json_bool_with_val_type() { + // Regression test for https://github.com/stellar/stellar-cli/issues/2438 + // A contract fn returning `Val` (SC_SPEC_TYPE_VAL) whose runtime value is + // ScVal::Bool must render instead of panicking with "doesn't have a + // matching Val". Both booleans hit the same match arm; false is not special. + let spec = Spec(None); + assert_eq!( + spec.xdr_to_json(&ScVal::Bool(false), &ScType::Val).unwrap(), + Value::Bool(false) + ); + assert_eq!( + spec.xdr_to_json(&ScVal::Bool(true), &ScType::Val).unwrap(), + Value::Bool(true) + ); + } + #[test] fn test_xdr_to_json_map_with_val_type() { // ScVal::Map with ScType::Val should delegate to to_json, not sc_object_to_json.