Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
feat: add date field so it can be queried
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Nov 29, 2023
1 parent 2dfcef5 commit 7ecaecd
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/action/execute/create_spot_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn create_spot_order(
info.sender.clone(),
order_target_denom,
&order_vec,
&env.block,
);

let bank_msg: BankMsg = BankMsg::Send {
Expand Down
6 changes: 5 additions & 1 deletion src/tests/cancel_spot_order/process_spot_order_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use cosmwasm_std::{coins, Coin};
use cosmwasm_std::{coins, Coin, Timestamp};

#[test]
fn process_spot_order_processing() {
Expand All @@ -26,6 +26,10 @@ fn process_spot_order_processing() {
owner_address: Addr::unchecked("user"),
order_target_denom: "ubtc".to_string(),
status: Status::Processed,
date: Date {
height: 20,
time: Timestamp::from_seconds(644),
},
};

// Create a mock message to instantiate the contract with the dummy order.
Expand Down
18 changes: 17 additions & 1 deletion src/tests/cancel_spot_orders/successfully_cancel_orders.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{to_json_binary, Coin};
use cosmwasm_std::{to_json_binary, Coin, Timestamp};

use super::*;

Expand All @@ -22,6 +22,10 @@ fn successfully_cancel_orders() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -35,6 +39,10 @@ fn successfully_cancel_orders() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -48,6 +56,10 @@ fn successfully_cancel_orders() {
owner_address: Addr::unchecked("user1"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -61,6 +73,10 @@ fn successfully_cancel_orders() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
];

Expand Down
18 changes: 17 additions & 1 deletion src/tests/cancel_spot_orders/successfully_cancel_orders_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{to_json_binary, Coin};
use cosmwasm_std::{to_json_binary, Coin, Timestamp};

use super::*;

Expand All @@ -22,6 +22,10 @@ fn successfully_cancel_orders_ids() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -35,6 +39,10 @@ fn successfully_cancel_orders_ids() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -48,6 +56,10 @@ fn successfully_cancel_orders_ids() {
owner_address: Addr::unchecked("user1"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -61,6 +73,10 @@ fn successfully_cancel_orders_ids() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
];

Expand Down
18 changes: 17 additions & 1 deletion src/tests/cancel_spot_orders/successfully_cancel_orders_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{to_json_binary, Coin};
use cosmwasm_std::{to_json_binary, Coin, Timestamp};

use super::*;

Expand All @@ -22,6 +22,10 @@ fn successfully_cancel_orders_type() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -35,6 +39,10 @@ fn successfully_cancel_orders_type() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -48,6 +56,10 @@ fn successfully_cancel_orders_type() {
owner_address: Addr::unchecked("user1"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -61,6 +73,10 @@ fn successfully_cancel_orders_type() {
owner_address: Addr::unchecked("user"),
order_target_denom: "".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
];

Expand Down
22 changes: 22 additions & 0 deletions src/tests/get_spot_orders/get_spot_orders.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cosmwasm_std::Timestamp;

use crate::msg::query_resp::GetSpotOrdersResp;

use super::*;
Expand Down Expand Up @@ -93,6 +95,10 @@ fn create_orders() -> Vec<SpotOrder> {
owner_address: Addr::unchecked("userA"),
order_target_denom: "btc".to_owned(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(600),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -106,6 +112,10 @@ fn create_orders() -> Vec<SpotOrder> {
owner_address: Addr::unchecked("userB"),
order_target_denom: "eth".to_owned(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(600),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -119,6 +129,10 @@ fn create_orders() -> Vec<SpotOrder> {
owner_address: Addr::unchecked("userC"),
order_target_denom: "xrp".to_owned(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(600),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -132,6 +146,10 @@ fn create_orders() -> Vec<SpotOrder> {
owner_address: Addr::unchecked("userD"),
order_target_denom: "ltc".to_owned(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(600),
},
},
SpotOrder {
order_type: OrderType::LimitBuy,
Expand All @@ -145,6 +163,10 @@ fn create_orders() -> Vec<SpotOrder> {
owner_address: Addr::unchecked("userE"),
order_target_denom: "ada".to_owned(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(600),
},
},
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use cosmwasm_std::{coins, Coin};
use cosmwasm_std::{coins, BlockInfo, Coin, Timestamp};

// This test case verifies the successful processing of a "limit buy" order in the contract.
// The scenario involves a "limit buy" order created by a user to buy ubtc at a specific price.
Expand Down Expand Up @@ -41,6 +41,11 @@ fn successful_process_limit_buy_order() {
Addr::unchecked("user"),
"ubtc".to_string(),
&vec![],
&BlockInfo {
height: 50,
time: Timestamp::from_seconds(600),
chain_id: "elys-app".to_string(),
},
);

// Create a mock message to instantiate the contract with the dummy order.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tests::read_processed_order_id::read_processed_order_id;

use super::*;
use cosmwasm_std::Coin;
use cosmwasm_std::{Coin, Timestamp};

#[test]
fn successful_process_5_of_10_orders() {
Expand Down Expand Up @@ -241,6 +241,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
rate: Decimal::from_atomics(Uint128::new(1700), 0).unwrap(),
},
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -254,6 +258,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -267,6 +275,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -280,6 +292,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::StopLoss,
Expand All @@ -293,6 +309,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -306,6 +326,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -319,6 +343,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -332,6 +360,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -345,6 +377,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
SpotOrder {
order_type: OrderType::LimitSell,
Expand All @@ -358,6 +394,10 @@ fn create_dummy_orders() -> Vec<SpotOrder> {
},
order_target_denom: "usdc".to_string(),
status: Status::NotProcessed,
date: Date {
height: 20,
time: Timestamp::from_seconds(500),
},
},
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::tests::read_processed_order_id::read_processed_order_id;

use super::*;
use cosmwasm_std::{coins, Coin};
use cosmwasm_std::{coins, BlockInfo, Coin, Timestamp};
// This test case verifies the successful processing of a "limit sell" order in the contract.
// The scenario involves a "limit sell" order created by a user to sell BTC at a specific price.
// - Initially, the BTC price is 20,000 USDC, and the order rate is set at 30,000 USDC per BTC.
Expand Down Expand Up @@ -47,6 +47,11 @@ fn successful_process_limit_sell_order() {
Addr::unchecked("user"),
"usdc".to_string(),
&vec![],
&BlockInfo {
height: 50,
time: Timestamp::from_seconds(600),
chain_id: "elys-app".to_string(),
},
);

// Create a mock message to instantiate the contract with the dummy order.
Expand Down
Loading

0 comments on commit 7ecaecd

Please sign in to comment.