-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
258 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ pub mod contract; | |
mod error; | ||
pub mod state; | ||
pub mod utils; | ||
#[cfg(test)] | ||
pub mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
use alliance_protocol::alliance_oracle_types::{ChainId, ChainInfo}; | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::Addr; | ||
use alliance_protocol::alliance_oracle_types::{ChainId, ChainInfo, Config, LunaInfo}; | ||
use cw_storage_plus::{Item, Map}; | ||
|
||
#[cw_serde] | ||
pub struct Config { | ||
pub governance_addr: Addr, | ||
pub controller_addr: Addr, | ||
} | ||
|
||
pub const CONFIG: Item<Config> = Item::new("config"); | ||
pub const CHAINS_INFO: Map<ChainId, ChainInfo> = Map::new("chains_info"); | ||
pub const LUNA_INFO: Item<LunaInfo> = Item::new("luna_info"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use alliance_protocol::alliance_oracle_types::{ | ||
ChainInfoMsg, ChainsInfo, ExecuteMsg, LunaAlliance, NativeToken, QueryMsg, ChainId, ChainInfo, LunaInfo | ||
}; | ||
use cosmwasm_std::{ | ||
testing::{mock_env, mock_info}, | ||
Decimal, from_binary, | ||
}; | ||
use std::str::FromStr; | ||
use crate::{contract::{execute, query}}; | ||
|
||
pub mod test_utils; | ||
|
||
#[test] | ||
fn test_update_oracle_data() { | ||
// Create the environment where the contract will be executed | ||
let mut deps = test_utils::setup_contract(); | ||
|
||
// Msg representing off-chain oracle data that is send to the oracle contract | ||
let msg = ExecuteMsg::UpdateChainsInfo { | ||
chains_info: ChainsInfo { | ||
luna_price: Decimal::from_str("0.589013565473308100").unwrap(), | ||
protocols_info: vec![ChainInfoMsg { | ||
chain_id: "chain-1".to_string(), | ||
native_token: NativeToken { | ||
denom: "udenom".to_string(), | ||
token_price: Decimal::from_str("0.028076098081623823").unwrap(), | ||
annual_inflation: Decimal::from_str("0.04").unwrap(), | ||
}, | ||
luna_alliances: vec![LunaAlliance { | ||
ibc_denom: String::from( | ||
"ibc/05238E98A143496C8AF2B6067BABC84503909ECE9E45FBCBAC2CBA5C889FD82A", | ||
), | ||
normalized_reward_weight: Decimal::from_str("0.023809523809523810").unwrap(), | ||
annual_take_rate: Decimal::from_str("0.009999998624824108").unwrap(), | ||
total_lsd_staked: Decimal::from_str("126195.966393").unwrap(), | ||
rebase_factor: Decimal::from_str("1.178655688356438636").unwrap(), | ||
}], | ||
}], | ||
}, | ||
}; | ||
|
||
// Create the controller_addr sender to successfully send the transaction to the contract | ||
let info = mock_info("controller_addr", &[]); | ||
let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); | ||
assert_eq!(1, res.attributes.len()); | ||
assert_eq!("action", res.attributes[0].key); | ||
assert_eq!("update_chains_info", res.attributes[0].value); | ||
|
||
|
||
// Query only the chains info to validate the data was stored correctly in the contract | ||
let res = query(deps.as_ref(), mock_env(), QueryMsg::ChainsInfo).unwrap(); | ||
let res: Vec<(ChainId, ChainInfo)> = from_binary(&res).unwrap(); | ||
assert_eq!(1, res.len()); | ||
|
||
let key = res[0].0.clone(); | ||
assert_eq!("chain-1", key); | ||
|
||
let chain_info = res[0].1.clone(); | ||
assert_eq!(NativeToken { | ||
denom: "udenom".to_string(), | ||
token_price: Decimal::from_str("0.028076098081623823").unwrap(), | ||
annual_inflation: Decimal::from_str("0.04").unwrap(), | ||
}, chain_info.native_token); | ||
|
||
let luna_alliances = chain_info.luna_alliances.clone(); | ||
assert_eq!(1, luna_alliances.len()); | ||
assert_eq!(LunaAlliance { | ||
ibc_denom: String::from( | ||
"ibc/05238E98A143496C8AF2B6067BABC84503909ECE9E45FBCBAC2CBA5C889FD82A", | ||
), | ||
normalized_reward_weight: Decimal::from_str("0.023809523809523810").unwrap(), | ||
annual_take_rate: Decimal::from_str("0.009999998624824108").unwrap(), | ||
total_lsd_staked: Decimal::from_str("126195.966393").unwrap(), | ||
rebase_factor: Decimal::from_str("1.178655688356438636").unwrap(), | ||
}, luna_alliances[0]); | ||
|
||
// Query the Luna info to validate the data was stored correctly in the contract | ||
let res = query(deps.as_ref(), mock_env(), QueryMsg::LunaInfo).unwrap(); | ||
let luna_info: LunaInfo = from_binary(&res).unwrap(); | ||
assert_eq!(Decimal::from_str("0.589013565473308100").unwrap(), luna_info.luna_price); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use alliance_protocol::alliance_oracle_types::{InstantiateMsg, QueryMsg, Config}; | ||
use cosmwasm_std::{testing::{mock_dependencies, mock_info, mock_env, MockStorage, MockApi, MockQuerier}, from_binary, OwnedDeps, Empty}; | ||
|
||
use crate::contract::{instantiate, query}; | ||
|
||
|
||
pub fn setup_contract() -> OwnedDeps<MockStorage, MockApi, MockQuerier, Empty> { | ||
let mut deps = mock_dependencies(); | ||
let msg = InstantiateMsg { | ||
data_expiry_seconds: 60, | ||
controller_addr: "controller_addr".to_string(), | ||
governance_addr: "governance_addr".to_string(), | ||
}; | ||
let info = mock_info("creator", &[]); | ||
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); | ||
assert_eq!(0, res.messages.len()); | ||
|
||
let cfg = query(deps.as_ref(), mock_env(), QueryMsg::Config).unwrap(); | ||
|
||
let cfg: Config = from_binary(&cfg).unwrap(); | ||
assert_eq!("controller_addr", cfg.controller_addr); | ||
assert_eq!("governance_addr", cfg.governance_addr); | ||
assert_eq!(60, cfg.data_expiry_seconds); | ||
|
||
deps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.