Skip to content

Commit

Permalink
fix query for sub state
Browse files Browse the repository at this point in the history
  • Loading branch information
tsilva-figure committed Jul 26, 2022
1 parent 488493a commit 0f06a21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/sub_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ pub struct SubInstantiateMsg {
#[derive(Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SubQueryMsg {
GetTerms {},
GetTransactions {},
GetState {},
}

#[derive(Deserialize, Serialize)]
pub struct SubTerms {
pub struct SubState {
pub recovery_admin: Addr,
pub lp: Addr,
pub raise: Addr,
pub commitment_denom: String,
pub investment_denom: String,
pub capital_denom: String,
pub capital_per_share: u64,
}
32 changes: 17 additions & 15 deletions src/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::state::{accepted_subscriptions, config_read, pending_subscriptions};
use crate::state::{
closed_subscriptions, outstanding_commitment_updates, outstanding_subscription_closures,
};
use crate::sub_msg::SubTerms;
use crate::sub_msg::{SubInstantiateMsg, SubQueryMsg};
use crate::sub_msg::{SubInstantiateMsg, SubQueryMsg, SubState};
use cosmwasm_std::Deps;
use cosmwasm_std::DepsMut;
use cosmwasm_std::Env;
Expand Down Expand Up @@ -146,11 +145,11 @@ pub fn try_accept_subscriptions(
}

for accept in accepts.iter() {
let terms: SubTerms = deps
let sub_state: SubState = deps
.querier
.query_wasm_smart(accept.subscription.clone(), &SubQueryMsg::GetTerms {})?;
.query_wasm_smart(accept.subscription.clone(), &SubQueryMsg::GetState {})?;

let attributes = get_attributes(deps.as_ref(), &terms)?;
let attributes = get_attributes(deps.as_ref(), &sub_state)?;

if !state.acceptable_accreditations.is_empty()
&& no_matches(&attributes, &state.acceptable_accreditations)
Expand Down Expand Up @@ -278,9 +277,9 @@ pub fn try_accept_commitment_update(
}
}

fn get_attributes(deps: Deps<ProvenanceQuery>, terms: &SubTerms) -> StdResult<HashSet<String>> {
fn get_attributes(deps: Deps<ProvenanceQuery>, sub_state: &SubState) -> StdResult<HashSet<String>> {
Ok(ProvenanceQuerier::new(&deps.querier)
.get_attributes(terms.lp.clone(), None as Option<String>)
.get_attributes(sub_state.lp.clone(), None as Option<String>)
.unwrap()
.attributes
.into_iter()
Expand Down Expand Up @@ -319,7 +318,6 @@ mod tests {
use crate::state::tests::set_pending;
use crate::state::tests::to_addresses;
use crate::state::State;
use crate::sub_msg::SubTerms;
use cosmwasm_std::coins;
use cosmwasm_std::from_binary;
use cosmwasm_std::testing::mock_env;
Expand All @@ -332,14 +330,18 @@ mod tests {
use cosmwasm_std::OwnedDeps;
use cosmwasm_std::SystemResult;

pub fn mock_sub_terms(
pub fn mock_sub_state(
) -> OwnedDeps<MemoryStorage, MockApi, MockContractQuerier, ProvenanceQuery> {
wasm_smart_mock_dependencies(&vec![], |_, _| {
SystemResult::Ok(ContractResult::Ok(
to_binary(&SubTerms {
to_binary(&SubState {
recovery_admin: Addr::unchecked("marketpalace"),
lp: Addr::unchecked("lp"),
raise: Addr::unchecked("raise_1"),
commitment_denom: String::from("raise_1.commitment"),
investment_denom: String::from("raise_1.investment"),
capital_denom: String::from("stable_coin"),
capital_per_share: 1,
})
.unwrap(),
))
Expand Down Expand Up @@ -579,7 +581,7 @@ mod tests {

#[test]
fn accept_subscription() {
let mut deps = mock_sub_terms();
let mut deps = mock_sub_state();
config(&mut deps.storage)
.save(&State::test_default())
.unwrap();
Expand Down Expand Up @@ -619,7 +621,7 @@ mod tests {

#[test]
fn accept_subscription_bad_actor() {
let mut deps = mock_sub_terms();
let mut deps = mock_sub_state();
set_pending(&mut deps.storage, vec!["sub_1"]);

// accept pending sub as gp
Expand All @@ -641,7 +643,7 @@ mod tests {

#[test]
fn accept_subscription_missing_acceptable_accreditation() {
let mut deps = mock_sub_terms();
let mut deps = mock_sub_state();

let mut state = State::test_default();
state.acceptable_accreditations = vec![String::from("506c")].into_iter().collect();
Expand All @@ -668,7 +670,7 @@ mod tests {

#[test]
fn accept_subscription_missing_required_tag() {
let mut deps = mock_sub_terms();
let mut deps = mock_sub_state();

let mut state = State::test_default();
state.other_required_tags = vec![String::from("misc")].into_iter().collect();
Expand All @@ -695,7 +697,7 @@ mod tests {

#[test]
fn accept_subscription_with_bad_amount() {
let mut deps = mock_sub_terms();
let mut deps = mock_sub_state();
set_pending(&mut deps.storage, vec!["sub_1"]);

// accept pending sub as gp
Expand Down

0 comments on commit 0f06a21

Please sign in to comment.