Skip to content

Commit

Permalink
tests works
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 14, 2024
1 parent 300e8a1 commit 54dde39
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 39 deletions.
8 changes: 5 additions & 3 deletions contracts/cosmwasm/order/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub(crate) fn expected_some_funds_in_route() -> StdError {
}

pub fn banks_funds_must_be_at_least_routed(has: &Coin, expected: &Coin) -> StdError {
StdError::generic_err(format!("banks_funds_must_be_at_least_routed {:?} => {:?} ", has, expected))

}
StdError::generic_err(format!(
"banks_funds_must_be_at_least_routed {:?} => {:?} ",
has, expected
))
}
9 changes: 4 additions & 5 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,13 @@ impl OrderContract<'_> {

// hey, need some other data structure for this
let solver_order = solver_orders
.iter_mut()
.find(|x| x.order.order_id == order.order_id)
.expect("solver order");
.iter_mut()
.find(|x| x.order.order_id == order.order_id)
.expect("solver order");

solver_order.order = order.clone();

let (event, remaining) = if order.given.amount.is_zero() {

api.debug(&format!("mantis::order::filled::full {:?}", order.order_id));

self.orders.remove(storage, order.order_id.u128());
Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm/outpost/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn force_asset(_: auth::Admin, deps: DepsMut, msg: AssetItem) -> Resu
pub(crate) fn get_asset_by_id(deps: Deps, asset_id: AssetId) -> Result<AssetItem> {
ASSETS
.may_load(deps.storage, asset_id)?
.ok_or(ContractError::AssetIdNotFound)
.ok_or(ContractError::AssetIdNotFound(asset_id))
}

/// Fetches information about given asset by its local reference.
Expand All @@ -39,8 +39,8 @@ pub(crate) fn get_local_asset_by_reference(
reference: AssetReference,
) -> Result<AssetItem> {
LOCAL_ASSETS
.may_load(deps.storage, reference)?
.ok_or(ContractError::AssetIdNotFound)
.may_load(deps.storage, reference.clone())?
.ok_or(ContractError::AssetByReferenceNotFound(reference))
}

/// Removes an existing asset from the registry; errors out if asset doesn’t
Expand Down
12 changes: 8 additions & 4 deletions contracts/cosmwasm/outpost/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cosmwasm_std::{
entry_point, wasm_execute, Addr, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Response, StdError,
};
use cvm_route::asset::{AssetReference, NetworkAssetItem};
use cvm_route::asset::{AssetReference, NetworkAssetItem};
use cw20::{Cw20Contract, Cw20ExecuteMsg};

use cvm_runtime::{
Expand Down Expand Up @@ -101,9 +101,13 @@ fn handle_config_msg(
to_network_id,
from_asset_id,
to_asset_id,
}) => {
assets::force_asset_to_network_map(auth, deps, from_asset_id, to_network_id, to_asset_id)
}
}) => assets::force_asset_to_network_map(
auth,
deps,
from_asset_id,
to_network_id,
to_asset_id,
),
ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg),
ConfigSubMsg::ForceInstantiate { user_origin, salt } => {
executor::force_instantiate(auth, env.contract.address.clone(), deps, user_origin, salt)
Expand Down
6 changes: 5 additions & 1 deletion contracts/cosmwasm/outpost/src/contract/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub fn query(deps: Deps, _env: Env, msg: msg::QueryMsg) -> Result<Binary> {
.and_then(|exchange| Ok(to_json_binary(&msg::GetExchangeResponse { exchange })?)),
GetConfig {} => {
crate::state::get_config(deps).and_then(|config| Ok(to_json_binary(&config)?))
} // GetRoute { program } => router::get_route(deps, program),
}
GetAllAssetIds {} => crate::state::assets::get_all_assets(deps)
.and_then(|x| Ok(to_json_binary(&x)?))
.map_err(Into::into),
// GetRoute { program } => router::get_route(deps, program),
}
}
3 changes: 3 additions & 0 deletions contracts/cosmwasm/outpost/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cosmwasm_std::{IbcOrder, Response, StdError};
use cvm_route::{asset::AssetReference, venue::AssetsVenueItem};
use cvm_runtime::{AssetId, NetworkId};
use ibc_core_host_types::error::IdentifierError;
use thiserror::Error;
Expand Down Expand Up @@ -27,6 +28,8 @@ pub enum ContractError {
FailedToSerialize,
#[error("Asset not been found in the registry {0}.")]
AssetIdNotFound(AssetId),
#[error("Asset by reference not found {0}.")]
AssetByReferenceNotFound(AssetReference),
#[error("Exchange not been found in the registry.")]
ExchangeNotFound,
#[error("The contract must be initialized first.")]
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub use alloc::format;
pub use cosmwasm_std::Addr;
pub use cvm_runtime::{outpost::config::*, shared::Displayed};
pub use cw_storage_plus::Map;
pub use enumn::N as EnumNum;
pub use ibc_core_host_types::identifiers::ChannelId;
pub use serde::{Deserialize, Serialize};
pub use enumn::N as EnumNum;
8 changes: 8 additions & 0 deletions crates/cvm-route/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Display;

use crate::{prelude::*, transport::ForeignAssetId};
use cvm::{AssetId, NetworkId};

Expand Down Expand Up @@ -98,6 +100,12 @@ impl AssetReference {
}
}

