Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-helpers: re-organize, update to web3 1.0, and add utilities from dao-templates, react-boilerplate #43

Merged
merged 16 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/test-helpers/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
],
plugins: ['prettier', 'node', 'promise'],
rules: {
curly: ['error', 'all'],
'node/no-missing-require': [
'error',
{
Expand Down
120 changes: 120 additions & 0 deletions packages/test-helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Aragon test helpers

[![Status](https://img.shields.io/badge/stability-stable.svg?style=flat-square)](https://nodejs.org/api/documentation.html#documentation_stability_index)
[![npm version](https://img.shields.io/npm/v/@aragon/contract-helpers-test.svg?style=flat-square&color=lightgrey)](https://npmjs.org/package/@aragon/truffle-config-v4)

Test helpers for both generic Solidity and Aragon-related smart contracts.

> 🛠 This package is designed to be used in a [`web3.js@1`](js.readthedocs.io/en/1.0/) and [Truffle v5](https://www.trufflesuite.com/docs/truffle/overview) environment. If you are using [ethers.js](https://docs.ethers.io/v5/), you are likely much better served by [waffle](https://getwaffle.io/) which comes batteries-included with most of the [assertion matchers](https://ethereum-waffle.readthedocs.io/en/latest/matchers.html) you'll need.

## Quick start

Install with `yarn add --dev @aragon/contract-helpers-test`.

In your tests, you'll then import these utilities like so:

```js
const { bn, getEvents, MAX_UINT256, ZERO_ADDRESS } = require('@aragon/contract-helpers-test')
const { assertEvent, assertRevert } = require('@aragon/contract-helpers-test/asserts')
const { newDao, newDaoFactory } = require('@aragon/contract-helpers-test/aragon-os')
```

A number of contract mocks are also accessible through `@aragon/contract-helpers-test/contracts/` and may be useful for testing Aragon apps or other generic smart contracts. More documentation on these contract mocks is available in the [`contracts/`](./contracts) subdirectory.

## API

The test helpers are grouped into several main exports:

- [`@aragon/contract-helpers-test/`](#generic-utilities): generic utilities for on-chain interactions
- [`@aragon/contract-helpers-test/asserts`](#custom-assertions): custom assertions for on-chain interactions
- [`@aragon/contract-helpers-test/aragon-os`](#aragonos-utilities): aragonOS-related utilities
- [`@aragon/contract-helpers-test/aragon-os/asserts`](#aragonos-assertions): aragonOS-related assertions

Furthermore, the package also comes with:

- [`@aragon/contract-helpers-test/contracts`](#smart-contract-mocks): smart contract mocks
- [`@aragon/contract-helpers-test/scripts`](#shell-scripts): utility shell scripts

### Global state

The utilities exposed from the test helpers will automatically detect and bind to an injected Truffle environment (`artifacts` and `web3`).

However, it is possible to override this default binding or inject your own if none exist at the start of a file.

#### `ctx`

Individual utilities containing a trailing `ctx` parameter allow you to override the environment specifically for that single call.

```ts
type Artifacts = {
require(name: string): TruffleContract,
}

type Context = {
artifacts: Artifacts,
web3: Web3,
}
```

#### `injectArtifacts()`

Inject an `artifacts` object into the global default environment.

Note that all future calls will now reference this new `artifacts` object by default.

#### `injectWeb3()`

Inject a `web3` object into the global default environment.

Note that all future calls will now reference this new `web3` object by default.

### Generic utilities

#### Constants

The following constants are available, and mostly self-explanatory:

- Ethereum related
- `EMPTY_BYTES`
- `ZERO_ADDRESS`
- `ZERO_BYTES32`
- Number related
- `MAX_UINT64`
- `MAX_UINT192`
- `MAX_UINT256`
- Time related
- `NOW`: `Date.now()`, *in seconds*
- `TOMORROW`: one day ahead of `Date.now()`, *in seconds*
- `NEXT_WEEK`: one week ahead of `Date.now()`, *in seconds*
- `ONE_DAY`: duration for one day, *in seconds*
- `ONE_WEEK`: duration for one week, *in seconds*

### Custom assertions

### aragonOS utilities

#### Constants

The following constants are available:

- ACL
- `ANY_ENTITY`: address denoting any address has permission
- `BURN_MANAGER`: address denoting a permission has been frozen via discarding (burning) its manager
- EVM Scripts
- `EMPTY_CALLS_SCRIPT`: empty CallsScript (with spec id 1)

### aragonOS assertions

### Smart contract mocks

Please visit the documentation available in [`contracts/`](./contracts).

### Shell scripts

#### `ganache-cli.sh`

A utility script to start a local `ganache-cli` or `solidity-coverage` RPC node and initiate `npx truffle test`.

This script is generally considered deprecated but may be useful if your test framework still requires you to start a local test node manually.

If you haven't already done so, you may be interested in migrating to [buidler](https://buidler.dev/), which handles this connection for you.
45 changes: 0 additions & 45 deletions packages/test-helpers/assertEvent.js

This file was deleted.

70 changes: 0 additions & 70 deletions packages/test-helpers/assertRole.js

This file was deleted.

68 changes: 0 additions & 68 deletions packages/test-helpers/assertThrow.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/test-helpers/balance.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/test-helpers/block.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/test-helpers/blockNumber.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/test-helpers/call.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/test-helpers/contracts/0.4/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Solc 0.4 contract mocks

Usage: `import "@aragon/test-helpers/contracts/0.4/<contract>";`
Usage: `import "@aragon/contract-helpers-test/contracts/0.4/<contract>";`

- [`aragonOS/`](#aragonos)
- [`EtherTokenConstant`](#ethertokenconstant)
Expand Down Expand Up @@ -96,7 +96,7 @@ Note that all time manipulation now occurs through the shared `TimeHelpersMock`

## Tokens

Imported via `@aragon/test-helpers/contracts/0.4/token/`.
Imported via `@aragon/contract-helpers-test/contracts/0.4/token/`.

### `TokenMock`

Expand Down
4 changes: 2 additions & 2 deletions packages/test-helpers/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ For usage with Truffle, you will need to do something like:
// contracts/test/TestImport
pragma solidity ^0.4.24;

import "@aragon/test-helpers/contracts/0.4/aragonOS/TimeHelpersMock.sol";
import "@aragon/test-helpers/contracts/0.4/token/TokenMock.sol";
import "@aragon/contract-helpers-test/contracts/0.4/aragonOS/TimeHelpersMock.sol";
import "@aragon/contract-helpers-test/contracts/0.4/token/TokenMock.sol";


contract TestImport {
Expand Down
Loading