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

added a test helper with common constants #1400

Merged
merged 21 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from 20 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
4 changes: 1 addition & 3 deletions test/access/Roles.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { assertRevert } = require('../helpers/assertRevert');

const { ZERO_ADDRESS } = require('../helpers/constants');
const RolesMock = artifacts.require('RolesMock');

require('chai')
.should();

contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.roles = await RolesMock.new();
});
Expand Down
2 changes: 1 addition & 1 deletion test/access/roles/PublicRole.behavior.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { assertRevert } = require('../../helpers/assertRevert');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const expectEvent = require('../../helpers/expectEvent');

require('chai')
Expand All @@ -10,7 +11,6 @@ function capitalize (str) {

function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], rolename) {
rolename = capitalize(rolename);
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

describe('should behave like public role', function () {
beforeEach('check preconditions', async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expectEvent = require('../helpers/expectEvent');
const { ether } = require('../helpers/ether');
const { assertRevert } = require('../helpers/assertRevert');
const { ethGetBalance } = require('../helpers/web3');
const { ZERO_ADDRESS } = require('../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -17,7 +18,6 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
const value = ether(0.42);
const expectedTokenAmount = rate.mul(value);
const tokenAllowance = new BigNumber('1e22');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expectEvent = require('../helpers/expectEvent');
const { assertRevert } = require('../helpers/assertRevert');
const { ether } = require('../helpers/ether');
const { ethGetBalance } = require('../helpers/web3');
const { ZERO_ADDRESS } = require('../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -17,7 +18,6 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
const value = ether(42);
const tokenSupply = new BigNumber('1e22');
const expectedTokenAmount = rate.mul(value);
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

it('requires a non-null token', async function () {
await assertRevert(
Expand Down
4 changes: 1 addition & 3 deletions test/drafts/ERC20Migrator.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { assertRevert } = require('../helpers/assertRevert');

const { ZERO_ADDRESS } = require('../helpers/constants');
const ERC20Mock = artifacts.require('ERC20Mock');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const ERC20Migrator = artifacts.require('ERC20Migrator');
Expand All @@ -11,8 +11,6 @@ require('chai')
.should();

contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

const totalSupply = 200;

it('reverts with a null legacy token address', async function () {
Expand Down
3 changes: 1 addition & 2 deletions test/examples/SimpleToken.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { decodeLogs } = require('../helpers/decodeLogs');
const { ZERO_ADDRESS } = require('../helpers/constants');
const SimpleToken = artifacts.require('SimpleToken');

const BigNumber = web3.BigNumber;
Expand All @@ -8,8 +9,6 @@ require('chai')
.should();

contract('SimpleToken', function ([_, creator]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.token = await SimpleToken.new({ from: creator });
});
Expand Down
6 changes: 6 additions & 0 deletions test/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const BigNumber = web3.BigNumber;

module.exports = {
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
MAX_UINT256: new BigNumber(2).pow(256).minus(1),
};
7 changes: 3 additions & 4 deletions test/math/SafeMath.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { assertRevert } = require('../helpers/assertRevert');
const { MAX_UINT256 } = require('../helpers/constants');

const BigNumber = web3.BigNumber;
const SafeMathMock = artifacts.require('SafeMathMock');
Expand All @@ -8,8 +9,6 @@ require('chai')
.should();

contract('SafeMath', function () {
const MAX_UINT = new BigNumber(2).pow(256).minus(1);

beforeEach(async function () {
this.safeMath = await SafeMathMock.new();
});
Expand All @@ -23,7 +22,7 @@ contract('SafeMath', function () {
});

it('throws a revert error on addition overflow', async function () {
const a = MAX_UINT;
const a = MAX_UINT256;
const b = new BigNumber(1);

await assertRevert(this.safeMath.add(a, b));
Expand Down Expand Up @@ -62,7 +61,7 @@ contract('SafeMath', function () {
});

it('throws a revert error on multiplication overflow', async function () {
const a = MAX_UINT;
const a = MAX_UINT256;
const b = new BigNumber(2);

await assertRevert(this.safeMath.mul(a, b));
Expand Down
3 changes: 1 addition & 2 deletions test/ownership/Ownable.behavior.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const { ZERO_ADDRESS } = require('../helpers/constants');

require('chai')
.should();
Expand Down
4 changes: 1 addition & 3 deletions test/ownership/Secondary.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { assertRevert } = require('../helpers/assertRevert');

const { ZERO_ADDRESS } = require('../helpers/constants');
const SecondaryMock = artifacts.require('SecondaryMock');

require('chai')
.should();

contract('Secondary', function ([_, primary, newPrimary, anyone]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.secondary = await SecondaryMock.new({ from: primary });
});
Expand Down
3 changes: 2 additions & 1 deletion test/payment/ConditionalEscrow.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const { ether } = require('../helpers/ether');

const BigNumber = web3.BigNumber;

Expand All @@ -24,7 +25,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
});

context('when withdrawal is disallowed', function () {
const amount = web3.toWei(23.0, 'ether');
const amount = ether(23.0);

beforeEach(async function () {
await this.escrow.setAllowed(payee, false);
Expand Down
3 changes: 2 additions & 1 deletion test/payment/Escrow.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expectEvent = require('../helpers/expectEvent');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const { ethGetBalance } = require('../helpers/web3');
const { ether } = require('../helpers/ether');

const BigNumber = web3.BigNumber;

Expand All @@ -10,7 +11,7 @@ require('chai')
.should();

function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
const amount = web3.toWei(42.0, 'ether');
const amount = ether(42.0);

describe('as an escrow', function () {
describe('deposits', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/payment/PullPayment.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { ethGetBalance } = require('../helpers/web3');
const { ether } = require('../helpers/ether');

const BigNumber = web3.BigNumber;

Expand All @@ -9,7 +10,7 @@ require('chai')
const PullPaymentMock = artifacts.require('PullPaymentMock');

contract('PullPayment', function ([_, payer, payee1, payee2]) {
const amount = web3.toWei(17.0, 'ether');
const amount = ether(17.0);

beforeEach(async function () {
this.contract = await PullPaymentMock.new({ value: amount });
Expand Down
5 changes: 3 additions & 2 deletions test/payment/RefundEscrow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const expectEvent = require('../helpers/expectEvent');
const { ethGetBalance } = require('../helpers/web3');
const { ether } = require('../helpers/ether');
const { ZERO_ADDRESS } = require('../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -12,9 +14,8 @@ require('chai')
const RefundEscrow = artifacts.require('RefundEscrow');

contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) {
const amount = web3.toWei(54.0, 'ether');
const amount = ether(54.0);
const refundees = [refundee1, refundee2];
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

it('requires a non-null beneficiary', async function () {
await expectThrow(
Expand Down
5 changes: 3 additions & 2 deletions test/payment/SplitPayment.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { ethGetBalance } = require('../helpers/web3');
const { sendEther } = require('./../helpers/sendTransaction');
const { ether } = require('../helpers/ether');
const { ZERO_ADDRESS } = require('./../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -12,8 +14,7 @@ const { EVMRevert } = require('../helpers/EVMRevert.js');
const SplitPayment = artifacts.require('SplitPayment');

contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = web3.toWei(1.0, 'ether');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const amount = ether(1.0);

it('rejects an empty set of payees', async function () {
await expectThrow(SplitPayment.new([], []), EVMRevert);
Expand Down
3 changes: 1 addition & 2 deletions test/token/ERC20/ERC20.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { assertRevert } = require('../../helpers/assertRevert');
const expectEvent = require('../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../helpers/constants');

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

Expand All @@ -10,8 +11,6 @@ require('chai')
.should();

contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.token = await ERC20Mock.new(owner, 100);
});
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC20/TokenVesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { expectThrow } = require('../../helpers/expectThrow');
const { EVMRevert } = require('../../helpers/EVMRevert');
const time = require('../../helpers/time');
const { ethGetBlock } = require('../../helpers/web3');
const { ZERO_ADDRESS } = require('../../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -14,7 +15,6 @@ const TokenVesting = artifacts.require('TokenVesting');

contract('TokenVesting', function ([_, owner, beneficiary]) {
const amount = new BigNumber(1000);
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
// +1 minute so it starts after contract instantiation
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC20/behaviors/ERC20Burnable.behavior.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { assertRevert } = require('../../../helpers/assertRevert');
const expectEvent = require('../../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../../helpers/constants');

const BigNumber = web3.BigNumber;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

require('chai')
.use(require('chai-bignumber')(BigNumber))
Expand Down
3 changes: 1 addition & 2 deletions test/token/ERC20/behaviors/ERC20Mintable.behavior.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { assertRevert } = require('../../../helpers/assertRevert');
const expectEvent = require('../../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -8,8 +9,6 @@ require('chai')
.should();

function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

describe('as a mintable token', function () {
describe('mint', function () {
const amount = 100;
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC721/ERC721.behavior.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const expectEvent = require('../../helpers/expectEvent');
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const { assertRevert } = require('../../helpers/assertRevert');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const { decodeLogs } = require('../../helpers/decodeLogs');
const { sendTransaction } = require('../../helpers/sendTransaction');

Expand All @@ -19,7 +20,6 @@ function shouldBehaveLikeERC721 (
const firstTokenId = 1;
const secondTokenId = 2;
const unknownTokenId = 3;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const RECEIVER_MAGIC_VALUE = '0x150b7a02';

describe('like an ERC721', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC721/ERC721MintBurn.behavior.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { assertRevert } = require('../../helpers/assertRevert');
const expectEvent = require('../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const BigNumber = web3.BigNumber;

require('chai')
Expand All @@ -15,7 +16,6 @@ function shouldBehaveLikeMintAndBurnERC721 (
const secondTokenId = 2;
const thirdTokenId = 3;
const unknownTokenId = 4;
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const MOCK_URI = 'https://example.com';

describe('like a mintable and burnable ERC721', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC721/ERC721PausedToken.behavior.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { assertRevert } = require('../../helpers/assertRevert');
const { sendTransaction } = require('../../helpers/sendTransaction');
const { ZERO_ADDRESS } = require('../../helpers/constants');

const BigNumber = web3.BigNumber;

Expand All @@ -11,7 +12,6 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
const firstTokenId = 1;
const mintedTokens = 1;
const mockData = '0x42';
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

describe('like a paused ERC721', function () {
beforeEach(async function () {
Expand Down