Skip to content

Commit

Permalink
feat(smart-contracts): add query config and tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Mar 11, 2024
1 parent 030772e commit 1593bcc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
7 changes: 5 additions & 2 deletions contracts/injective-auction-pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use injective_auction::auction_pool::{Config, ExecuteMsg, InstantiateMsg, QueryM
use crate::error::ContractError;
use crate::executions::{self, settle_auction};
use crate::helpers::{query_current_auction, validate_percentage};
use crate::queries;
use crate::state::{Auction, BIDDING_BALANCE, CONFIG, UNSETTLED_AUCTION};

const CONTRACT_NAME: &str = "crates.io:injective-auction-pool";
Expand Down Expand Up @@ -128,6 +129,8 @@ pub fn execute(
}

#[entry_point]
pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
unimplemented!()
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => queries::query_config(deps),
}
}
1 change: 1 addition & 0 deletions contracts/injective-auction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod error;
pub mod executions;
pub mod helpers;
pub mod msg;
pub mod queries;
pub mod state;

pub use crate::error::ContractError;
Expand Down
10 changes: 10 additions & 0 deletions contracts/injective-auction-pool/src/queries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_std::{to_json_binary, Binary, Deps, StdResult};
use injective_auction::auction_pool::ConfigResponse;

use crate::state::CONFIG;

pub fn query_config(deps: Deps) -> StdResult<Binary> {
to_json_binary(&ConfigResponse {
config: CONFIG.load(deps.storage)?,
})
}
11 changes: 7 additions & 4 deletions contracts/injective-auction-pool/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use cosmwasm_std::{
OwnedDeps, Querier, QuerierResult, QueryRequest, Uint128, WasmMsg,
};
use injective_auction::auction::{Coin, MsgBid, QueryCurrentAuctionBasketResponse};
use injective_auction::auction_pool::{ExecuteMsg, InstantiateMsg};
use injective_auction::auction_pool::{ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
use prost::Message;
use std::marker::PhantomData;
use treasurechest::tf::tokenfactory::TokenFactoryType;

use crate::contract::{execute, instantiate};
use crate::state::{BIDDING_BALANCE, CONFIG};
use crate::contract::{execute, instantiate, query};
use crate::state::BIDDING_BALANCE;
use crate::ContractError;

pub struct AuctionQuerier {
Expand Down Expand Up @@ -154,7 +154,10 @@ fn update_config() {
]
);

let config = CONFIG.load(&deps.storage).unwrap();
// query the config to check if it was updated
let msg = QueryMsg::Config {};
let res: ConfigResponse = from_json(&query(deps.as_ref(), env.clone(), msg).unwrap()).unwrap();
let config = res.config;
assert_eq!(config.owner, Addr::unchecked("new_owner"));
assert_eq!(config.rewards_fee, Decimal::percent(20));
assert_eq!(config.rewards_fee_addr, "new_rewards_addr".to_string());
Expand Down
10 changes: 9 additions & 1 deletion packages/injective_auction/src/auction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ pub enum ExecuteMsg {

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {}
pub enum QueryMsg {
#[returns(ConfigResponse)]
Config {},
}

#[cw_serde]
pub struct ConfigResponse {
pub config: Config,
}

#[cw_serde]
/// Config of the contract
Expand Down

0 comments on commit 1593bcc

Please sign in to comment.