Merge pull request #287 from jakub-wojciechowski/test/day-limit

Added new test for a day passed scenario to the DayLimit contract
pull/290/head
Manuel Aráoz 8 years ago committed by GitHub
commit 96b550b722
  1. 27
      test/DayLimit.js

@ -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);
});
}); });

Loading…
Cancel
Save