From f71162b0dd42190387be3f911413e5f3e6513f09 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Wed, 8 Jan 2025 11:32:54 +1100 Subject: [PATCH] fix some tests --- contracts/btc-finality/src/multitest/suite.rs | 45 ++++++++++++++++--- contracts/btc-staking/src/queries.rs | 41 ++++++++++------- contracts/btc-staking/src/staking.rs | 15 ++++--- packages/bindings-test/src/multitest.rs | 20 +++++++-- packages/bindings/src/query.rs | 6 +-- 5 files changed, 92 insertions(+), 35 deletions(-) diff --git a/contracts/btc-finality/src/multitest/suite.rs b/contracts/btc-finality/src/multitest/suite.rs index e279b06..bb4bdb7 100644 --- a/contracts/btc-finality/src/multitest/suite.rs +++ b/contracts/btc-finality/src/multitest/suite.rs @@ -68,7 +68,8 @@ impl SuiteBuilder { #[track_caller] pub fn build(self) -> Suite { - let owner = Addr::unchecked("owner"); + let owner = + Addr::unchecked("cosmwasm19mfs8tl4s396u7vqw9rrnsmrrtca5r66p7v8jvwdxvjn3shcmllqupdgxu"); let mut app = BabylonApp::new_at_height(owner.as_str(), self.height.unwrap_or(1)); @@ -84,8 +85,9 @@ impl SuiteBuilder { let btc_finality_code_id = app.store_code_with_creator(owner.clone(), contract_btc_finality()); let contract_code_id = app.store_code_with_creator(owner.clone(), contract_babylon()); - let staking_params = btc_staking::test_utils::staking_params(); - let contract = app + + // instantiate Babylon contract + let babylon_contract_addr = app .instantiate_contract( contract_code_id, owner.clone(), @@ -106,12 +108,43 @@ impl SuiteBuilder { ) .unwrap(); + // instantiate BTC Staking contract + let staking_params = btc_staking::test_utils::staking_params(); + let staking_contract_addr = app + .instantiate_contract( + btc_staking_code_id, + owner.clone(), + &btc_staking::msg::InstantiateMsg { + admin: Some(owner.to_string()), + params: Some(staking_params), + }, + &[], + "btc-staking", + Some(owner.to_string()), + ) + .unwrap(); + + // instantiate BTC Finality contract + let finality_contract_addr = app + .instantiate_contract( + btc_finality_code_id, + owner.clone(), + &crate::msg::InstantiateMsg { + admin: Some(owner.to_string()), + params: Some(crate::state::config::Params::default()), + }, + &[], + "btc-finality", + Some(owner.to_string()), + ) + .unwrap(); + Suite { app, code_id: contract_code_id, - babylon: contract, - staking: Addr::unchecked(CONTRACT1_ADDR), - finality: Addr::unchecked(CONTRACT2_ADDR), + babylon: babylon_contract_addr, + staking: staking_contract_addr, + finality: finality_contract_addr, owner, } } diff --git a/contracts/btc-staking/src/queries.rs b/contracts/btc-staking/src/queries.rs index e514003..1a17d02 100644 --- a/contracts/btc-staking/src/queries.rs +++ b/contracts/btc-staking/src/queries.rs @@ -224,7 +224,8 @@ mod tests { #[test] fn test_finality_providers() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -233,7 +234,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -283,7 +284,8 @@ mod tests { #[test] fn test_delegations() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -292,7 +294,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -356,7 +358,8 @@ mod tests { #[test] fn test_active_delegations() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -365,7 +368,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -443,8 +446,8 @@ mod tests { #[test] fn test_delegations_by_fp() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); - + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( deps.as_mut(), @@ -452,7 +455,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -502,7 +505,8 @@ mod tests { #[test] fn test_active_delegations_by_fp() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -511,7 +515,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -592,7 +596,8 @@ mod tests { #[test] fn test_fp_info() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let initial_env = mock_env_height(10); @@ -603,7 +608,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -697,7 +702,8 @@ mod tests { #[test] fn test_fp_info_raw_query() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -706,7 +712,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -751,7 +757,8 @@ mod tests { #[test] fn test_fps_by_power() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -760,7 +767,7 @@ mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); diff --git a/contracts/btc-staking/src/staking.rs b/contracts/btc-staking/src/staking.rs index 7ffe537..342c997 100644 --- a/contracts/btc-staking/src/staking.rs +++ b/contracts/btc-staking/src/staking.rs @@ -507,7 +507,8 @@ pub(crate) mod tests { #[test] fn active_delegation_happy_path() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -516,7 +517,7 @@ pub(crate) mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -572,7 +573,8 @@ pub(crate) mod tests { #[test] fn undelegation_works() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -581,7 +583,7 @@ pub(crate) mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); @@ -671,7 +673,8 @@ pub(crate) mod tests { #[test] fn slashed_delegation_works() { let mut deps = mock_dependencies(); - let info = message_info(&deps.api.addr_make(CREATOR), &[]); + let admin = deps.api.addr_make(CREATOR); + let info = message_info(&admin, &[]); let params = staking_params(); instantiate( @@ -680,7 +683,7 @@ pub(crate) mod tests { info.clone(), InstantiateMsg { params: Some(params), - admin: None, + admin: Some(admin.to_string()), }, ) .unwrap(); diff --git a/packages/bindings-test/src/multitest.rs b/packages/bindings-test/src/multitest.rs index 81526f7..837f7ba 100644 --- a/packages/bindings-test/src/multitest.rs +++ b/packages/bindings-test/src/multitest.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Result as AnyResult}; +use babylon_bindings::query::ParamsResponse; use schemars::JsonSchema; use serde::de::DeserializeOwned; use std::cmp::max; @@ -7,7 +8,7 @@ use std::ops::{Deref, DerefMut}; use thiserror::Error; use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage}; -use cosmwasm_std::OwnedDeps; +use cosmwasm_std::{to_json_binary, OwnedDeps}; use std::marker::PhantomData; use cosmwasm_std::Order::Ascending; @@ -105,9 +106,22 @@ impl Module for BabylonModule { _storage: &dyn Storage, _querier: &dyn Querier, _block: &BlockInfo, - _request: BabylonQuery, + request: BabylonQuery, ) -> anyhow::Result { - bail!("query not implemented for BabylonModule") + match request { + BabylonQuery::Params {} => { + let response = ParamsResponse { + babylon_contract_address: Addr::unchecked(""), + btc_staking_contract_address: Addr::unchecked(""), + btc_finality_contract_address: Addr::unchecked(""), + babylon_contract_code_id: 0, + btc_staking_contract_code_id: 0, + btc_finality_contract_code_id: 0, + max_gas_begin_blocker: 0, + }; + Ok(to_json_binary(&response)?) + } + } } fn sudo( diff --git a/packages/bindings/src/query.rs b/packages/bindings/src/query.rs index 8803ba8..8a7a08c 100644 --- a/packages/bindings/src/query.rs +++ b/packages/bindings/src/query.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ - from_json, to_json_binary, Addr, ContractResult, CustomQuery, QuerierWrapper, StdError, - SystemResult, + from_json, to_json_binary, Addr, ContractResult, CustomQuery, QuerierWrapper, QueryRequest, + StdError, SystemResult, }; #[cw_serde] @@ -35,7 +35,7 @@ pub struct ParamsResponse { pub fn get_babylon_sdk_params( querier: &QuerierWrapper, ) -> Result { - let query = BabylonQuery::Params {}; + let query = QueryRequest::Custom(BabylonQuery::Params {}); let res = match querier.raw_query(&to_json_binary(&query)?) { SystemResult::Err(system_err) => Err(StdError::generic_err(format!( "Querier system error: {}",