Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jan 8, 2025
1 parent ddabb4f commit f71162b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 35 deletions.
45 changes: 39 additions & 6 deletions contracts/btc-finality/src/multitest/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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(),
Expand All @@ -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,
}
}
Expand Down
41 changes: 24 additions & 17 deletions contracts/btc-staking/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -233,7 +234,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -292,7 +294,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -365,7 +368,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -443,16 +446,16 @@ 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(),
mock_env(),
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -511,7 +515,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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);

Expand All @@ -603,7 +608,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -706,7 +712,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -760,7 +767,7 @@ mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down
15 changes: 9 additions & 6 deletions contracts/btc-staking/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -516,7 +517,7 @@ pub(crate) mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -581,7 +583,7 @@ pub(crate) mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down Expand Up @@ -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(
Expand All @@ -680,7 +683,7 @@ pub(crate) mod tests {
info.clone(),
InstantiateMsg {
params: Some(params),
admin: None,
admin: Some(admin.to_string()),
},
)
.unwrap();
Expand Down
20 changes: 17 additions & 3 deletions packages/bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -105,9 +106,22 @@ impl Module for BabylonModule {
_storage: &dyn Storage,
_querier: &dyn Querier,
_block: &BlockInfo,
_request: BabylonQuery,
request: BabylonQuery,
) -> anyhow::Result<Binary> {
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<ExecC, QueryC>(
Expand Down
6 changes: 3 additions & 3 deletions packages/bindings/src/query.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct ParamsResponse {
pub fn get_babylon_sdk_params(
querier: &QuerierWrapper<BabylonQuery>,
) -> Result<ParamsResponse, StdError> {
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: {}",
Expand Down

0 comments on commit f71162b

Please sign in to comment.