Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor testing error throwing
  • Loading branch information
jakub-wojciechowski committed Jul 22, 2017
commit b3f60b932024fff9ec672a5cb295039172f73e3f
6 changes: 3 additions & 3 deletions test/BasicToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ contract('BasicToken', function(accounts) {
let token = await BasicTokenMock.new(accounts[0], 100);
try {
let transfer = await token.transfer(accounts[1], 101);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
}
assert.fail('should have thrown before');
assertJump(error);
}
});

});
12 changes: 6 additions & 6 deletions test/Claimable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ contract('Claimable', function(accounts) {

it('should prevent to claimOwnership from no pendingOwner', async function() {
try {
await claimable.claimOwnership({from: accounts[2]});
await claimable.claimOwnership({from: accounts[2]});
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it('should prevent non-owners from transfering', async function() {
const other = accounts[2];
const owner = await claimable.owner.call();
assert.isTrue(owner !== other);
try {
await claimable.transferOwnership(other, {from: other});
await claimable.transferOwnership(other, {from: other});
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

describe('after initiating a transfer', function () {
Expand Down
54 changes: 27 additions & 27 deletions test/DayLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ contract('DayLimit', function(accounts) {
assert.equal(spentToday, 8);

try {
await dayLimit.attemptSpend(3);
await dayLimit.attemptSpend(3);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

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

try {
await dayLimit.attemptSpend(3);
assert.fail('should have thrown before');
} catch(error) {
assertJump(error);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);

await dayLimit.setDailyLimit(15);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
return assert.equal(spentToday, 11);
}
assert.fail('should have thrown before');
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);

await dayLimit.setDailyLimit(15);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 11);
});

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

try {
await dayLimit.attemptSpend(3);
assert.fail('should have thrown before');
} catch(error) {
assertJump(error);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);

await dayLimit.resetSpentToday(15);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
return assert.equal(spentToday, 3);
}
assert.fail('should have thrown before');
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);

await dayLimit.resetSpentToday(15);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 3);
});

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

try {
await dayLimit.attemptSpend(3);
assert.fail('should have thrown before');
} catch(error) {
assertJump(error);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);
}
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);

await timer(day);
await timer(day);

await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
return assert.equal(spentToday, 3);
}
assert.fail('should have thrown before');
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 3);
});

});
14 changes: 7 additions & 7 deletions test/LimitBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ contract('LimitBalance', function(accounts) {
it('shouldnt allow sending above limit', async function() {
let amount = 1110;
try {
await lb.limitedDeposit({value: amount});
await lb.limitedDeposit({value: amount});
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
}
assert.fail('should have thrown before');
assertJump(error);
}
});

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

try {
await lb.limitedDeposit({value: amount+1});
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
}
assert.fail('should have thrown before');
assertJump(error);
}
});

});
4 changes: 2 additions & 2 deletions test/Ownable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ contract('Ownable', function(accounts) {
assert.isTrue(owner !== other);
try {
await ownable.transferOwnership(other, {from: other});
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it('should guard ownership against stuck state', async function() {
Expand Down
17 changes: 9 additions & 8 deletions test/Pausable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ contract('Pausable', function(accounts) {

try {
await Pausable.normalProcess();
assert.fail('should have thrown before');
} catch(error) {
let count1 = await Pausable.count();
assert.equal(count1, 0);
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
let count1 = await Pausable.count();
assert.equal(count1, 0);
});


it('can not take drastic measure in non-pause', async function() {
let Pausable = await PausableMock.new();
try {
await Pausable.drasticMeasure();
assert.fail('should have thrown before');
} catch(error) {
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken);
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken);
});

it('can take a drastic measure in a pause', async function() {
Expand Down Expand Up @@ -69,6 +69,7 @@ contract('Pausable', function(accounts) {
await Pausable.unpause();
try {
await Pausable.drasticMeasure();
assert.fail('should have thrown before');
} catch(error) {
assertJump(error);
}
Expand Down
8 changes: 4 additions & 4 deletions test/PausableToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ contract('PausableToken', function(accounts) {
await token.pause();
try {
await token.transfer(accounts[1], 100);
assert.fail('should have thrown before');
} catch (error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it('should throw an error trying to transfer from another account while transactions are paused', async function() {
await token.pause();
try {
await token.transferFrom(accounts[0], accounts[1], 100);
assert.fail('should have thrown before');
} catch (error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});
})
12 changes: 6 additions & 6 deletions test/SafeMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,32 @@ contract('SafeMath', function(accounts) {
let b = 5678;
try {
let subtract = await safeMath.subtract(a, b);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it("should throw an error on addition overflow", async function() {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
let b = 1;
try {
let add = await safeMath.add(a, b);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it("should throw an error on multiplication overflow", async function() {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
let b = 2;
try {
let multiply = await safeMath.multiply(a, b);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

});
8 changes: 4 additions & 4 deletions test/StandardToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ contract('StandardToken', function(accounts) {
let token = await StandardTokenMock.new(accounts[0], 100);
try {
await token.transfer(accounts[1], 101);
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

it('should return correct balances after transfering from another account', async function() {
Expand All @@ -64,10 +64,10 @@ contract('StandardToken', function(accounts) {
await token.approve(accounts[1], 99);
try {
await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
assert.fail('should have thrown before');
} catch (error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
});

});
20 changes: 10 additions & 10 deletions test/VestedToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ contract('VestedToken', function(accounts) {
it('throws when trying to transfer non vested tokens', async () => {
try {
await token.transfer(accounts[7], 1, { from: receiver })
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
})

it('throws when trying to transfer from non vested tokens', async () => {
try {
await token.approve(accounts[7], 1, { from: receiver })
await token.transferFrom(receiver, accounts[7], tokenAmount, { from: accounts[7] })
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
})

it('can be revoked by granter', async () => {
Expand All @@ -71,10 +71,10 @@ contract('VestedToken', function(accounts) {
it('cannot be revoked by non granter', async () => {
try {
await token.revokeTokenGrant(receiver, 0, { from: accounts[3] });
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
})

it('can be revoked by granter and non vested tokens are returned', async () => {
Expand Down Expand Up @@ -131,10 +131,10 @@ contract('VestedToken', function(accounts) {
it('throws when granter attempts to revoke', async () => {
try {
await token.revokeTokenGrant(receiver, 0, { from: granter });
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
})
})

Expand All @@ -160,10 +160,10 @@ contract('VestedToken', function(accounts) {
it('cannot be revoked by non granter', async () => {
try {
await token.revokeTokenGrant(receiver, 0, { from: accounts[3] });
assert.fail('should have thrown before');
} catch(error) {
return assertJump(error);
assertJump(error);
}
assert.fail('should have thrown before');
})

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