SmartWeave Testing
A testing client for SmartWeave contracts. You can execute any kind of interactWrite input against your contract. It does not require any connection to Arweave.
This enables fast and reliable testing. The new state
of the contract will be stored and by this enabling multi input testing.
Installation
yarn add --dev smartweave-testing
Usage
import SmartWeaveTester from "smartweave-testing"
import { handle } from [my-contract]
const caller = "..."
const initialState = {}
const smartweave = new SmartWeaveTester(handle, initialState, caller)
Executing an action
input = { function: "my_function" };
result = await smartweave.execute(input);
In case you don't want to update the state of your contract use execute({}, false)
Manipulating block height
If your contract uses SmartWeave.block.height, the client will make use of it's internal block logic.
Every time you execute an action, the block height will increase by 1. You can use
smartweave.block.height = ... to manually adjust the block height.
Examples
import SmartWeaveTester from "smartweave-testing"
import { handle } from [my-contract]
const caller = "..."
const initialState = {
balances: {}
}
const smartweave = new SmartWeaveTester(handle, initialState, caller)
let input, result;
input = { function: "dispense" };
result = await smartweave.execute(input);
if (result.balances[caller] !== 100) throw Error("Dispense does not work")
input = { function: "dispense" };
result = await smartweave.execute(input);
if (result.balances[caller] !== 200) throw Error("Dispense does not work")