# @openzeppelin/test-helpers

> JavaScript testing helpers for Ethereum smart contract development.

Latest version **0.5.16** (published 2022-09-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @openzeppelin/test-helpers
pnpm add @openzeppelin/test-helpers
yarn add @openzeppelin/test-helpers
bun add @openzeppelin/test-helpers
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.16 |
| Published | 2022-09-06 |
| First published | 2019-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 43 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 410 |
| Author | OpenZeppelin Community |
| Maintainers | ericglau, frangio, amxx |
| Keywords | ethereum, smart, contracts, test, solidity, zeppelin, openzeppelin |

## Links

- npm: https://www.npmjs.com/package/@openzeppelin/test-helpers
- Repository: https://github.com/OpenZeppelin/openzeppelin-test-helpers
- Homepage: https://github.com/OpenZeppelin/openzeppelin-test-helpers#readme
- Issues: https://github.com/OpenZeppelin/openzeppelin-test-helpers/issues
- npm.io page: https://npm.io/package/@openzeppelin/test-helpers

## Dependencies (10)

- [chai](https://npm.io/package/chai.md) ^4.2.0
- [web3](https://npm.io/package/web3.md) ^1.2.5
- [semver](https://npm.io/package/semver.md) ^5.6.0
- [chai-bn](https://npm.io/package/chai-bn.md) ^0.2.1
- [ethjs-abi](https://npm.io/package/ethjs-abi.md) ^0.2.1
- [web3-utils](https://npm.io/package/web3-utils.md) ^1.2.5
- [ansi-colors](https://npm.io/package/ansi-colors.md) ^3.2.3
- [lodash.flatten](https://npm.io/package/lodash.flatten.md) ^4.4.0
- [@truffle/contract](https://npm.io/package/@truffle/contract.md) ^4.0.35
- [@openzeppelin/contract-loader](https://npm.io/package/@openzeppelin/contract-loader.md) ^0.6.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.5.16 (latest) — 2022-09-06
- 0.5.13-0 (next) — 2021-08-12
- 0.5.15 — 2021-10-05
- 0.5.14 — 2021-10-04
- 0.5.13 — 2021-08-12
- 0.5.12 — 2021-07-05
- 0.5.11 — 2021-04-29
- 0.5.10 — 2020-12-22
- 0.5.9 — 2020-10-28
- 0.5.8 — 2020-10-27
- 0.5.8-rc.0 — 2020-10-27
- 0.5.7 — 2020-10-13
- 0.5.6 — 2020-06-01
- 0.5.6-rc.0 — 2020-06-01
- 0.5.5 — 2020-03-12
- … 7 more at https://npm.io/package/@openzeppelin/test-helpers/versions

## README

# OpenZeppelin Test Helpers

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/test-helpers)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/test-helpers.svg)](https://www.npmjs.org/package/@openzeppelin/test-helpers)
[![Build Status](https://travis-ci.com/OpenZeppelin/openzeppelin-test-helpers.svg?branch=master)](https://travis-ci.com/OpenZeppelin/openzeppelin-test-helpers)

**Assertion library for Ethereum smart contract testing.** Make sure your contracts behave as expected.

 * Check that [transactions revert](https://docs.openzeppelin.com/test-helpers/api#expect-revert) for the correct reason
 * Verify that [events](https://docs.openzeppelin.com/test-helpers/api#expect-event) were emitted with the right values
 * Track [balance changes](https://docs.openzeppelin.com/test-helpers/api#balance) elegantly
 * Handle [very large numbers](https://docs.openzeppelin.com/test-helpers/api#bn)
 * Simulate the [passing of time](https://docs.openzeppelin.com/test-helpers/api#time)

## Overview

### Installation

```bash
npm install --save-dev @openzeppelin/test-helpers
```

#### Hardhat

Install `web3` and the `hardhat-web3` plugin.

```
npm install --save-dev @nomiclabs/hardhat-web3 web3
```

Remember to include the plugin in your configuration as explained in the [installation instructions](https://hardhat.org/plugins/nomiclabs-hardhat-web3.html#installation).

### Usage

Import `@openzeppelin/test-helpers` in your test files to access the different assertions and utilities.

```javascript
const {
  BN,           // Big Number support
  constants,    // Common constants, like the zero address and largest integers
  expectEvent,  // Assertions for emitted events
  expectRevert, // Assertions for transactions that should fail
} = require('@openzeppelin/test-helpers');

const ERC20 = artifacts.require('ERC20');

contract('ERC20', function ([sender, receiver]) {
  beforeEach(async function () {
    // The bundled BN library is the same one web3 uses under the hood
    this.value = new BN(1);

    this.erc20 = await ERC20.new();
  });

  it('reverts when transferring tokens to the zero address', async function () {
    // Conditions that trigger a require statement can be precisely tested
    await expectRevert(
      this.erc20.transfer(constants.ZERO_ADDRESS, this.value, { from: sender }),
      'ERC20: transfer to the zero address',
    );
  });

  it('emits a Transfer event on successful transfers', async function () {
    const receipt = await this.erc20.transfer(
      receiver, this.value, { from: sender }
    );

    // Event assertions can verify that the arguments are the expected ones
    expectEvent(receipt, 'Transfer', {
      from: sender,
      to: receiver,
      value: this.value,
    });
  });

  it('updates balances on successful transfers', async function () {
    this.erc20.transfer(receiver, this.value, { from: sender });

    // BN assertions are automatically available via chai-bn (if using Chai)
    expect(await this.erc20.balanceOf(receiver))
      .to.be.bignumber.equal(this.value);
  });
});
```

## Learn More

* Head to [Configuration](https://docs.openzeppelin.com/test-helpers/configuration) for advanced settings.
* For detailed usage information, take a look at the [API Reference](https://docs.openzeppelin.com/test-helpers/api).


## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/@openzeppelin/test-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
