refactor testing error throwing

This commit is contained in:
Jakub Wojciechowski
2017-07-22 21:40:01 +01:00
parent 5e7847537a
commit b3f60b9320
10 changed files with 79 additions and 78 deletions

View File

@ -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() {
@ -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() {
@ -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() {
@ -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);
await timer(day);
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 timer(day);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 3);
});
});