0.0.80 • Published 1 year ago
@c-forge/polkahat-chai-matchers v0.0.80
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-matchersIf you are using yarn:
yarn add --dev @c-forge/polkahat-chai-matchersUsage
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:
revertedrevertedWithrevertedWithCustomErrorrevertedWithoutReasonrevertedWithPanicchangeEtherBalancechangeEtherBalanceschangeTokenBalancechangePSP22Balancesemit(with the only exception of chaining multipleemitmatchers)
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(...)