impl Display for AssetReference {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(&self.denom())
}
}

#[cfg(feature = "cosmwasm")]
impl cw_storage_plus::PrimaryKey<'_> for AssetReference {
type Prefix = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ pub struct SwapAmountInRoute {
pub pool_id: u64,
#[prost(string, tag = "2")]
pub token_out_denom: String,
}
}
4 changes: 3 additions & 1 deletion crates/cvm-runtime/src/outpost/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use cvm_route::{
asset::{AssetItem, NetworkAssetItem}, exchange::ExchangeItem, transport::NetworkToNetworkItem,
asset::{AssetItem, NetworkAssetItem},
exchange::ExchangeItem,
transport::NetworkToNetworkItem,
venue::AssetsVenueItem,
};

Expand Down
6 changes: 5 additions & 1 deletion crates/cvm-runtime/src/outpost/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub enum QueryMsg {
returns(GetAssetResponse)
)]
GetAssetById { asset_id: AssetId },

#[cfg_attr(
feature = "json-schema", // all(feature = "json-schema", not(target_arch = "wasm32")),
returns(Vec<AssetItem>)
)]
GetAllAssetIds {},
/// Returns [`AssetItem`] for an asset with given local reference.
#[cfg_attr(
feature = "json-schema", // all(feature = "json-schema", not(target_arch = "wasm32")),
Expand Down
45 changes: 26 additions & 19 deletions mantis/node/tests/cvms.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use bounded_collections::Get;
use cosmrs::tendermint::block::Height;
use cosmwasm_std::{Addr, Coin, Coins, Empty};
use cosmwasm_std::{Addr, Coin, Coins, Empty, Querier, QuerierWrapper};
use cvm_route::{
asset::{self, AssetItem, AssetReference, NetworkAssetItem},
exchange::ExchangeItem,
transport::{NetworkToNetworkItem, OtherNetworkItem},
venue::AssetsVenueItem,
};
use cw_cvm_outpost::msg::{CvmGlt, HereItem, NetworkItem, OutpostId};
use cw_cvm_outpost::msg::{CvmGlt, GetAssetResponse, HereItem, NetworkItem, OutpostId};
use cw_mantis_order::{OrderItem, OrderSubMsg, SolutionSubMsg};
use cw_multi_test::{App, Bank, BankKeeper, Contract, ContractWrapper, Executor};
use cw_multi_test::{App, Bank, BankKeeper, Contract, ContractWrapper, Executor, StargateQuery};
use mantis_node::mantis::cosmos::{client::Tip, signer::from_mnemonic};
use serde::de;

Expand Down Expand Up @@ -41,7 +41,7 @@ async fn cvm_devnet_case() {

let sender = Addr::unchecked("juno1g2rahf5846rxzp3fwlswy08fz8ccuwk03k57y");
let cw_cvm_outpost_instantiate = cw_cvm_outpost::msg::InstantiateMsg(HereItem {
network_id: 3.into(),
network_id: 1.into(),
admin: sender.clone(),
});
let cw_cvm_outpost_contract = centauri
Expand Down Expand Up @@ -296,26 +296,33 @@ async fn cvm_devnet_case() {
)
.await;

centauri.execute_contract(
sender.clone(),
cw_mantis_contract.clone(),
&solution[0],
&[],
).unwrap();
centauri
.execute_contract(
sender.clone(),
cw_mantis_contract.clone(),
&solution[0],
&[],
)
.unwrap();

centauri.update_block(|x| {
x.height += 2;
});

println!("=========================================================================================");
centauri.execute_contract(
sender.clone(),
cw_mantis_contract.clone(),
&solution[0],
&[],
).unwrap();

//panic!("solution: {:?}", solution);
let query = cvm_runtime::outpost::QueryMsg::GetAllAssetIds {};
let cvm_glt: Vec<AssetItem> = centauri
.wrap()
.query_wasm_smart(cw_cvm_outpost_contract, &query)
.unwrap();
//panic!("{:?}", cvm_glt);
centauri
.execute_contract(
sender.clone(),
cw_mantis_contract.clone(),
&solution[0],
&[],
)
.expect("https://github.com/CosmWasm/cw-multi-test/blob/main/src/wasm.rs#L722");
}

enum True {}
Expand Down

0 comments on commit 54dde39

Please sign in to comment.