Custom Matchers
A set of Vitest matchers that can be used to make assertions on Clarity values with the Clarinet JS SDK.
Installation
npx @hirosystems/clarinet-sdk
toHaveClarityType
Check that a value has the right Clarity type, without checking its value.
Parameters
expectedType
RequiredClarityType
The Clarity type that the expected value should have.
toBeOk
Check that a response is (ok <ok-type>)
and has the expected value. Any Clarity value can be passed.
Parameters
expected
RequiredClarityValue
The ClarityValue
that the expected value should have.
toBeErr
Check that a response is (err <error-type>)
and has the expected value. Any Clarity value can be passed.
Parameters
expected
RequiredClarityValue
The ClarityValue
that the expected value should have.
toBeSome
Check that a response is (some <value>)
and has the expected value. Any Clarity value can be passed.
Parameters
expected
RequiredClarityValue
The ClarityValue
that the expected value should have.
toBeNone
Check that a response is (none)
.
toBeBool
Asserts the value of Clarity boolean (true
or false
).
Parameters
expected
Requiredboolean
The boolean
that the expected value should have.
toBeInt
Asserts the value of a Clarity integer.
Parameters
expected
Requiredboolean
The integer
that the expected value should have.
toBeUint
Asserts the value of a Clarity unsigned integer.
Parameters
expected
Requiredboolean
The unsigned integer
that the expected value should have.
toBeAscii
Asserts the value of a Clarity string-ascii.
Parameters
expected
Requiredstring
The string
that the expected value should have.
toBeUtf8
Asserts the value of a Clarity string-utf8.
Parameters
expected
Requiredstring
The string
that the expected value should have.
toBePrincipal
Asserts the value of a Clarity principal.
The principal can be a standard or a contract principal.
Parameters
expected
Requiredstring
The string
that the expected value should have.
toBeBuff
Asserts the value of a Clarity buffer. It takes an ArrayBuffer as an input.
For building a buffer, @stacks/transactions
provides some helper functions:
bufferFromAscii
bufferFromUtf8
bufferFromHex
Parameters
expected
RequiredUint8Array
The Uint8Array
buffer that the expected value should have.
toBeList
Asserts the value of a Clarity list containing an array of Clarity values.
Parameters
expected
RequiredClarityValue[]
The Uint8Array
buffer that the expected value should have.
import { Cl } from '@stacks/transactions';
const { result } = simnet.callReadOnlyFn(
'helpers',
'get-addresses',
[],
simnet.deployer
);
expect(result).toBeList(
[
Cl.standardPrincipal('ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'),
Cl.standardPrincipal('ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5'),
Cl.standardPrincipal('ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG')
]
);
toBeTuple
Asserts the value of a Clarity tuple.
Parameters
expected
Requiredobject
The object
of Clarity values that the expected value should have.
import { Cl } from '@stacks/transactions';
const { result } = simnet.callReadOnlyFn(
'pool',
'get-participant-data',
[Cl.standardPrincipal(simnet.deployer)],
simnet.deployer
);
expect(result).toBeTuple({
enrollmentBlock: Cl.some(Cl.uint(1)),
contributionAmount: Cl.some(Cl.uint(19000000)),
});