Update how constants is used.

This commit is contained in:
Nicolás Venturo
2019-01-11 16:30:52 -03:00
parent 53767a0963
commit 8c5d65de2f
19 changed files with 69 additions and 51 deletions

View File

@ -8,7 +8,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});
it('reverts when querying roles for the null account', async function () {
await shouldFail.reverting(this.roles.has(constants.ZERO_ADDRESS));
await shouldFail.reverting(this.roles.has(ZERO_ADDRESS));
});
context('initially', function () {
@ -31,7 +31,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});
it('reverts when adding roles to the null account', async function () {
await shouldFail.reverting(this.roles.add(constants.ZERO_ADDRESS));
await shouldFail.reverting(this.roles.add(ZERO_ADDRESS));
});
});
});
@ -54,7 +54,7 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
});
it('reverts when removing roles from the null account', async function () {
await shouldFail.reverting(this.roles.remove(constants.ZERO_ADDRESS));
await shouldFail.reverting(this.roles.remove(ZERO_ADDRESS));
});
});
});

View File

@ -1,4 +1,5 @@
const { shouldFail, constants, expectEvent } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function capitalize (str) {
return str.replace(/\b\w/g, l => l.toUpperCase());
@ -23,7 +24,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
}
it('reverts when querying roles for the null account', async function () {
await shouldFail.reverting(this.contract[`is${rolename}`](constants.ZERO_ADDRESS));
await shouldFail.reverting(this.contract[`is${rolename}`](ZERO_ADDRESS));
});
describe('access control', function () {
@ -63,7 +64,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
});
it('reverts when adding role to the null account', async function () {
await shouldFail.reverting(this.contract[`add${rolename}`](constants.ZERO_ADDRESS, { from }));
await shouldFail.reverting(this.contract[`add${rolename}`](ZERO_ADDRESS, { from }));
});
});
});
@ -89,7 +90,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
});
it('reverts when removing role from the null account', async function () {
await shouldFail.reverting(this.contract[`remove${rolename}`](constants.ZERO_ADDRESS), { from });
await shouldFail.reverting(this.contract[`remove${rolename}`](ZERO_ADDRESS), { from });
});
});
});

View File

@ -1,4 +1,5 @@
const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const AllowanceCrowdsaleImpl = artifacts.require('AllowanceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
@ -74,7 +75,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('when token wallet is different from token address', function () {
it('creation reverts', async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
await shouldFail.reverting(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, constants.ZERO_ADDRESS));
await shouldFail.reverting(AllowanceCrowdsaleImpl.new(rate, wallet, this.token.address, ZERO_ADDRESS));
});
});
});

View File

@ -1,4 +1,5 @@
const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const Crowdsale = artifacts.require('CrowdsaleMock');
const SimpleToken = artifacts.require('SimpleToken');
@ -11,7 +12,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it('requires a non-null token', async function () {
await shouldFail.reverting(
Crowdsale.new(rate, wallet, constants.ZERO_ADDRESS)
Crowdsale.new(rate, wallet, ZERO_ADDRESS)
);
});
@ -28,7 +29,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it('requires a non-null wallet', async function () {
await shouldFail.reverting(
Crowdsale.new(rate, constants.ZERO_ADDRESS, this.token.address)
Crowdsale.new(rate, ZERO_ADDRESS, this.token.address)
);
});
@ -64,7 +65,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it('requires a non-null beneficiary', async function () {
await shouldFail.reverting(
this.crowdsale.buyTokens(constants.ZERO_ADDRESS, { value: value, from: purchaser })
this.crowdsale.buyTokens(ZERO_ADDRESS, { value: value, from: purchaser })
);
});
});

View File

