To aid in testing we provide a separate mock_dependencies_custom function that provides handlers for specific ADO contracts. This can be found here. The following mock variables are used:
The admin_address has ownership of the aOS and as such can make adjustments as required. It is also registered under the VFS as user am, therefore any ADOs registered with the admin address would be accessible via ~/am/... when using the VFS.
The next step is to add some ADOs to the setup, this can be done with the store_ado method:
let andr =mock_andromeda();andr.store_ado(&mut router, mock_andromeda_app(), "app");
Here the second parameter is a cw-multi-testmock contract and the third is a name for the ADO. This can be used to access the code id by calling andr.get_code_id(&router, "app"). Repeat this process for any ADOs you wish to add (including your own).
Creating a Mock Contract
All our mock contracts implement two structs; MockContract and MockADO. The MockContract struct exposes simple query and execute methods while MockADO exposes any messages that an ADO may provide such as ownership and permissioning. To implement both these structs in a quick and easy manner we have provided a macro:
use andromeda_test::{mock_ado, MockADO, MockContract};usecrate::msg::{ExecuteMsg, QueryMsg};pubstructMyMockADO(Addr);mock_ado!(MyMockADO, ExecuteMsg, QueryMsg);implMyMockADO {// Expose any useful methods in here}
Once this is done you can either create the contract directly or you can create it as part of an app. If you create it using the MockAppstruct provided in andromeda-app-contract the mock contract struct can be created via a query:
let app =MockApp::instantiate(...);let my_ado:MyMockADO= app.query_ado_by_component_name(&router, my_ado_name);
Mock structs have been provided for most ADOs however they are still a work in progress.
Test Scaffolding
To help with setting up a testing environment using aOS we can use the MockAndromedaBuilder struct. This allows definition of what wallets and contracts you would like to use while testing:
This generates two wallets ("owner" and "user1") and assigns 1000 uandr to the "owner" wallet. Here the provided names are not addresses but are simply names. These can be accessed using:
let owner = andr.get_wallet("owner");let user1 = andr.get_wallet("user1");
Next we include the contracts we would like to use:
In this case we would like to use the CW721 contract and the App contract, the provided names can also be version (e.g. "[email protected]"). The stored code IDs for these can be accessed via their names like so:
let app_code_id = andr.get_code_id("cw721");
The rest of the integration test should continue as usual.