@c-forge/polkahat-chai-matchers
v0.0.80
Published
Polkahat utils for testing
Downloads
71
Readme
Polkahat Chai Matchers
This plugin adds various capabilities to the Chai assertion library, making your smart contract tests easy to write and read.
Installation
npm install --save-dev @c-forge/polkahat-chai-matchers
If you are using yarn:
yarn add --dev @c-forge/polkahat-chai-matchers
Usage
After installing it, import the config in:
import "@c-forge/polkahat-chai-matchers";
Then you'll be able to use the matchers in your tests:
expect(await token.totalSupply()).to.equal(1_000_000);
await expect(token.transfer(token, 1000)).to.be.revertedWith(
"Cannot transfer to the contract itself"
);
await expect(token.transfer(recipient, 1000))
.to.emit(token, "Transfer")
.withArgs(owner, recipient, 1000);
Known issues
Chaining Async Matchers
Currently, the following matchers do not support chaining:
reverted
revertedWith
revertedWithCustomError
revertedWithoutReason
revertedWithPanic
changeEtherBalance
changeEtherBalances
changeTokenBalance
changePSP22Balances
emit
(with the only exception of chaining multipleemit
matchers)
Which means you can't do:
await expect(contract.f(...))
.to.changeEtherBalance(...)
.and.to.changeTokenBalance(...)
To work around this limitation, write separate assertions for each matcher:
const tx = contract.f(...);
await expect(tx).to.changeEtherBalance(...)
await expect(tx).to.changeTokenBalance(...)