added new test for a day passed scenario to the DayLimit contract

This commit is contained in:
Jakub Wojciechowski
2017-07-02 21:06:58 +01:00
parent 262b7dd7dd
commit d2dd6e40b6

View File

@ -1,9 +1,11 @@
'use strict'; 'use strict';
const assertJump = require('./helpers/assertJump'); const assertJump = require('./helpers/assertJump');
const timer = require('./helpers/timer');
var DayLimitMock = artifacts.require('helpers/DayLimitMock.sol'); var DayLimitMock = artifacts.require('./helpers/DayLimitMock.sol');
contract('DayLimit', function(accounts) { contract('DayLimit', function(accounts) {
const day = 60 * 60 * 24;
it('should construct with the passed daily limit', async function() { it('should construct with the passed daily limit', async function() {
let initLimit = 10; let initLimit = 10;
@ -84,4 +86,27 @@ contract('DayLimit', function(accounts) {
assert.equal(spentToday, 3); assert.equal(spentToday, 3);
}); });
it('should allow spending if daily limit is reached and then the next has come', async function() {
let limit = 10;
let dayLimit = await DayLimitMock.new(limit);
await dayLimit.attemptSpend(8);
let spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);
try {
await dayLimit.attemptSpend(3);
} catch(error) {
assertJump(error);
}
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 8);
await timer(day);
await dayLimit.attemptSpend(3);
spentToday = await dayLimit.spentToday();
assert.equal(spentToday, 3);
});
}); });