Tests
The Mimic Protocol Test Library (@mimicprotocol/test-ts) provides tools for simulating task execution to validate expected task behavior under different scenarios.
1. Getting Started
1.1. Installation
# Install dependencies
yarn add @mimicprotocol/test-ts
# Optional
yarn add @mimicprotocol/sdk1.2. Basic test structure
Every test follows this structure:
import { runTask, /* types */ } from '@mimicprotocol/test-ts'
describe('Task', () => {
// 1. Define context, inputs, mocks
const taskDir = './build'
const context = { /* required fields */ }
const inputs = { /* manifest inputs */ }
it('produces the expected intents', async () => {
// 2. Execute the task
const result = await runTask(taskDir, context, { inputs, /* needed mocks */ })
// 3. Check the task outputs
expect(result.success).to.be.true
expect(result.intents).to.have.lengthOf(N)
})
})1.3. Project setup
Create a basic task project:
2. Task Runner Reference
This section describes the parameters and outputs of the runTask function.
2.1. Parameters
2.1.1. Task directory
The directory where the compiled task .wasm is located.
2.1.2. Context
The context includes the fields needed during task execution.
2.1.3. Inputs
The values for the inputs defined in the manifest. For example, if the manifest declares:
Then, the inputs may be:
2.1.4. Prices mock
The responses for the price queries made in the task.
For example, if the task does:
Then, the prices mock may be:
2.1.5. Relevant tokens mock
The responses for the relevant tokens queries made in the task.
For example, if the task does:
Then, the relevant tokens mock may be:
2.1.6. Contract calls mock
The responses for the contract calls made in the task. Only for read functions, i.e., those that are not intended to generate intents.
Note: Token decimals and symbol are sometimes queried behind the scenes and need mocks in those cases.
For example, if the task does:
Then, the calls mock may be:
2.1.7. Subgraph queries mock
The responses for the subgraph queries made in the task.
For example, if the task does:
Then, the subgraph queries mock may be:
2.2. Output
The runTask function returns an object containing the following fields:
success- Boolean. True if the execution ended properly, or false if it had an error.timestamp- Number. Execution timestamp in milliseconds.fuelUsed- Number. Amount of fuel used during the execution.intents- Array of intents produced by the execution.logs- Array of logs produced by the execution. It may include error logs.
2.2.1. Intents
The fields depend on the type of intents produced by the execution.
Transfer
If the task creates a transfer intent:
Then, the test should be:
Swap
If the task creates a swap intent:
Then, the test should be:
Call
If the task creates a call intent:
Then, the test should be:
2.2.2. Logs
For example, if the task does:
Then, the test should be:
Last updated