All tests now use account names, and dont use accounts[0] (except ERC… (#1137)

* All tests now use account names, and dont use accounts[0] (except ERC721)

* Added account names to some missing contracts.
This commit is contained in:
Nicolás Venturo
2018-08-02 16:55:31 -03:00
committed by GitHub
parent f49721576f
commit 4544df47da
41 changed files with 210 additions and 300 deletions

View File

@ -8,19 +8,17 @@ require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
function shouldBehaveLikeBurnableToken ([owner], initialBalance) {
function shouldBehaveLikeBurnableToken (owner, initialBalance) {
describe('as a basic burnable token', function () {
const from = owner;
describe('when the given amount is not greater than balance of the sender', function () {
const amount = 100;
beforeEach(async function () {
({ logs: this.logs } = await this.token.burn(amount, { from }));
({ logs: this.logs } = await this.token.burn(amount, { from: owner }));
});
it('burns the requested amount', async function () {
const balance = await this.token.balanceOf(from);
const balance = await this.token.balanceOf(owner);
balance.should.be.bignumber.equal(initialBalance - amount);
});
@ -42,7 +40,7 @@ function shouldBehaveLikeBurnableToken ([owner], initialBalance) {
const amount = initialBalance + 1;
it('reverts', async function () {
await assertRevert(this.token.burn(amount, { from }));
await assertRevert(this.token.burn(amount, { from: owner }));
});
});
});

View File

@ -1,12 +1,12 @@
const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour');
const BurnableTokenMock = artifacts.require('BurnableTokenMock');
contract('BurnableToken', function ([owner]) {
contract('BurnableToken', function ([_, owner]) {
const initialBalance = 1000;
beforeEach(async function () {
this.token = await BurnableTokenMock.new(owner, initialBalance);
this.token = await BurnableTokenMock.new(owner, initialBalance, { from: owner });
});
shouldBehaveLikeBurnableToken([owner], initialBalance);
shouldBehaveLikeBurnableToken(owner, initialBalance);
});

View File

@ -1,6 +1,6 @@
const { expectThrow } = require('../../helpers/expectThrow');
function shouldBehaveLikeCappedToken ([owner, anotherAccount, minter, cap]) {
function shouldBehaveLikeCappedToken (minter, [anyone], cap) {
describe('capped token', function () {
const from = minter;
@ -11,18 +11,18 @@ function shouldBehaveLikeCappedToken ([owner, anotherAccount, minter, cap]) {
});
it('should mint when amount is less than cap', async function () {
const result = await this.token.mint(owner, cap.sub(1), { from });
const result = await this.token.mint(anyone, cap.sub(1), { from });
assert.equal(result.logs[0].event, 'Mint');
});
it('should fail to mint if the ammount exceeds the cap', async function () {
await this.token.mint(owner, cap.sub(1), { from });
await expectThrow(this.token.mint(owner, 100, { from }));
await this.token.mint(anyone, cap.sub(1), { from });
await expectThrow(this.token.mint(anyone, 100, { from }));
});
it('should fail to mint after cap is reached', async function () {
await this.token.mint(owner, cap, { from });
await expectThrow(this.token.mint(owner, 1, { from }));
await this.token.mint(anyone, cap, { from });
await expectThrow(this.token.mint(anyone, 1, { from }));
});
});
}

View File

@ -4,14 +4,13 @@ const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour');
const CappedToken = artifacts.require('CappedToken');
contract('Capped', function ([owner, anotherAccount]) {
const _cap = ether(1000);
contract('Capped', function ([_, owner, ...otherAccounts]) {
const cap = ether(1000);
beforeEach(async function () {
this.token = await CappedToken.new(_cap, { from: owner });
this.token = await CappedToken.new(cap, { from: owner });
});
shouldBehaveLikeCappedToken([owner, anotherAccount, owner, _cap]);
shouldBehaveLikeMintableToken([owner, anotherAccount, owner]);
shouldBehaveLikeCappedToken(owner, otherAccounts, cap);
shouldBehaveLikeMintableToken(owner, owner, otherAccounts);
});

View File

@ -6,7 +6,7 @@ require('chai')
const DetailedERC20Mock = artifacts.require('DetailedERC20Mock');
contract('DetailedERC20', accounts => {
contract('DetailedERC20', function () {
let detailedERC20 = null;
const _name = 'My Detailed ERC20';

View File

@ -6,7 +6,7 @@ require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) {
function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
describe('as a basic mintable token', function () {
describe('after token creation', function () {
it('sender should be token owner', async function () {
@ -67,7 +67,7 @@ function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) {
});
describe('when the sender is not the token owner', function () {
const from = anotherAccount;
const from = anyone;
describe('when the token minting was not finished', function () {
it('reverts', async function () {
@ -124,7 +124,7 @@ function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) {
});
describe('when the sender has not the minting permission', function () {
const from = anotherAccount;
const from = anyone;
describe('when the token minting is not finished', function () {
it('reverts', async function () {

View File

@ -1,12 +1,10 @@
const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour');
const MintableToken = artifacts.require('MintableToken');
contract('MintableToken', function ([owner, anotherAccount]) {
const minter = owner;
contract('MintableToken', function ([_, owner, ...otherAccounts]) {
beforeEach(async function () {
this.token = await MintableToken.new({ from: owner });
});
shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
shouldBehaveLikeMintableToken(owner, owner, otherAccounts);
});

View File

@ -5,15 +5,15 @@ const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour');
const RBACCappedTokenMock = artifacts.require('RBACCappedTokenMock');
contract('RBACCappedToken', function ([owner, anotherAccount, minter]) {
const _cap = ether(1000);
contract('RBACCappedToken', function ([_, owner, minter, ...otherAccounts]) {
const cap = ether(1000);
beforeEach(async function () {
this.token = await RBACCappedTokenMock.new(_cap, { from: owner });
this.token = await RBACCappedTokenMock.new(cap, { from: owner });
await this.token.addMinter(minter, { from: owner });
});
shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
shouldBehaveLikeRBACMintableToken([owner, anotherAccount]);
shouldBehaveLikeCappedToken([owner, anotherAccount, minter, _cap]);
shouldBehaveLikeMintableToken(owner, minter, otherAccounts);
shouldBehaveLikeRBACMintableToken(owner, otherAccounts);
shouldBehaveLikeCappedToken(minter, otherAccounts, cap);
});

View File

@ -2,26 +2,26 @@ const { expectThrow } = require('../../helpers/expectThrow');
const ROLE_MINTER = 'minter';
function shouldBehaveLikeRBACMintableToken ([owner, anotherAccount]) {
function shouldBehaveLikeRBACMintableToken (owner, [anyone]) {
describe('handle roles', function () {
it('owner can add and remove a minter role', async function () {
await this.token.addMinter(anotherAccount, { from: owner });
let hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
await this.token.addMinter(anyone, { from: owner });
let hasRole = await this.token.hasRole(anyone, ROLE_MINTER);
assert.equal(hasRole, true);
await this.token.removeMinter(anotherAccount, { from: owner });
hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
await this.token.removeMinter(anyone, { from: owner });
hasRole = await this.token.hasRole(anyone, ROLE_MINTER);
assert.equal(hasRole, false);
});
it('another account can\'t add or remove a minter role', async function () {
it('anyone can\'t add or remove a minter role', async function () {
await expectThrow(
this.token.addMinter(anotherAccount, { from: anotherAccount })
this.token.addMinter(anyone, { from: anyone })
);
await this.token.addMinter(anotherAccount, { from: owner });
await this.token.addMinter(anyone, { from: owner });
await expectThrow(
this.token.removeMinter(anotherAccount, { from: anotherAccount })
this.token.removeMinter(anyone, { from: anyone })
);
});
});

View File

@ -3,12 +3,12 @@ const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour');
const RBACMintableToken = artifacts.require('RBACMintableToken');
contract('RBACMintableToken', function ([owner, anotherAccount, minter]) {
contract('RBACMintableToken', function ([_, owner, minter, ...otherAccounts]) {
beforeEach(async function () {
this.token = await RBACMintableToken.new({ from: owner });
await this.token.addMinter(minter, { from: owner });
});
shouldBehaveLikeRBACMintableToken([owner, anotherAccount, minter]);
shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
shouldBehaveLikeRBACMintableToken(owner, otherAccounts);
shouldBehaveLikeMintableToken(owner, minter, otherAccounts);
});

View File

@ -10,14 +10,14 @@ require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('StandardBurnableToken', function ([owner, burner]) {
contract('StandardBurnableToken', function ([_, owner, burner]) {
const initialBalance = 1000;
beforeEach(async function () {
this.token = await StandardBurnableTokenMock.new(owner, initialBalance);
});
shouldBehaveLikeBurnableToken([owner], initialBalance);
shouldBehaveLikeBurnableToken(owner, initialBalance);
describe('burnFrom', function () {
describe('on success', function () {