0.5.16 • Published 3 years ago

@openzeppelin/test-helpers v0.5.16

Weekly downloads
8,544
License
MIT
Repository
github
Last release
3 years ago

OpenZeppelin Test Helpers

Docs NPM Package Build Status

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

Overview

Installation

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.

Usage

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

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

License

MIT

liquidity-provider-sc@sirenprotocol/contractsoff-ramp-hackathon@bamboo-defi/bamboo-defi-core@bamboo-defi/bamboodefi-core-testdashabi-farmalpes-smart@blockfold/auditetherless@livelyverse/lively-core-onchain@infinitebrahmanuniverse/nolb-_openzgu-erc777-basic@everything-registry/sub-chunk-691world-contractx1-sfcstaking-contractstemp-poolz-helper-v2temp-project-atemp-whitelisttest-sashimivaulttest-whitelist@devest/contracts@devest/dv-asset@defi-warrior/farm@cpchain-tools/dapps-test-helpers@bnex/protocol@bnsdomain/bns@bnsdomain/buffer@bnsdomain/dnssec-oracle@bnsdomain/registrar@bnsdomain/resolvers@bnsdomain/root@bnsdomain/solsha1@royalhalo/core@spherex-xyz/poolz-helper-v2stn5_membershiptoken-sale-contractstoken_distributiontoken_with_distributiontotammagni@artman325/community@artman325/nonfungibletokencontract@animoca/ethereum-contracts-core_library@authereum/contracts@alpaca-finance/xalpaca-contract@bamboo-defi/bamboodefi-core@bsc-bns/bscbns@brinkninja/brink-adapters@brinkninja/brink-verifiers@chainscore/contracts@chainscore/client@defilyswap/defilyswap-core@crus/routervesting-contracts@rsksmart/rif-scheduler-sdk@elpis-global/nfts@livelyversenpm/lively-core-onchain@levx/sushiswap-core@intercoin/nonfungibletokencontract@intercoin/sales@intercoin/staking@intercoin/tradedtokencontract@intercoin/community@intercoin/contest@intercoin/control@intercoin/fundcontract@intercoin/income@mahdiidarabi/token_with_distribution@manifoldxyz/creator-core-solidity@fairmint/c-org-contracts@interplanetary-lab/smart-contracts@knsdomain/buffer@knsdomain/dnssec-oracle@knsdomain/kns@knsdomain/resolvers@knsdomain/solsha1@kimtony/xxx@kgcdream2019/v1-core@dx-gov-test/dxdao-contracts@julswap/v1-core@pyroswap/pyro-farm@saladswap/saladswap@poolzfinance/poolz-helper-v2@pokeballfinance/ballswap-core@pokeballfinance/contract@pattayaswap-dev-libs/farm@passive-income/dpex-peripheral@passive-income/dpex-swap-core@passive-income/launchpad-contracts@passive-income/psi-contracts@obt/dao-share-template@obt/id@obt/minitoken@obt/staking@openvasp/contracts@overnight-contracts/blp-rebalancermerklemintopenswap-corerubic-bridge-basereleasemanager
0.5.16

3 years ago

0.5.14

4 years ago

0.5.15

4 years ago

0.5.13-0

4 years ago

0.5.13

4 years ago

0.5.12

4 years ago

0.5.11

4 years ago

0.5.10

4 years ago

0.5.8

5 years ago

0.5.9

5 years ago

0.5.8-rc.0

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.6-rc.0

5 years ago

0.5.5

5 years ago

0.5.5-rc.0

5 years ago

0.5.4

6 years ago

0.5.4-rc.0

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.2-rc.0

6 years ago

0.5.1

6 years ago