Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.

[Not actively maintained] One-line setup for blazing-fast smart contracts tests

License

Notifications You must be signed in to change notification settings

OpenZeppelin/openzeppelin-test-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

63ed202 · Aug 20, 2021
Apr 15, 2020
Nov 16, 2020
Dec 17, 2019
Dec 22, 2020
May 12, 2021
Oct 26, 2019
Nov 14, 2019
Jul 16, 2020
Nov 11, 2019
Dec 22, 2020
Oct 26, 2019
Aug 20, 2021
Nov 14, 2019
Dec 3, 2019
Apr 9, 2021
Dec 22, 2020
Dec 22, 2019

Repository files navigation

⚠️ This project is not being actively maintained. It is advisable to use an alternative (Hardhat, Truffle).

OpenZeppelin Test Environment

Docs NPM Package Build Status

Blazing fast smart contract testing. One-line setup for an awesome testing experience.

  • Near-instant start up: have your code running in under 2s after typing npm test.
  • Test runner agnostic – from the familiarity of Mocha, to parallel tests using Jest or Ava!
  • Non-opinionated: use either @truffle/contract or web3-eth-contract as you see fit.
  • First class support for the OpenZeppelin Test Helpers.
  • Highly configurable: from gas limit and initial balance, to complex custom web3 providers.
  • No global variables, no hacks.

test-environment is the result of our learnings while developing the OpenZeppelin Contracts, combining best practices and the tools we've come to rely on over the years. We think you'll love it!

Overview

Installation

npm install --save-dev @openzeppelin/test-environment

Usage

By including require('@openzeppelin/test-environment') in your test files, a local ganache-powered blockchain with unlocked accounts will be spun up, and all tools configured to work with it.

Here's a quick sample of how using test-environment in a Mocha + Chai setup looks like.

const { accounts, contract } = require('@openzeppelin/test-environment');
const [ owner ] = accounts;

const { expect } = require('chai');

const MyContract = contract.fromArtifact('MyContract'); // Loads a compiled contract

describe('MyContract', function () {
  it('deployer is owner', async function () {
    const myContract = await MyContract.new({ from: owner });
    expect(await myContract.owner()).to.equal(owner);
  });
});

If you're used to truffle test, this probably looks very familiar. Follow our guide on migrating from Truffle to have your project running with test-environment in a breeze!

Note: if you'd rather not rely on truffle contracts and use web3 contract types directly, worry not: you can configure test-environment to use the web3-eth-contract abstraction.

Learn More

License

Released under the MIT License.