Skip to content

Commit

Permalink
Payroll: Use TimeHelpersMock to simulate past
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Apr 12, 2019
1 parent ac42479 commit 1a9cdf7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ contract('Payroll gas costs', ([owner, employee, anotherEmployee]) => {

beforeEach('initialize payroll app', async () => {
await payroll.initialize(finance.address, denominationToken.address, priceFeed.address, RATE_EXPIRATION_TIME, { from: owner })
await payroll.mockSetTimestamp(NOW)

const startDate = NOW - ONE_MONTH
const salary = annualSalaryPerSecond(100000, TOKEN_DECIMALS)
Expand Down
16 changes: 8 additions & 8 deletions future-apps/payroll/test/contracts/Payroll_payday.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -199,7 +199,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -249,7 +249,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

itReverts(expiredRatesReason)
Expand Down Expand Up @@ -496,7 +496,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -548,7 +548,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -638,7 +638,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -735,7 +735,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

itReverts(requestedAmount, expiredRatesReason)
Expand Down Expand Up @@ -963,7 +963,7 @@ contract('Payroll payday', ([owner, employee, anotherEmployee, anyone]) => {

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ contract('Payroll reimbursements', ([owner, employee, anotherEmployee, anyone])

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -265,7 +265,7 @@ contract('Payroll reimbursements', ([owner, employee, anotherEmployee, anyone])

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -418,7 +418,7 @@ contract('Payroll reimbursements', ([owner, employee, anotherEmployee, anyone])

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -470,7 +470,7 @@ contract('Payroll reimbursements', ([owner, employee, anotherEmployee, anyone])

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down Expand Up @@ -560,7 +560,7 @@ contract('Payroll reimbursements', ([owner, employee, anotherEmployee, anyone])

context('when exchange rates are expired', () => {
beforeEach('expire exchange rates', async () => {
await priceFeed.mockSetTimestamp(NOW - TWO_MONTHS)
await priceFeed.mockDecreaseTime(TWO_MONTHS)
})

it('reverts', async () => {
Expand Down
8 changes: 8 additions & 0 deletions shared/test-helpers/contracts/TimeHelpersMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ contract TimeHelpersMock is TimeHelpers {
else mockedTimestamp = block.timestamp.add(_seconds);
}

/**
* @dev Decreases the mocked timestamp value, used only for testing purposes
*/
function mockDecreaseTime(uint256 _seconds) public {
if (mockedTimestamp != 0) mockedTimestamp = mockedTimestamp.sub(_seconds);
else mockedTimestamp = block.timestamp.sub(_seconds);
}

/**
* @dev Advances the mocked block number value, used only for testing purposes
*/
Expand Down

0 comments on commit 1a9cdf7

Please sign in to comment.