Skip to content

Commit

Permalink
feat(smart-contracts): add tests for add & remove swap route failing …
Browse files Browse the repository at this point in the history
…scenarios
  • Loading branch information
nseguias committed Apr 19, 2024
1 parent 3faf786 commit b6422fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contracts/liquidity_hub/pool-manager/src/router/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ pub fn execute_swap_operations(

pub fn add_swap_routes(
deps: DepsMut,
env: Env,
sender: Addr,
// TODO: still need to save the swap route creator into state
_env: Env,
_sender: Addr,
swap_routes: Vec<SwapRoute>,
) -> Result<Response, ContractError> {
let mut attributes = vec![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,17 @@ mod router {
}));
});

// Re-add the same swap route should fail
suite.add_swap_routes(creator.clone(), vec![swap_route_1.clone()], |result| {
assert_eq!(
result.unwrap_err().downcast_ref::<ContractError>(),
Some(&ContractError::SwapRouteAlreadyExists {
offer_asset: "uwhale".to_string(),
ask_asset: "uusd".to_string()
})
);
});

// Let's query for the swap route
suite.query_swap_routes(|result| {
assert_eq!(result.unwrap().swap_routes[0], swap_route_1);
Expand Down Expand Up @@ -1471,6 +1482,17 @@ mod router {
suite.query_swap_routes(|result| {
assert_eq!(result.unwrap().swap_routes.len(), 0);
});

// Re-remove the same swap route should fail
suite.remove_swap_routes(creator.clone(), vec![swap_route_1.clone()], |result| {
assert_eq!(
result.unwrap_err().downcast_ref::<ContractError>(),
Some(&ContractError::NoSwapRouteForAssets {
offer_asset: "uwhale".to_string(),
ask_asset: "uusd".to_string()
})
);
});
}
}

Expand Down

0 comments on commit b6422fa

Please sign in to comment.