Skip to content

Commit

Permalink
staking
Browse files Browse the repository at this point in the history
  • Loading branch information
jbernal87 committed Mar 16, 2024
1 parent 7c455e0 commit cc26de7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
7 changes: 5 additions & 2 deletions contracts/injective-cosmwasm-mock/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
reply::{handle_create_derivative_order_reply, handle_create_order_reply},
};

use crate::query::{handle_token_factory_creation_fee, handle_token_factory_denom_total_supply};
use crate::query::{handle_staked_amount_query, handle_token_factory_creation_fee, handle_token_factory_denom_total_supply};
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult};
use cw2::set_contract_version;
use injective_cosmwasm::{create_deposit_msg, InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper};
Expand Down Expand Up @@ -132,7 +132,10 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, _env: Env, msg: QueryMsg) -> Std
} => handle_oracle_volatility_query(&querier, base_info, quote_info, max_age, include_raw_history, include_metadata),
QueryMsg::TestQueryOraclePrice { oracle_type, base, quote } => handle_oracle_price_query(&querier, &oracle_type, base, quote),
QueryMsg::TestQueryPythPrice { price_id } => handle_pyth_price_query(&querier, price_id),
QueryMsg::TestQueryStakedAmount { .. } => Ok(Default::default()),
QueryMsg::TestQueryStakedAmount {
delegator_address,
max_delegations,
} => handle_staked_amount_query(&querier, deps.api.addr_validate(delegator_address.as_str())?, max_delegations),
QueryMsg::TestQueryTokenFactoryDenomTotalSupply { denom } => handle_token_factory_denom_total_supply(&querier, denom),
QueryMsg::TestQueryTokenFactoryCreationFee {} => handle_token_factory_creation_fee(&querier),
QueryMsg::TestQueryContractRegistrationInfo { .. } => Ok(Default::default()),
Expand Down
2 changes: 1 addition & 1 deletion contracts/injective-cosmwasm-mock/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub enum QueryMsg {
price_id: String,
},
TestQueryStakedAmount {
delegator_address: Addr,
delegator_address: String,
max_delegations: u16,
},
TestQueryTokenFactoryDenomTotalSupply {
Expand Down
6 changes: 5 additions & 1 deletion contracts/injective-cosmwasm-mock/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{to_json_binary, Binary, StdResult};
use cosmwasm_std::{to_json_binary, Addr, Binary, StdResult};
use injective_cosmwasm::{CancellationStrategy, InjectiveQuerier, MarketId, OracleInfo, OracleType, OrderSide, SubaccountId};
use injective_math::FPDecimal;

Expand Down Expand Up @@ -151,3 +151,7 @@ pub fn handle_token_factory_denom_total_supply(querier: &InjectiveQuerier, denom
pub fn handle_token_factory_creation_fee(querier: &InjectiveQuerier) -> StdResult<Binary> {
to_json_binary(&querier.query_token_factory_creation_fee()?)
}

pub fn handle_staked_amount_query(querier: &InjectiveQuerier, delegator_address: Addr, max_delegations: u16) -> StdResult<Binary> {
to_json_binary(&querier.query_staked_amount(delegator_address, max_delegations)?)
}
1 change: 1 addition & 0 deletions contracts/injective-cosmwasm-mock/src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod test_exchange;
mod test_exchange_derivative;
mod test_oracle;
mod test_staking;
mod test_token_factory;
39 changes: 39 additions & 0 deletions contracts/injective-cosmwasm-mock/src/testing/test_staking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::msg::QueryMsg;
use crate::utils::{ExchangeType, Setup, BASE_DENOM};
use injective_cosmwasm::exchange::response::StakedAmountResponse;
use injective_std::types::cosmos::base::v1beta1::Coin;
use injective_std::types::cosmos::staking::v1beta1::MsgDelegate;
use injective_test_tube::{Account, Module, Staking, Wasm};

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_staked_amount() {
let env = Setup::new(ExchangeType::None);
let wasm = Wasm::new(&env.app);
let staking = Staking::new(&env.app);

let validator = env.app.get_first_validator_signing_account(BASE_DENOM.to_string(), 1.2f64).unwrap();

staking
.delegate(
MsgDelegate {
delegator_address: env.owner.address(),
validator_address: validator.address(),
amount: Some(Coin {
amount: "10".to_string(),
denom: BASE_DENOM.to_string(),
}),
},
&env.owner,
)
.unwrap();

let query_msg = QueryMsg::TestQueryStakedAmount {
delegator_address: validator.address(),
max_delegations: 100,
};

let res: StakedAmountResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
print!("{:?}", res);
assert_eq!(1, 2);
}

0 comments on commit cc26de7

Please sign in to comment.