Skip to content

Commit

Permalink
add test-tube + fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
0xstepit committed May 9, 2024
1 parent d94dbc4 commit da3ec71
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 531 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,3 @@ jobs:
with:
command: clippy
args: -- -D warnings

- name: Generate Schema
uses: actions-rs/cargo@v1
with:
command: schema
args: --locked

- name: Schema Changes
# fails if any changes not committed
run: git diff --exit-code schema
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ just schema

## Considerations

`cw-atomic-swap` is a just a proof of concept and this section describes possible improvements and future works:

- Improve the quality of tests. At the moment just basic scenarios and the main contract flow have been tested. Without
test-tube tests, test coverage is $84.4%$.
- Improve storage layout to access an order just through the index using `IndexedMaps or other solutions.
- Allow users to cancel offers.
- Tests if due to the atomicity of the execution the code can be cleaned removing some of the validations.
- Give a sense to the config structure allowing to specify a fee or pause the market.
- Allow users to swap multiple coins.
- Tests a factory pattern to see if instantiating a different market for every token can improve UX.
- Support IBC to implement the full ICS20.
Other TODOs have been left in the contract to mark other possible improvements.
## License
This project is licensed under the MIT License - see the LICENSE file for details.
20 changes: 17 additions & 3 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub mod execute {
}
}

order.taker = Some(info.sender);
order.taker = Some(info.sender.clone());
order.status = OrderStatus::Accepted;

SWAP_ORDERS.save(deps.storage, (&maker, order_id), &order)?;
Expand All @@ -203,6 +203,7 @@ pub mod execute {
deps.storage,
&OrderPointer {
maker: maker.clone(),
taker: info.sender,
order_id,
},
)?;
Expand Down Expand Up @@ -354,7 +355,7 @@ pub mod query {
}

pub mod reply {
use cosmwasm_std::{DepsMut, Response};
use cosmwasm_std::{BankMsg, Coin, DepsMut, Response};

use crate::error::ContractError;
use crate::state::{OrderPointer, OrderStatus, ORDER_POINTER, SWAP_ORDERS};
Expand All @@ -364,20 +365,33 @@ pub mod reply {
/// NOTE: currently all order status are not used but still included to
/// easily extend functionalities in the future.
pub fn reply_confirm_order(deps: DepsMut) -> Result<Response, ContractError> {
let OrderPointer { order_id, maker } = ORDER_POINTER.load(deps.storage)?;
let OrderPointer {
order_id,
maker,
taker,
} = ORDER_POINTER.load(deps.storage)?;

let mut coin_out = Coin::default();
SWAP_ORDERS.update(
deps.storage,
(&maker, order_id),
|swap_order| match swap_order {
Some(mut order) => {
order.status = OrderStatus::Failed;
coin_out = order.coin_out.clone();
Ok(order)
}
None => Err(ContractError::Unauthorized),
},
)?;
ORDER_POINTER.remove(deps.storage);
let refund_msg = BankMsg::Send {
to_address: taker.to_string(),
amount: vec![coin_out],
};

Ok(Response::new()
.add_message(refund_msg)
.add_attribute("action", "reply")
.add_attribute("reason", "order_execution_failed"))
}
Expand Down
2 changes: 2 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub struct OrderPointer {
pub order_id: u64,
/// Address of the maker of the order.
pub maker: Addr,
/// Address of the taker of the order.
pub taker: Addr,
}

/// Data structure used to store the number of created deals.
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod multitest;
// mod testtube;
mod testtube;
mod unit_test;
Loading

0 comments on commit da3ec71

Please sign in to comment.