Skip to content

Commit f7b431b

Browse files
committed
All tests now use account names, and dont use accounts[0] (except ERC721)
1 parent 567b773 commit f7b431b

37 files changed

+190
-265
lines changed

test/examples/SampleCrowdsale.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require('chai')
1616
const SampleCrowdsale = artifacts.require('SampleCrowdsale');
1717
const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken');
1818

19-
contract('SampleCrowdsale', function ([owner, wallet, investor]) {
19+
contract('SampleCrowdsale', function ([_, owner, wallet, investor]) {
2020
const RATE = new BigNumber(10);
2121
const GOAL = ether(10);
2222
const CAP = ether(20);
@@ -33,9 +33,10 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
3333

3434
this.token = await SampleCrowdsaleToken.new({ from: owner });
3535
this.crowdsale = await SampleCrowdsale.new(
36-
this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, GOAL
36+
this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, GOAL,
37+
{ from: owner }
3738
);
38-
await this.token.transferOwnership(this.crowdsale.address);
39+
await this.token.transferOwnership(this.crowdsale.address, { from: owner });
3940
});
4041

4142
it('should create crowdsale with correct parameters', async function () {

test/examples/SimpleToken.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const { decodeLogs } = require('../helpers/decodeLogs');
22
const SimpleToken = artifacts.require('SimpleToken');
33

4-
contract('SimpleToken', accounts => {
4+
contract('SimpleToken', function ([_, creator]) {
55
let token;
6-
const creator = accounts[0];
76

87
beforeEach(async function () {
98
token = await SimpleToken.new({ from: creator });

test/introspection/SupportsInterfaceWithLookup.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLook
66
require('chai')
77
.should();
88

9-
contract('SupportsInterfaceWithLookup', function (accounts) {
9+
contract('SupportsInterfaceWithLookup', function () {
1010
beforeEach(async function () {
1111
this.mock = await SupportsInterfaceWithLookup.new();
1212
});

test/library/ECRecovery.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ECRecoveryMock = artifacts.require('ECRecoveryMock');
66
require('chai')
77
.should();
88

9-
contract('ECRecovery', function (accounts) {
9+
contract('ECRecovery', function ([_, anyone]) {
1010
let ecrecovery;
1111
const TEST_MESSAGE = 'OpenZeppelin';
1212

@@ -36,28 +36,28 @@ contract('ECRecovery', function (accounts) {
3636

3737
it('recover using web3.eth.sign()', async function () {
3838
// Create the signature using account[0]
39-
const signature = signMessage(accounts[0], web3.sha3(TEST_MESSAGE));
39+
const signature = signMessage(anyone, web3.sha3(TEST_MESSAGE));
4040

4141
// Recover the signer address from the generated message and signature.
4242
const addrRecovered = await ecrecovery.recover(
4343
hashMessage(TEST_MESSAGE),
4444
signature
4545
);
46-
addrRecovered.should.eq(accounts[0]);
46+
addrRecovered.should.eq(anyone);
4747
});
4848

4949
it('recover using web3.eth.sign() should return wrong signer', async function () {
5050
// Create the signature using account[0]
51-
const signature = signMessage(accounts[0], web3.sha3(TEST_MESSAGE));
51+
const signature = signMessage(anyone, web3.sha3(TEST_MESSAGE));
5252

5353
// Recover the signer address from the generated message and wrong signature.
5454
const addrRecovered = await ecrecovery.recover(hashMessage('Nope'), signature);
55-
assert.notEqual(accounts[0], addrRecovered);
55+
assert.notEqual(anyone, addrRecovered);
5656
});
5757

5858
it('recover should revert when a small hash is sent', async function () {
5959
// Create the signature using account[0]
60-
const signature = signMessage(accounts[0], TEST_MESSAGE);
60+
const signature = signMessage(anyone, TEST_MESSAGE);
6161
try {
6262
await expectThrow(
6363
ecrecovery.recover(hashMessage(TEST_MESSAGE).substring(2), signature)

test/library/Math.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const MathMock = artifacts.require('MathMock');
22

3-
contract('Math', function (accounts) {
3+
contract('Math', function () {
44
let math;
55

66
beforeEach(async function () {

test/library/MerkleProof.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { sha3, bufferToHex } = require('ethereumjs-util');
33

44
const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
55

6-
contract('MerkleProof', function (accounts) {
6+
contract('MerkleProof', function () {
77
let merkleProof;
88

99
beforeEach(async function () {
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
const DestructibleMock = artifacts.require('DestructibleMock');
22
const { ethGetBalance } = require('../helpers/web3');
33

4-
contract('Destructible', function (accounts) {
4+
contract('Destructible', function ([_, owner, recipient]) {
55
beforeEach(async function () {
6-
this.destructible = await DestructibleMock.new({ from: accounts[0] });
6+
this.destructible = await DestructibleMock.new({ from: owner });
77
await web3.eth.sendTransaction({
8-
from: accounts[0],
8+
from: owner,
99
to: this.destructible.address,
1010
value: web3.toWei('10', 'ether'),
1111
});
12-
13-
this.owner = await this.destructible.owner();
1412
});
1513

1614
it('should send balance to owner after destruction', async function () {
17-
const initBalance = await ethGetBalance(this.owner);
18-
await this.destructible.destroy({ from: this.owner });
19-
const newBalance = await ethGetBalance(this.owner);
15+
const initBalance = await ethGetBalance(owner);
16+
await this.destructible.destroy({ from: owner });
17+
const newBalance = await ethGetBalance(owner);
2018
assert.isTrue(newBalance > initBalance);
2119
});
2220

2321
it('should send balance to recepient after destruction', async function () {
24-
const initBalance = await ethGetBalance(accounts[1]);
25-
await this.destructible.destroyAndSend(accounts[1], { from: this.owner });
26-
const newBalance = await ethGetBalance(accounts[1]);
22+
const initBalance = await ethGetBalance(recipient);
23+
await this.destructible.destroyAndSend(recipient, { from: owner });
24+
const newBalance = await ethGetBalance(recipient);
2725
assert.isTrue(newBalance.greaterThan(initBalance));
2826
});
2927
});

test/lifecycle/Pausable.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { assertRevert } = require('../helpers/assertRevert');
22
const PausableMock = artifacts.require('PausableMock');
33

4-
contract('Pausable', function (accounts) {
4+
contract('Pausable', function () {
55
beforeEach(async function () {
66
this.Pausable = await PausableMock.new();
77
});

test/lifecycle/TokenDestructible.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ const { ethGetBalance } = require('../helpers/web3');
33
const TokenDestructible = artifacts.require('TokenDestructible');
44
const StandardTokenMock = artifacts.require('StandardTokenMock');
55

6-
contract('TokenDestructible', function (accounts) {
6+
contract('TokenDestructible', function ([_, owner]) {
77
let tokenDestructible;
8-
let owner;
98

109
beforeEach(async function () {
1110
tokenDestructible = await TokenDestructible.new({
12-
from: accounts[0],
11+
from: owner,
1312
value: web3.toWei('10', 'ether'),
1413
});
15-
16-
owner = await tokenDestructible.owner();
1714
});
1815

1916
it('should send balance to owner after destruction', async function () {

test/ownership/CanReclaimToken.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ const { expectThrow } = require('../helpers/expectThrow');
33
const CanReclaimToken = artifacts.require('CanReclaimToken');
44
const BasicTokenMock = artifacts.require('BasicTokenMock');
55

6-
contract('CanReclaimToken', function (accounts) {
6+
contract('CanReclaimToken', function ([_, owner, anyone]) {
77
let token = null;
88
let canReclaimToken = null;
99

1010
beforeEach(async function () {
1111
// Create contract and token
12-
token = await BasicTokenMock.new(accounts[0], 100);
13-
canReclaimToken = await CanReclaimToken.new();
12+
token = await BasicTokenMock.new(owner, 100, { from: owner });
13+
canReclaimToken = await CanReclaimToken.new({ from: owner });
1414
// Force token into contract
15-
await token.transfer(canReclaimToken.address, 10);
15+
await token.transfer(canReclaimToken.address, 10, { from: owner });
1616
const startBalance = await token.balanceOf(canReclaimToken.address);
1717
assert.equal(startBalance, 10);
1818
});
1919

2020
it('should allow owner to reclaim tokens', async function () {
21-
const ownerStartBalance = await token.balanceOf(accounts[0]);
22-
await canReclaimToken.reclaimToken(token.address);
23-
const ownerFinalBalance = await token.balanceOf(accounts[0]);
21+
const ownerStartBalance = await token.balanceOf(owner);
22+
await canReclaimToken.reclaimToken(token.address, { from: owner });
23+
const ownerFinalBalance = await token.balanceOf(owner);
2424
const finalBalance = await token.balanceOf(canReclaimToken.address);
2525
assert.equal(finalBalance, 0);
2626
assert.equal(ownerFinalBalance - ownerStartBalance, 10);
2727
});
2828

2929
it('should allow only owner to reclaim tokens', async function () {
3030
await expectThrow(
31-
canReclaimToken.reclaimToken(token.address, { from: accounts[1] }),
31+
canReclaimToken.reclaimToken(token.address, { from: anyone })
3232
);
3333
});
3434
});

0 commit comments

Comments
 (0)