@ -1,4 +1,5 @@
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mock = artifacts.require('ERC20Mock');
const ERC20Mintable = artifacts.require('ERC20Mintable');
@ -8,7 +9,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
const totalSupply = new BN('200');
it('reverts with a null legacy token address', async function () {
await shouldFail.reverting(ERC20Migrator.new(constants.ZERO_ADDRESS));
await shouldFail.reverting(ERC20Migrator.new(ZERO_ADDRESS));
});
describe('with tokens and migrator', function () {
@ -24,7 +25,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
describe('beginMigration', function () {
it('reverts with a null new token address', async function () {
await shouldFail.reverting(this.migrator.beginMigration(constants.ZERO_ADDRESS));
await shouldFail.reverting(this.migrator.beginMigration(ZERO_ADDRESS));
});
it('reverts if not a minter of the token', async function () {

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenVesting = artifacts.require('TokenVesting');
@ -26,7 +27,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
it('reverts with a null beneficiary', async function () {
await shouldFail.reverting(
TokenVesting.new(constants.ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner })
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner })
);
});

View File

@ -1,4 +1,5 @@
const { constants, expectEvent } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const SimpleToken = artifacts.require('SimpleToken');
@ -26,7 +27,7 @@ contract('SimpleToken', function ([_, creator]) {
creatorBalance.should.be.bignumber.equal(totalSupply);
await expectEvent.inConstruction(this.token, 'Transfer', {
from: constants.ZERO_ADDRESS,
from: ZERO_ADDRESS,
to: creator,
value: totalSupply,
});

View File

@ -1,4 +1,5 @@
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const SafeMathMock = artifacts.require('SafeMathMock');

View File

@ -1,4 +1,5 @@
const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeOwnable (owner, [anyone]) {
describe('as an ownable', function () {
@ -20,14 +21,14 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
});
it('should guard ownership against stuck state', async function () {
await shouldFail.reverting(this.ownable.transferOwnership(constants.ZERO_ADDRESS, { from: owner }));
await shouldFail.reverting(this.ownable.transferOwnership(ZERO_ADDRESS, { from: owner }));
});
it('loses owner after renouncement', async function () {
const { logs } = await this.ownable.renounceOwnership({ from: owner });
expectEvent.inLogs(logs, 'OwnershipTransferred');
(await this.ownable.owner()).should.equal(constants.ZERO_ADDRESS);
(await this.ownable.owner()).should.equal(ZERO_ADDRESS);
});
it('should prevent non-owners from renouncement', async function () {

View File

@ -1,4 +1,5 @@
const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const SecondaryMock = artifacts.require('SecondaryMock');
@ -29,7 +30,7 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) {
});
it('reverts when transfering to the null address', async function () {
await shouldFail.reverting(this.secondary.transferPrimary(constants.ZERO_ADDRESS, { from: primary }));
await shouldFail.reverting(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary }));
});
it('reverts when called by anyone', async function () {

View File

@ -1,4 +1,5 @@
const { balance, constants, ether, expectEvent, send, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const PaymentSplitter = artifacts.require('PaymentSplitter');
@ -18,7 +19,7 @@ contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpaye
});
it('rejects null payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, constants.ZERO_ADDRESS], [20, 30]));
await shouldFail.reverting(PaymentSplitter.new([payee1, ZERO_ADDRESS], [20, 30]));
});
it('rejects zero-valued shares', async function () {

View File

@ -1,4 +1,5 @@
const { balance, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const RefundEscrow = artifacts.require('RefundEscrow');
@ -8,7 +9,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
it('requires a non-null beneficiary', async function () {
await shouldFail.reverting(
RefundEscrow.new(constants.ZERO_ADDRESS, { from: primary })
RefundEscrow.new(ZERO_ADDRESS, { from: primary })
);
});

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mock = artifacts.require('ERC20Mock');
@ -64,7 +65,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
});
describe('when the recipient is the zero address', function () {
const to = constants.ZERO_ADDRESS;
const to = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.transfer(to, initialSupply, { from: initialHolder }));
@ -147,7 +148,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
describe('when the spender is the zero address', function () {
const amount = initialSupply;
const spender = constants.ZERO_ADDRESS;
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.approve(spender, amount, { from: initialHolder }));
@ -238,7 +239,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
describe('when the recipient is the zero address', function () {
const amount = initialSupply;
const to = constants.ZERO_ADDRESS;
const to = ZERO_ADDRESS;
beforeEach(async function () {
await this.token.approve(spender, amount, { from: initialHolder });
@ -312,7 +313,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
describe('when the spender is the zero address', function () {
const amount = initialSupply;
const spender = constants.ZERO_ADDRESS;
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
@ -394,7 +395,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
});
describe('when the spender is the zero address', function () {
const spender = constants.ZERO_ADDRESS;
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: initialHolder }));
@ -406,7 +407,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
const amount = new BN(50);
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.mint(constants.ZERO_ADDRESS, amount));
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, amount));
});
describe('for a non null account', function () {
@ -426,7 +427,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
it('emits Transfer event', async function () {
const event = expectEvent.inLogs(this.logs, 'Transfer', {
from: constants.ZERO_ADDRESS,
from: ZERO_ADDRESS,
to: recipient,
});
@ -437,7 +438,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
describe('_burn', function () {
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.burn(constants.ZERO_ADDRESS, new BN(1)));
await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, new BN(1)));
});
describe('for a non null account', function () {
@ -465,7 +466,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
it('emits Transfer event', async function () {
const event = expectEvent.inLogs(this.logs, 'Transfer', {
from: initialHolder,
to: constants.ZERO_ADDRESS,
to: ZERO_ADDRESS,
});
event.args.value.should.be.bignumber.equal(amount);
@ -488,7 +489,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
});
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.burnFrom(constants.ZERO_ADDRESS, new BN(1)));
await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, new BN(1)));
});
describe('for a non null account', function () {
@ -525,7 +526,7 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
it('emits a Transfer event', async function () {
const event = expectEvent.inLogs(this.logs, 'Transfer', {
from: initialHolder,
to: constants.ZERO_ADDRESS,
to: ZERO_ADDRESS,
});
event.args.value.should.be.bignumber.equal(amount);

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
describe('burn', function () {
@ -23,7 +24,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: constants.ZERO_ADDRESS,
to: ZERO_ADDRESS,
value: amount,
});
});
@ -69,7 +70,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: constants.ZERO_ADDRESS,
to: ZERO_ADDRESS,
value: amount,
});
});

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
describe('as a mintable token', function () {
@ -27,7 +28,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
it('emits a mint and a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
from: constants.ZERO_ADDRESS,
from: ZERO_ADDRESS,
to: anyone,
value: amount,
});

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
@ -35,7 +36,7 @@ function shouldBehaveLikeERC721 (
context('when querying the zero address', function () {
it('throws', async function () {
await shouldFail.reverting(this.token.balanceOf(constants.ZERO_ADDRESS));
await shouldFail.reverting(this.token.balanceOf(ZERO_ADDRESS));
});
});
});
@ -75,7 +76,7 @@ function shouldBehaveLikeERC721 (
});
it('clears the approval for the token ID', async function () {
(await this.token.getApproved(tokenId)).should.be.equal(constants.ZERO_ADDRESS);
(await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS);
});
if (approved) {
@ -133,7 +134,7 @@ function shouldBehaveLikeERC721 (
context('when called by the owner without an approved user', function () {
beforeEach(async function () {
await this.token.approve(constants.ZERO_ADDRESS, tokenId, { from: owner });
await this.token.approve(ZERO_ADDRESS, tokenId, { from: owner });
({ logs } = await transferFunction.call(this, owner, this.toWhom, tokenId, { from: operator }));
});
transferWasSuccessful({ owner, tokenId, approved: null });
@ -149,7 +150,7 @@ function shouldBehaveLikeERC721 (
});
it('clears the approval for the token ID', async function () {
(await this.token.getApproved(tokenId)).should.be.equal(constants.ZERO_ADDRESS);
(await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS);
});
it('emits only a transfer event', async function () {
@ -199,7 +200,7 @@ function shouldBehaveLikeERC721 (
context('when the address to transfer the token to is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(
transferFunction.call(this, owner, constants.ZERO_ADDRESS, tokenId, { from: owner })
transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner })
);
});
});
@ -315,7 +316,7 @@ function shouldBehaveLikeERC721 (
const itClearsApproval = function () {
it('clears approval for the token', async function () {
(await this.token.getApproved(tokenId)).should.be.equal(constants.ZERO_ADDRESS);
(await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS);
});
};
@ -338,21 +339,21 @@ function shouldBehaveLikeERC721 (
context('when clearing approval', function () {
context('when there was no prior approval', function () {
beforeEach(async function () {
({ logs } = await this.token.approve(constants.ZERO_ADDRESS, tokenId, { from: owner }));
({ logs } = await this.token.approve(ZERO_ADDRESS, tokenId, { from: owner }));
});
itClearsApproval();
itEmitsApprovalEvent(constants.ZERO_ADDRESS);
itEmitsApprovalEvent(ZERO_ADDRESS);
});
context('when there was a prior approval', function () {
beforeEach(async function () {
await this.token.approve(approved, tokenId, { from: owner });
({ logs } = await this.token.approve(constants.ZERO_ADDRESS, tokenId, { from: owner }));
({ logs } = await this.token.approve(ZERO_ADDRESS, tokenId, { from: owner }));
});
itClearsApproval();
itEmitsApprovalEvent(constants.ZERO_ADDRESS);
itEmitsApprovalEvent(ZERO_ADDRESS);
});
});

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const ERC721Mock = artifacts.require('ERC721Mock.sol');
@ -15,7 +16,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
describe('_mint(address, uint256)', function () {
it('reverts with a null destination address', async function () {
await shouldFail.reverting(this.token.mint(constants.ZERO_ADDRESS, tokenId));
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, tokenId));
});
context('with minted token', async function () {
@ -24,7 +25,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('emits a Transfer event', function () {
expectEvent.inLogs(this.logs, 'Transfer', { from: constants.ZERO_ADDRESS, to: tokenOwner, tokenId });
expectEvent.inLogs(this.logs, 'Transfer', { from: ZERO_ADDRESS, to: tokenOwner, tokenId });
});
it('creates the token', async function () {
@ -58,7 +59,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('emits a Transfer event', function () {
expectEvent.inLogs(this.logs, 'Transfer', { from: tokenOwner, to: constants.ZERO_ADDRESS, tokenId });
expectEvent.inLogs(this.logs, 'Transfer', { from: tokenOwner, to: ZERO_ADDRESS, tokenId });
});
it('deletes the token', async function () {
@ -89,7 +90,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('emits a Transfer event', function () {
expectEvent.inLogs(this.logs, 'Transfer', { from: tokenOwner, to: constants.ZERO_ADDRESS, tokenId });
expectEvent.inLogs(this.logs, 'Transfer', { from: tokenOwner, to: ZERO_ADDRESS, tokenId });
});
it('deletes the token', async function () {

View File

@ -1,4 +1,5 @@
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeMintAndBurnERC721 (
creator,
@ -36,7 +37,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
it('emits a transfer and minted event', async function () {
expectEvent.inLogs(logs, 'Transfer', {
from: constants.ZERO_ADDRESS,
from: ZERO_ADDRESS,
to: newOwner,
tokenId: thirdTokenId,
});
@ -45,7 +46,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
describe('when the given owner address is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.mint(constants.ZERO_ADDRESS, thirdTokenId, { from: minter }));
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, thirdTokenId, { from: minter }));
});
});
@ -82,7 +83,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
it('emits a burn event', async function () {
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: constants.ZERO_ADDRESS,
to: ZERO_ADDRESS,
tokenId: tokenId,
});
});

View File

@ -1,4 +1,5 @@
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
const firstTokenId = new BN(1);
@ -35,7 +36,7 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
describe('getApproved', function () {
it('returns approved address', async function () {
const approvedAccount = await this.token.getApproved(firstTokenId);
approvedAccount.should.be.equal(constants.ZERO_ADDRESS);
approvedAccount.should.be.equal(ZERO_ADDRESS);
});
});