0.0.12 • Published 2 months ago

wookashwackomytest-pendzl-tests v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

npm

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 wookashwackomytest-polkahat-chai-matchers

If you are using yarn:

yarn add --dev wookashwackomytest-polkahat-chai-matchers

Usage

After installing it, import the config in:

import "wookashwackomytest-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
  • changeTokenBalances
  • emit (with the only exception of chaining multiple emit 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(...)