Skip to content

Commit

Permalink
Merge pull request #209 from InjectiveLabs/f/mocked-bank-supply
Browse files Browse the repository at this point in the history
chore: add mocked bank supply
  • Loading branch information
gorgos authored Jan 29, 2024
2 parents 424abf4 + 12e4bc9 commit aa4f051
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/atomic-order-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cosmwasm-storage = { version = "1.5.0", features = [ "iterator" ] }
cw-storage-plus = { version = "1.2.0" }
cw-utils = { version = "0.16.0" }
cw2 = { version = "0.16.0" }
injective-cosmwasm = { version = "0.2.18", path = "../../packages/injective-cosmwasm" }
injective-cosmwasm = { version = "0.2.21", path = "../../packages/injective-cosmwasm" }
injective-math = { version = "0.2.4", path = "../../packages/injective-math" }
injective-protobuf = { version = "0.2.2", path = "../../packages/injective-protobuf" }
protobuf = { version = "2.28.0", features = [ "with-bytes" ] }
Expand Down
2 changes: 1 addition & 1 deletion contracts/dummy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
cosmwasm-std = { version = "1.5.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] }
cw-storage-plus = { version = "1.2.0" }
cw2 = { version = "0.16.0" }
injective-cosmwasm = { version = "0.2.18", path = "../../packages/injective-cosmwasm" }
injective-cosmwasm = { version = "0.2.21", path = "../../packages/injective-cosmwasm" }
schemars = "0.8.8"
serde = { version = "1.0.136", default-features = false, features = [ "derive" ] }
thiserror = { version = "1.0.30" }
2 changes: 1 addition & 1 deletion packages/injective-cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "injective-cosmwasm"
readme = "README.md"
repository = "https://github.com/InjectiveLabs/cw-injective/tree/dev/packages/injective-cosmwasm"
version = "0.2.18"
version = "0.2.21"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
34 changes: 31 additions & 3 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;
use cosmwasm_std::testing::{MockApi, MockStorage};
use cosmwasm_std::{
from_json, to_json_binary, Addr, AllBalanceResponse, BalanceResponse, BankQuery, Binary, Coin, ContractResult, OwnedDeps, Querier, QuerierResult,
QueryRequest, SystemError, SystemResult, Uint128, WasmQuery,
QueryRequest, SupplyResponse, SystemError, SystemResult, Uint128, WasmQuery,
};

use injective_math::FPDecimal;
Expand All @@ -18,6 +18,7 @@ use crate::oracle::{
types::{OracleHistoryOptions, OracleType, PriceState, PythPriceState},
volatility::TradeHistoryOptions,
};

use crate::tokenfactory::response::{TokenFactoryCreateDenomFeeResponse, TokenFactoryDenomSupplyResponse};
use crate::wasmx::response::QueryContractRegistrationInfoResponse;
use crate::{
Expand Down Expand Up @@ -254,6 +255,14 @@ fn default_token_factory_denom_total_supply_handler() -> QuerierResult {
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}

fn default_bank_total_supply_handler() -> QuerierResult {
let response = SupplyResponse::new(Coin {
denom: "inj".to_string(),
amount: Uint128::from(1000u128),
});
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}

fn default_token_factory_denom_creation_fee_handler() -> QuerierResult {
let response = TokenFactoryCreateDenomFeeResponse {
fee: vec![Coin::new(10, "inj")],
Expand Down Expand Up @@ -495,6 +504,7 @@ pub struct WasmMockQuerier {
pub token_factory_denom_creation_fee_handler: Option<Box<dyn HandlesFeeQuery>>,
pub balance_query_handler: Option<Box<dyn HandlesBankBalanceQuery>>,
pub all_balances_query_handler: Option<Box<dyn HandlesBankAllBalancesQuery>>,
pub total_supply_handler: Option<Box<dyn HandlesDenomSupplyQuery>>,
pub registered_contract_info_query_handler: Option<Box<dyn HandlesByAddressQuery>>,
pub spot_market_orderbook_response_handler: Option<Box<dyn HandlesPriceLevelsQuery>>,
pub derivative_market_orderbook_response_handler: Option<Box<dyn HandlesDerivativePriceLevelsQuery>>,
Expand Down Expand Up @@ -533,6 +543,10 @@ impl WasmMockQuerier {
Some(handler) => handler.handle(address.to_string()),
None => default_all_balances_bank_query_handler(),
},
BankQuery::Supply { denom } => match &self.total_supply_handler {
Some(handler) => handler.handle(denom.to_string()),
None => default_bank_total_supply_handler(),
},
_ => panic!("unsupported"),
},
QueryRequest::Custom(query) => match query.query_data.clone() {
Expand Down Expand Up @@ -753,6 +767,7 @@ impl WasmMockQuerier {
spot_market_orderbook_response_handler: None,
derivative_market_orderbook_response_handler: None,
market_atomic_execution_fee_multiplier_response_handler: None,
total_supply_handler: None,
}
}
}
Expand Down Expand Up @@ -781,8 +796,8 @@ impl TestDeposit {

pub mod handlers {
use cosmwasm_std::{
to_json_binary, AllBalanceResponse, BalanceResponse, Binary, Coin, ContractResult, QuerierResult, StdResult, SystemError, SystemResult,
Uint128,
to_json_binary, AllBalanceResponse, BalanceResponse, Binary, Coin, ContractResult, QuerierResult, StdResult, SupplyResponse, SystemError,
SystemResult, Uint128,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -1180,6 +1195,19 @@ pub mod handlers {
}))
}

pub fn create_bank_supply_handler(supply: Uint128) -> Option<Box<dyn HandlesDenomSupplyQuery>> {
struct Temp {
supply: Uint128,
}
impl HandlesDenomSupplyQuery for Temp {
fn handle(&self, denom: String) -> QuerierResult {
let response = SupplyResponse::new(Coin { denom, amount: self.supply });
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}
}
Some(Box::new(Temp { supply }))
}

pub fn create_denom_supply_handler(supply: Uint128) -> Option<Box<dyn HandlesDenomSupplyQuery>> {
struct Temp {
supply: Uint128,
Expand Down
1 change: 1 addition & 0 deletions packages/injective-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub enum InjectiveQuery {
PerpetualMarketFunding {
market_id: MarketId,
},
// Make sure you are aware of the potential to run out of gas when using this query
MarketVolatility {
market_id: MarketId,
trade_history_options: TradeHistoryOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/injective-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = { version = "1.0.66" }
base64 = { version = "0.13.1" }
cosmwasm-std = { version = "1.5.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] }
cw-multi-test = { version = "0.16.2" }
injective-cosmwasm = { version = "0.2.18", path = "../injective-cosmwasm" }
injective-cosmwasm = { version = "0.2.21", path = "../injective-cosmwasm" }
injective-math = { version = "0.2.4", path = "../injective-math" }
rand = { version = "0.4.6" }
secp256k1 = { version = "0.6.2" }
Expand Down

0 comments on commit aa4f051

Please sign in to comment.