Integration Tests
General Setup
Example tests are provided in sei_cosmwasm_integration_tests.rs. The tests use setup_test() which utilize cw_multi_test to instantiate a wrapper version of a cosmwasm contract, for example, sei_tester which can be found in this repo under contracts/sei_tester.
A typical integration test will start with:
let mut app = mock_app;
let sei_tester_addr = setup_test;
followed by relevant any relevant Msg to execute or Query to run.
To execute a MsgToExecute you can use execute() or execute_multi():
app
.execute_multi
.unwrap;
To query MsgToQuery you can use query_wasm_smart():
app
.wrap
.query_wasm_smart
Module functionality is mocked at the chain level, more details on each module can be found below.
Dex Module
You can interact with a mocked version of the dex module in the following ways:
Messages:
PlaceOrders(orders, funds, contract_address): places the correspondingordersfor thecontract_address. Each order follows theOrderstruct and has anorder_id.CancelOrders(order_ids, contract_address): cancels the particularorder_idsfor thecontract_address.
Queries:
GetOrders(contract_address, account): returnsordersfor a given accountGetOrderById(contract_address, price_denom, asset_denom, id): returns particularorderbased onidandprice_denom, andasset_denom.OrderSimulation(contract_address, order): retuns the simulation of anorderagainst the existing placed orders for a givencontract_address.
Examples:
- Below is an example where you make an order and call
PlaceOrders()followed byGetOrders():
First placing an order:
let mut orders: = Vecnew;
let mut funds = Vec::new;
let contract_addr = "example_contract".to_string;
// Make order1
let price = raw;
let quantity = raw;
let price_denom = "USDC".to_string;
let asset_denom = "ATOM".to_string;
let order_type = Market;
let position_direction = Long;
let data = "".to_string;
let status_description = "order1".to_string;
let order1: Order = Order ;
orders.push;
let res = app
.execute_multi
.unwrap;
Then querying:
let res: GetOrdersResponse = app
.wrap
.query_wasm_smart
.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
...
To simulate an order:
let res: OrderSimulationResponse = app
.wrap
.query
.unwrap;
Oracle Module
The oracle module should only be interacted with after initializing the app with a price history of assets:
let app = mock_app;
Queries:
ExchangeRates(): returns the most recent exchange rates of all pairsOracleTwaps(lookback_seconds): returns the TWAP of all pairs for the providedlookback_seconds
Examples:
- Below are two examples of querying the oracle module:
ExchangeRates:
let res: ExchangeRatesResponse = app
.wrap
.query
.unwrap;
OracleTwaps:
let res: OracleTwapsResponse = app
.wrap
.query
.unwrap;