added a test helper with common constants (#1400)
* signing prefix added * Minor improvement * Tests changed * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commita6889776f4. * updates * fixes #1206 (cherry picked from commit58a42443df)
This commit is contained in:
@ -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();
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const { assertRevert } = require('../../helpers/assertRevert');
|
||||
const { ZERO_ADDRESS } = require('../../helpers/constants');
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
|
||||
require('chai')
|
||||
@ -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 () {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
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;
|
||||
|
||||
@ -16,7 +17,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 });
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
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;
|
||||
|
||||
@ -16,7 +17,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(
|
||||
|
||||
@ -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');
|
||||
@ -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 () {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const { decodeLogs } = require('../helpers/decodeLogs');
|
||||
const { ZERO_ADDRESS } = require('../helpers/constants');
|
||||
const SimpleToken = artifacts.require('SimpleToken');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
@ -10,8 +11,6 @@ require('chai')
|
||||
contract('SimpleToken', function ([_, creator]) {
|
||||
let token;
|
||||
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
beforeEach(async function () {
|
||||
token = await SimpleToken.new({ from: creator });
|
||||
});
|
||||
|
||||
6
test/helpers/constants.js
Normal file
6
test/helpers/constants.js
Normal file
@ -0,0 +1,6 @@
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
module.exports = {
|
||||
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
|
||||
MAX_UINT256: new BigNumber(2).pow(256).minus(1),
|
||||
};
|
||||
@ -1,4 +1,5 @@
|
||||
const { assertRevert } = require('../helpers/assertRevert');
|
||||
const { MAX_UINT256 } = require('../helpers/constants');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
const SafeMathMock = artifacts.require('SafeMathMock');
|
||||
@ -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();
|
||||
});
|
||||
@ -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));
|
||||
@ -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));
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
const { expectThrow } = require('../helpers/expectThrow');
|
||||
const { EVMRevert } = require('../helpers/EVMRevert');
|
||||
const expectEvent = require('../helpers/expectEvent');
|
||||
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
const { ZERO_ADDRESS } = require('../helpers/constants');
|
||||
|
||||
require('chai')
|
||||
.should();
|
||||
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const { ethGetBalance } = require('../helpers/web3');
|
||||
const { ether } = require('../helpers/ether');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -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 });
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
|
||||
const { ether } = require('../helpers/ether');
|
||||
const { ZERO_ADDRESS } = require('./../helpers/constants');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -11,8 +13,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);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
const { assertRevert } = require('../../helpers/assertRevert');
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
const { ZERO_ADDRESS } = require('../../helpers/constants');
|
||||
|
||||
const ERC20 = artifacts.require('ERC20Mock');
|
||||
|
||||
@ -10,8 +11,6 @@ require('chai')
|
||||
.should();
|
||||
|
||||
contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
beforeEach(async function () {
|
||||
this.token = await ERC20.new(owner, 100);
|
||||
});
|
||||
|
||||
@ -3,6 +3,7 @@ const { EVMRevert } = require('../../helpers/EVMRevert');
|
||||
const { latestTime } = require('../../helpers/latestTime');
|
||||
const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
|
||||
const { ethGetBlock } = require('../../helpers/web3');
|
||||
const { ZERO_ADDRESS } = require('../../helpers/constants');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -15,7 +16,6 @@ const TokenVesting = artifacts.require('TokenVesting');
|
||||
|
||||
contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
const amount = new BigNumber(1000);
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
beforeEach(async function () {
|
||||
this.start = (await latestTime()) + duration.minutes(1); // +1 minute so it starts after contract instantiation
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
const { assertRevert } = require('../../../helpers/assertRevert');
|
||||
const expectEvent = require('../../../helpers/expectEvent');
|
||||
const { ZERO_ADDRESS } = require('../../../helpers/constants');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
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');
|
||||
const _ = require('lodash');
|
||||
@ -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 () {
|
||||
|
||||
@ -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')
|
||||
@ -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 () {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
const { assertRevert } = require('../../helpers/assertRevert');
|
||||
const { sendTransaction } = require('../../helpers/sendTransaction');
|
||||
const { ZERO_ADDRESS } = require('../../helpers/constants');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user