Skip to content

Commit b3f60b9

Browse files
refactor testing error throwing
1 parent 5e78475 commit b3f60b9

File tree

10 files changed

+78
-77
lines changed

10 files changed

+78
-77
lines changed

test/BasicToken.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ contract('BasicToken', function(accounts) {
2626
let token = await BasicTokenMock.new(accounts[0], 100);
2727
try {
2828
let transfer = await token.transfer(accounts[1], 101);
29+
assert.fail('should have thrown before');
2930
} catch(error) {
30-
return assertJump(error);
31-
}
32-
assert.fail('should have thrown before');
31+
assertJump(error);
32+
}
3333
});
3434

3535
});

test/Claimable.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ contract('Claimable', function(accounts) {
2525

2626
it('should prevent to claimOwnership from no pendingOwner', async function() {
2727
try {
28-
await claimable.claimOwnership({from: accounts[2]});
28+
await claimable.claimOwnership({from: accounts[2]});
29+
assert.fail('should have thrown before');
2930
} catch(error) {
30-
return assertJump(error);
31+
assertJump(error);
3132
}
32-
assert.fail('should have thrown before');
3333
});
3434

3535
it('should prevent non-owners from transfering', async function() {
3636
const other = accounts[2];
3737
const owner = await claimable.owner.call();
3838
assert.isTrue(owner !== other);
3939
try {
40-
await claimable.transferOwnership(other, {from: other});
40+
await claimable.transferOwnership(other, {from: other});
41+
assert.fail('should have thrown before');
4142
} catch(error) {
42-
return assertJump(error);
43+
assertJump(error);
4344
}
44-
assert.fail('should have thrown before');
4545
});
4646

4747
describe('after initiating a transfer', function () {

test/DayLimit.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ contract('DayLimit', function(accounts) {
3535
assert.equal(spentToday, 8);
3636

3737
try {
38-
await dayLimit.attemptSpend(3);
38+
await dayLimit.attemptSpend(3);
39+
assert.fail('should have thrown before');
3940
} catch(error) {
40-
return assertJump(error);
41+
assertJump(error);
4142
}
42-
assert.fail('should have thrown before');
4343
});
4444

4545
it('should allow spending if daily limit is reached and then set higher', async function() {
@@ -49,17 +49,17 @@ contract('DayLimit', function(accounts) {
4949

5050
try {
5151
await dayLimit.attemptSpend(3);
52+
assert.fail('should have thrown before');
5253
} catch(error) {
5354
assertJump(error);
54-
spentToday = await dayLimit.spentToday();
55-
assert.equal(spentToday, 8);
56-
57-
await dayLimit.setDailyLimit(15);
58-
await dayLimit.attemptSpend(3);
59-
spentToday = await dayLimit.spentToday();
60-
return assert.equal(spentToday, 11);
6155
}
62-
assert.fail('should have thrown before');
56+
spentToday = await dayLimit.spentToday();
57+
assert.equal(spentToday, 8);
58+
59+
await dayLimit.setDailyLimit(15);
60+
await dayLimit.attemptSpend(3);
61+
spentToday = await dayLimit.spentToday();
62+
assert.equal(spentToday, 11);
6363
});
6464

6565
it('should allow spending if daily limit is reached and then amount spent is reset', async function() {
@@ -69,17 +69,17 @@ contract('DayLimit', function(accounts) {
6969

7070
try {
7171
await dayLimit.attemptSpend(3);
72+
assert.fail('should have thrown before');
7273
} catch(error) {
7374
assertJump(error);
74-
spentToday = await dayLimit.spentToday();
75-
assert.equal(spentToday, 8);
76-
77-
await dayLimit.resetSpentToday(15);
78-
await dayLimit.attemptSpend(3);
79-
spentToday = await dayLimit.spentToday();
80-
return assert.equal(spentToday, 3);
8175
}
82-
assert.fail('should have thrown before');
76+
spentToday = await dayLimit.spentToday();
77+
assert.equal(spentToday, 8);
78+
79+
await dayLimit.resetSpentToday(15);
80+
await dayLimit.attemptSpend(3);
81+
spentToday = await dayLimit.spentToday();
82+
assert.equal(spentToday, 3);
8383
});
8484

8585
it('should allow spending if daily limit is reached and then the next has come', async function() {
@@ -92,18 +92,18 @@ contract('DayLimit', function(accounts) {
9292

9393
try {
9494
await dayLimit.attemptSpend(3);
95+
assert.fail('should have thrown before');
9596
} catch(error) {
9697
assertJump(error);
97-
spentToday = await dayLimit.spentToday();
98-
assert.equal(spentToday, 8);
98+
}
99+
spentToday = await dayLimit.spentToday();
100+
assert.equal(spentToday, 8);
99101

100-
await timer(day);
102+
await timer(day);
101103

102-
await dayLimit.attemptSpend(3);
103-
spentToday = await dayLimit.spentToday();
104-
return assert.equal(spentToday, 3);
105-
}
106-
assert.fail('should have thrown before');
104+
await dayLimit.attemptSpend(3);
105+
spentToday = await dayLimit.spentToday();
106+
assert.equal(spentToday, 3);
107107
});
108108

109109
});

test/LimitBalance.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ contract('LimitBalance', function(accounts) {
2727
it('shouldnt allow sending above limit', async function() {
2828
let amount = 1110;
2929
try {
30-
await lb.limitedDeposit({value: amount});
30+
await lb.limitedDeposit({value: amount});
31+
assert.fail('should have thrown before');
3132
} catch(error) {
32-
return assertJump(error);
33-
}
34-
assert.fail('should have thrown before');
33+
assertJump(error);
34+
}
3535
});
3636

3737
it('should allow multiple sends below limit', async function() {
@@ -52,10 +52,10 @@ contract('LimitBalance', function(accounts) {
5252

5353
try {
5454
await lb.limitedDeposit({value: amount+1});
55+
assert.fail('should have thrown before');
5556
} catch(error) {
56-
return assertJump(error);
57-
}
58-
assert.fail('should have thrown before');
57+
assertJump(error);
58+
}
5959
});
6060

6161
});

test/Ownable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ contract('Ownable', function(accounts) {
2929
assert.isTrue(owner !== other);
3030
try {
3131
await ownable.transferOwnership(other, {from: other});
32+
assert.fail('should have thrown before');
3233
} catch(error) {
33-
return assertJump(error);
34+
assertJump(error);
3435
}
35-
assert.fail('should have thrown before');
3636
});
3737

3838
it('should guard ownership against stuck state', async function() {

test/Pausable.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ contract('Pausable', function(accounts) {
2323

2424
try {
2525
await Pausable.normalProcess();
26+
assert.fail('should have thrown before');
2627
} catch(error) {
27-
let count1 = await Pausable.count();
28-
assert.equal(count1, 0);
29-
return assertJump(error);
28+
assertJump(error);
3029
}
31-
assert.fail('should have thrown before');
30+
let count1 = await Pausable.count();
31+
assert.equal(count1, 0);
3232
});
3333

3434

3535
it('can not take drastic measure in non-pause', async function() {
3636
let Pausable = await PausableMock.new();
3737
try {
3838
await Pausable.drasticMeasure();
39+
assert.fail('should have thrown before');
3940
} catch(error) {
40-
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
41-
assert.isFalse(drasticMeasureTaken);
42-
return assertJump(error);
41+
assertJump(error);
4342
}
44-
assert.fail('should have thrown before');
43+
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
44+
assert.isFalse(drasticMeasureTaken);
4545
});
4646

4747
it('can take a drastic measure in a pause', async function() {
@@ -69,6 +69,7 @@ contract('Pausable', function(accounts) {
6969
await Pausable.unpause();
7070
try {
7171
await Pausable.drasticMeasure();
72+
assert.fail('should have thrown before');
7273
} catch(error) {
7374
assertJump(error);
7475
}

test/PausableToken.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ contract('PausableToken', function(accounts) {
5555
await token.pause();
5656
try {
5757
await token.transfer(accounts[1], 100);
58+
assert.fail('should have thrown before');
5859
} catch (error) {
59-
return assertJump(error);
60+
assertJump(error);
6061
}
61-
assert.fail('should have thrown before');
6262
});
6363

6464
it('should throw an error trying to transfer from another account while transactions are paused', async function() {
6565
await token.pause();
6666
try {
6767
await token.transferFrom(accounts[0], accounts[1], 100);
68+
assert.fail('should have thrown before');
6869
} catch (error) {
69-
return assertJump(error);
70+
assertJump(error);
7071
}
71-
assert.fail('should have thrown before');
7272
});
7373
})

test/SafeMath.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,32 @@ contract('SafeMath', function(accounts) {
4040
let b = 5678;
4141
try {
4242
let subtract = await safeMath.subtract(a, b);
43+
assert.fail('should have thrown before');
4344
} catch(error) {
44-
return assertJump(error);
45+
assertJump(error);
4546
}
46-
assert.fail('should have thrown before');
4747
});
4848

4949
it("should throw an error on addition overflow", async function() {
5050
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
5151
let b = 1;
5252
try {
5353
let add = await safeMath.add(a, b);
54+
assert.fail('should have thrown before');
5455
} catch(error) {
55-
return assertJump(error);
56+
assertJump(error);
5657
}
57-
assert.fail('should have thrown before');
5858
});
5959

6060
it("should throw an error on multiplication overflow", async function() {
6161
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
6262
let b = 2;
6363
try {
6464
let multiply = await safeMath.multiply(a, b);
65+
assert.fail('should have thrown before');
6566
} catch(error) {
66-
return assertJump(error);
67+
assertJump(error);
6768
}
68-
assert.fail('should have thrown before');
6969
});
7070

7171
});

test/StandardToken.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ contract('StandardToken', function(accounts) {
3939
let token = await StandardTokenMock.new(accounts[0], 100);
4040
try {
4141
await token.transfer(accounts[1], 101);
42+
assert.fail('should have thrown before');
4243
} catch(error) {
43-
return assertJump(error);
44+
assertJump(error);
4445
}
45-
assert.fail('should have thrown before');
4646
});
4747

4848
it('should return correct balances after transfering from another account', async function() {
@@ -64,10 +64,10 @@ contract('StandardToken', function(accounts) {
6464
await token.approve(accounts[1], 99);
6565
try {
6666
await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
67+
assert.fail('should have thrown before');
6768
} catch (error) {
68-
return assertJump(error);
69+
assertJump(error);
6970
}
70-
assert.fail('should have thrown before');
7171
});
7272

7373
});

test/VestedToken.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ contract('VestedToken', function(accounts) {
4646
it('throws when trying to transfer non vested tokens', async () => {
4747
try {
4848
await token.transfer(accounts[7], 1, { from: receiver })
49+
assert.fail('should have thrown before');
4950
} catch(error) {
50-
return assertJump(error);
51+
assertJump(error);
5152
}
52-
assert.fail('should have thrown before');
5353
})
5454

5555
it('throws when trying to transfer from non vested tokens', async () => {
5656
try {
5757
await token.approve(accounts[7], 1, { from: receiver })
5858
await token.transferFrom(receiver, accounts[7], tokenAmount, { from: accounts[7] })
59+
assert.fail('should have thrown before');
5960
} catch(error) {
60-
return assertJump(error);
61+
assertJump(error);
6162
}
62-
assert.fail('should have thrown before');
6363
})
6464

6565
it('can be revoked by granter', async () => {
@@ -71,10 +71,10 @@ contract('VestedToken', function(accounts) {
7171
it('cannot be revoked by non granter', async () => {
7272
try {
7373
await token.revokeTokenGrant(receiver, 0, { from: accounts[3] });
74+
assert.fail('should have thrown before');
7475
} catch(error) {
75-
return assertJump(error);
76+
assertJump(error);
7677
}
77-
assert.fail('should have thrown before');
7878
})
7979

8080
it('can be revoked by granter and non vested tokens are returned', async () => {
@@ -131,10 +131,10 @@ contract('VestedToken', function(accounts) {
131131
it('throws when granter attempts to revoke', async () => {
132132
try {
133133
await token.revokeTokenGrant(receiver, 0, { from: granter });
134+
assert.fail('should have thrown before');
134135
} catch(error) {
135-
return assertJump(error);
136+
assertJump(error);
136137
}
137-
assert.fail('should have thrown before');
138138
})
139139
})
140140

@@ -160,10 +160,10 @@ contract('VestedToken', function(accounts) {
160160
it('cannot be revoked by non granter', async () => {
161161
try {
162162
await token.revokeTokenGrant(receiver, 0, { from: accounts[3] });
163+
assert.fail('should have thrown before');
163164
} catch(error) {
164-
return assertJump(error);
165+
assertJump(error);
165166
}
166-
assert.fail('should have thrown before');
167167
})
168168

169169
it('can be revoked by granter and non vested tokens are returned', async () => {

0 commit comments

Comments
 (0)