Skip to content

Commit 4544df4

Browse files
authored
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.
1 parent f497215 commit 4544df4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+211
-301
lines changed

test/Heritable.test.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
66

77
const Heritable = artifacts.require('Heritable');
88

9-
contract('Heritable', function (accounts) {
9+
contract('Heritable', function ([_, owner, heir, anyone]) {
1010
let heritable;
11-
let owner;
1211

1312
beforeEach(async function () {
14-
heritable = await Heritable.new(4141);
15-
owner = await heritable.owner();
13+
heritable = await Heritable.new(4141, { from: owner });
1614
});
1715

1816
it('should start off with an owner, but without heir', async function () {
@@ -31,31 +29,23 @@ contract('Heritable', function (accounts) {
3129
});
3230

3331
it('only owner should set heir', async function () {
34-
const newHeir = accounts[1];
35-
const someRandomAddress = accounts[2];
36-
assert.isTrue(owner !== someRandomAddress);
37-
38-
await heritable.setHeir(newHeir, { from: owner });
39-
await expectThrow(heritable.setHeir(newHeir, { from: someRandomAddress }));
32+
await heritable.setHeir(heir, { from: owner });
33+
await expectThrow(heritable.setHeir(heir, { from: anyone }));
4034
});
4135

4236
it('owner can\'t be heir', async function () {
4337
await assertRevert(heritable.setHeir(owner, { from: owner }));
4438
});
4539

4640
it('owner can remove heir', async function () {
47-
const newHeir = accounts[1];
48-
await heritable.setHeir(newHeir, { from: owner });
49-
let heir = await heritable.heir();
50-
51-
assert.notStrictEqual(heir, NULL_ADDRESS);
52-
await heritable.removeHeir();
53-
heir = await heritable.heir();
54-
assert.isTrue(heir === NULL_ADDRESS);
41+
await heritable.setHeir(heir, { from: owner });
42+
assert.equal(await heritable.heir(), heir);
43+
44+
await heritable.removeHeir({ from: owner });
45+
assert.equal(await heritable.heir(), NULL_ADDRESS);
5546
});
5647

5748
it('heir can claim ownership only if owner is dead and timeout was reached', async function () {
58-
const heir = accounts[1];
5949
await heritable.setHeir(heir, { from: owner });
6050
await expectThrow(heritable.claimHeirOwnership({ from: heir }));
6151

@@ -69,20 +59,17 @@ contract('Heritable', function (accounts) {
6959
});
7060

7161
it('only heir can proclaim death', async function () {
72-
const someRandomAddress = accounts[2];
7362
await assertRevert(heritable.proclaimDeath({ from: owner }));
74-
await assertRevert(heritable.proclaimDeath({ from: someRandomAddress }));
63+
await assertRevert(heritable.proclaimDeath({ from: anyone }));
7564
});
7665

7766
it('heir can\'t proclaim death if owner is death', async function () {
78-
const heir = accounts[1];
7967
await heritable.setHeir(heir, { from: owner });
8068
await heritable.proclaimDeath({ from: heir });
8169
await assertRevert(heritable.proclaimDeath({ from: heir }));
8270
});
8371

8472
it('heir can\'t claim ownership if owner heartbeats', async function () {
85-
const heir = accounts[1];
8673
await heritable.setHeir(heir, { from: owner });
8774

8875
await heritable.proclaimDeath({ from: heir });
@@ -96,8 +83,6 @@ contract('Heritable', function (accounts) {
9683
});
9784

9885
it('should log events appropriately', async function () {
99-
const heir = accounts[1];
100-
10186
const setHeirLogs = (await heritable.setHeir(heir, { from: owner })).logs;
10287
const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged');
10388

test/LimitBalance.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { ethGetBalance } = require('./helpers/web3');
33

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

6-
contract('LimitBalance', function (accounts) {
6+
contract('LimitBalance', function () {
77
let limitBalance;
88

99
beforeEach(async function () {

test/ReentrancyGuard.test.js

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

5-
contract('ReentrancyGuard', function (accounts) {
5+
contract('ReentrancyGuard', function () {
66
let reentrancyMock;
77

88
beforeEach(async function () {

test/SimpleSavingsWallet.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');
33

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

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

109
const paymentAmount = 4242;
1110

1211
beforeEach(async function () {
13-
savingsWallet = await SimpleSavingsWallet.new(4141);
14-
owner = await savingsWallet.owner();
12+
savingsWallet = await SimpleSavingsWallet.new(4141, { from: owner });
1513
});
1614

1715
it('should receive funds', async function () {
@@ -22,14 +20,15 @@ contract('SimpleSavingsWallet', function (accounts) {
2220

2321
it('owner can send funds', async function () {
2422
// Receive payment so we have some money to spend.
25-
await ethSendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
23+
await ethSendTransaction({ from: anyone, to: savingsWallet.address, value: 1000000 });
24+
2625
await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner }));
2726
await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner }));
28-
await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner }));
27+
await expectThrow(savingsWallet.sendTo(anyone, 0, { from: owner }));
2928

30-
const balance = await ethGetBalance(accounts[1]);
31-
await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner });
32-
const updatedBalance = await ethGetBalance(accounts[1]);
29+
const balance = await ethGetBalance(anyone);
30+
await savingsWallet.sendTo(anyone, paymentAmount, { from: owner });
31+
const updatedBalance = await ethGetBalance(anyone);
3332
assert.isTrue(balance.plus(paymentAmount).equals(updatedBalance));
3433
});
3534
});

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 () {

0 commit comments

Comments
 (0)