This package has been deprecated

Author message:

This plugin has been deprecated in favor of @nomicfoundation/hardhat-chai-matchers

@matterlabs/hardhat-zksync-chai-matchers
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

hardhat-zksync-chai-matchers 🚀

zkSync Era's integration into the Chai assertion library is enabled by this Hardhat plugin, adding capabilities that make writing and reading smart contract tests easy."

Era Logo

⚠️ Version Compatibility Warning

Ensure you are using the correct version of the plugin with ethers:

  • For plugin version <1.0.0:

    • Compatible with ethers v5.
  • For plugin version ≥1.0.0:

    • Compatible with ethers v6 (⭐ Recommended)

📥 Installation

To install hardhat-zksync-chai-matchers plugin, run:

npm install -D @matterlabs/hardhat-zksync-chai-matchers

or

yarn add -D @matterlabs/hardhat-zksync-chai-matchers @nomicfoundation/hardhat-chai-matchers chai @nomiclabs/hardhat-ethers ethers

📖 Usage

After installing it, add the plugin to your Hardhat config:

import "@matterlabs/hardhat-zksync-chai-matchers";

Then you'll be able to use the matchers in your tests.

changeEtherBalance

Assert that the ether balance of an address changed by a specific amount:

await expect(() =>
  sender.transfer({
    to: receiver.address,
    amount: 2000,
  })
).to.changeEtherBalance(sender.address, -2000);

changeTokenBalance

Assert that an ERC20 token balance of an address changed by a specific amount:

await expect(sender.transfer({ to: receiver.address, amount: 5, token: token.address })).to.changeTokenBalance(token, sender, -5);

await expect(token.transfer(receiver.address, 5)).to.not.changeTokenBalance(token, sender, 0);

revertedWithCustomError

Assert that a transaction reverted with a specific custom error:

await expect(contract.setAmount(100)).to.be.reverted;

You can also use regular chai matchers like:

await expect(contract.setAmount(100)).to.emit(contract, "AmountUpdated");

expect("0x36615Cf349d7F6344891B1e7CA7C72883F5dc049").to.be.properAddress;

expect(await contract.getAmount()).to.equal(100);

📝 Documentation

In addition to the hardhat-zksync-chai-matchers, zkSync's Era website offers a variety of resources including:

Guides to get started: Learn how to start building on zkSync Era.
Hardhat zkSync Era plugins: Overview and guides for all Hardhat zkSync Era plugins.
Hyperscaling: Deep dive into hyperscaling on zkSync Era.

🤝 Contributing

Contributions are always welcome! Feel free to open any issue or send a pull request.

Go to CONTRIBUTING.md to learn about steps and best practices for contributing to zkSync hardhat tooling base repository.

🙌 Feedback, help and news

zkSync Era Discord server: for questions and feedback.
Follow zkSync Era on Twitter

Happy building!

Package Sidebar

Install

npm i @matterlabs/hardhat-zksync-chai-matchers

Weekly Downloads

14,076

Version

1.3.0

License

MIT

Unpacked Size

415 kB

Total Files

145

Last publish

Collaborators

  • ly0va
  • npm-matterlabs
  • popzxc