diff --git a/contracts/btc-staking/src/queries.rs b/contracts/btc-staking/src/queries.rs index 6cf6f92e..51d50050 100644 --- a/contracts/btc-staking/src/queries.rs +++ b/contracts/btc-staking/src/queries.rs @@ -139,12 +139,12 @@ pub fn finality_provider_info( deps: Deps, btc_pk_hex: String, height: Option, -) -> StdResult { +) -> Result { let fp_state = match height { Some(h) => fps().may_load_at_height(deps.storage, &btc_pk_hex, h), None => fps().may_load(deps.storage, &btc_pk_hex), }? - .unwrap_or_default(); + .ok_or_else(|| ContractError::FinalityProviderNotFound(btc_pk_hex.clone()))?; Ok(FinalityProviderInfo { btc_pk_hex, @@ -710,6 +710,17 @@ mod tests { power: 250, } ); + + // Query finality provider info for a non-existent FP + let non_existent_fp = "010203040506".to_string(); + let result = + crate::queries::finality_provider_info(deps.as_ref(), non_existent_fp.clone(), None); + + // Assert that the result is a FinalityProviderNotFound error + assert!(matches!( + result, + Err(ContractError::FinalityProviderNotFound(pk)) if pk == non_existent_fp + )); } #[test] diff --git a/contracts/btc-staking/src/staking.rs b/contracts/btc-staking/src/staking.rs index 99466305..c9451544 100644 --- a/contracts/btc-staking/src/staking.rs +++ b/contracts/btc-staking/src/staking.rs @@ -583,9 +583,11 @@ pub(crate) mod tests { .clone_from(&active_delegation.fp_btc_pk_list[0]); // Check that the finality provider has no power yet - let res = queries::finality_provider_info(deps.as_ref(), new_fp.btc_pk_hex.clone(), None) - .unwrap(); - assert_eq!(res.power, 0); + let res = queries::finality_provider_info(deps.as_ref(), new_fp.btc_pk_hex.clone(), None); + assert!(matches!( + res, + Err(ContractError::FinalityProviderNotFound(pk)) if pk == new_fp.btc_pk_hex + )); let msg = ExecuteMsg::BtcStaking { new_fp: vec![new_fp.clone()],