Skip to content

Commit

Permalink
First tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhaki committed Dec 3, 2023
1 parent 760eced commit c2ba3b0
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = "1.0.31"
rhaki-cw-plus = "0.6.12"
cosmwasm_otc-pkg = { path = "./package", version = "0.1.0"}
cosmwasm-otc-pkg = { path = "./package", version = "0.1.0"}
cosmwasm-otc = { path = "./contracts/otc", version = "0.1.0"}

cw-multi-test = "0.16.5"
4 changes: 2 additions & 2 deletions contracts/otc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cosmwasm-ootc"
name = "cosmwasm-otc"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -32,7 +32,7 @@ schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
rhaki-cw-plus = { workspace = true }
cosmwasm_otc-pkg = { workspace = true }
cosmwasm-otc-pkg = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
2 changes: 1 addition & 1 deletion contracts/otc/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn run_create_otc(
position.validate(deps.as_ref())?;

let (msgs_deposit, remaining_coins) =
collect_otc_items(&env, &position.ask, info.sender, info.funds)?;
collect_otc_items(&env, &position.offer, info.sender, info.funds)?;

let msgs_fee = send_fee(&env, &config.fee, &config.fee_collector, remaining_coins)?;

Expand Down
2 changes: 1 addition & 1 deletion package/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cosmwasm_otc-pkg"
name = "cosmwasm-otc-pkg"

version = { workspace = true }
authors = { workspace = true }
Expand Down
11 changes: 10 additions & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ cosmwasm-std = { workspace = true }
cw20 = { workspace = true }
cw721 = { workspace = true }
rhaki-cw-plus = { workspace = true }
cw-multi-test = { workspace = true }
cw-multi-test = { workspace = true }
cosmwasm-otc-pkg = { workspace = true }
cosmwasm-otc = { workspace = true }
anyhow = "1.0.75"
cw20-base = "1.1.1"
cw721-base = {version = "0.18.0", features = ["library"]}

schemars = { workspace = true }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }

56 changes: 56 additions & 0 deletions tests/src/app_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::{
collections::HashMap,
fmt::{self, Display},
};

use cosmwasm_std::{Binary, Coin, CustomQuery, Deps, DepsMut, Env, MessageInfo, Response, Uint128};
use cw_multi_test::ContractWrapper;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;

type ContractFn<T, C, E, Q> =
fn(deps: DepsMut<Q>, env: Env, info: MessageInfo, msg: T) -> Result<Response<C>, E>;

type QueryFn<T, E, Q> = fn(deps: Deps<Q>, env: Env, msg: T) -> Result<Binary, E>;

pub fn create_code<
T1: DeserializeOwned + fmt::Debug + 'static,
T2: DeserializeOwned + 'static,
T3: DeserializeOwned + 'static,
C: Clone + fmt::Debug + PartialEq + JsonSchema + 'static,
E1: Display + fmt::Debug + Send + Sync + 'static,
E2: Display + fmt::Debug + Send + Sync + 'static,
E3: Display + fmt::Debug + Send + Sync + 'static,
Q: CustomQuery + DeserializeOwned + 'static,
>(
instantiate: ContractFn<T2, C, E2, Q>,
execute: ContractFn<T1, C, E1, Q>,
query: QueryFn<T3, E3, Q>,
) -> Box<ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q>> {
let contract: ContractWrapper<T1, T2, T3, E1, E2, E3, C, Q> =
ContractWrapper::new(execute, instantiate, query);

Box::new(contract)
}

pub trait MergeCoin {
fn merge(self) -> Vec<Coin>;
}

impl MergeCoin for Vec<Coin> {
fn merge(self) -> Vec<Coin> {
let mut map: HashMap<String, Uint128> = HashMap::new();

for i in self {
if let Some(val) = map.get_mut(&i.denom) {
*val += i.amount
} else {
map.insert(i.denom.to_string(), i.amount);
}
}

map.into_iter()
.map(|(denom, amount)| Coin::new(amount.into(), denom))
.collect()
}
}
33 changes: 33 additions & 0 deletions tests/src/cw721_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use cosmwasm_std::{
entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult,
};
use cw721_base::{ContractError, Cw721Contract, ExecuteMsg, InstantiateMsg, QueryMsg};
use rhaki_cw_plus::serde_value::StdValue as Value;

#[entry_point]
pub fn instantiate(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> StdResult<Response> {
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default();
tract.instantiate(deps, env, info, msg)
}

#[entry_point]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg<Value, Empty>,
) -> Result<Response, ContractError> {
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default();
tract.execute(deps, env, info, msg)
}

#[entry_point]
pub fn query(deps: Deps, env: Env, msg: QueryMsg<Empty>) -> StdResult<Binary> {
let tract = Cw721Contract::<Value, Empty, Empty, Empty>::default();
tract.query(deps, env, msg)
}
Loading

0 comments on commit c2ba3b0

Please sign in to comment.