Skip to content

Commit

Permalink
Added two minor test cases to place limit test
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Feb 18, 2024
1 parent 33ae708 commit 47f0ae4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions contracts/orderbook/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::types::{LimitOrder, OrderDirection};
use cosmwasm_std::{coin, ensure, BankMsg, DepsMut, Env, MessageInfo, Response, Uint128};
use cw_utils::must_pay;

#[allow(clippy::manual_range_contains, clippy::uninlined_format_args)]
#[allow(clippy::manual_range_contains)]
pub fn place_limit(
deps: DepsMut,
env: Env,
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn place_limit(
.add_attribute("book_id", book_id.to_string())
.add_attribute("tick_id", tick_id.to_string())
.add_attribute("order_id", order_id.to_string())
.add_attribute("order_direction", format!("{:?}", order_direction))
.add_attribute("order_direction", format!("{order_direction:?}"))
.add_attribute("quantity", quantity.to_string()))
}

Expand Down
25 changes: 24 additions & 1 deletion contracts/orderbook/src/tests/test_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn test_place_limit() {
}),
},
PlaceLimitTestCase {
name: "invalid tick id",
name: "invalid tick id (max)",
book_id: valid_book_id,
tick_id: MAX_TICK + 1,
quantity: Uint128::new(100),
Expand All @@ -84,6 +84,17 @@ fn test_place_limit() {
tick_id: MAX_TICK + 1,
}),
},
PlaceLimitTestCase {
name: "invalid tick id (min)",
book_id: valid_book_id,
tick_id: MIN_TICK - 1,
quantity: Uint128::new(100),
sent: Uint128::new(100),
order_direction: OrderDirection::Ask,
expected_error: Some(ContractError::InvalidTickId {
tick_id: MIN_TICK - 1,
}),
},
PlaceLimitTestCase {
name: "invalid quantity",
book_id: valid_book_id,
Expand All @@ -107,6 +118,18 @@ fn test_place_limit() {
required: Uint128::new(1000),
}),
},
PlaceLimitTestCase {
name: "excessive funds",
book_id: valid_book_id,
tick_id: 1,
quantity: Uint128::new(100),
sent: Uint128::new(500),
order_direction: OrderDirection::Ask,
expected_error: Some(ContractError::InsufficientFunds {
sent: Uint128::new(500),
required: Uint128::new(100),
}),
},
];

for test in test_cases {
Expand Down

0 comments on commit 47f0ae4

Please sign in to comment.