Skip to content
Permalink
Browse files

fix(getDeadlineForDispute): fix wrong computation and return date object

  • Loading branch information...
epiqueras authored and satello committed Feb 13, 2018
1 parent 1d65cc2 commit 7ee05f5ae30599f4231c7a0780e8b6cb2915acf4
Showing with 9 additions and 13 deletions.
  1. +8 −13 src/abstractWrappers/Disputes.js
  2. +1 −0 src/test/kleros.test.js
@@ -319,25 +319,20 @@ class Disputes extends AbstractWrapper {
}

/**
* get the deadline for dispute
* @param {string} arbitratorAddress address of arbitrator contract
* @param {number} period default to voting period
* @return {string} date string in the form dd/mm/yyyy
* Gets the deadline for an arbitrator's period, which is also the deadline for all its disputes.
* @param {string} arbitratorAddress - The address of the arbitrator contract.
* @param {number} [period=PERIODS.VOTE] - The period to get the deadline for.
* @return {Date} - A date object.
*/
getDeadlineForDispute = async (
arbitratorAddress,
period = PERIODS.VOTE
) => {
// Get arbitrator data
const arbitratorData = await this._Arbitrator.getData(arbitratorAddress)
// compute end date
const startTime = arbitratorData.lastPeriodChange
const length = await this._Arbitrator.getTimeForPeriod(arbitratorAddress, period)
// FIXME this is all UTC for now. Timezones are a pain
const deadline = new Date(0);
deadline.setUTCSeconds(startTime)
deadline.setSeconds(deadline.getSeconds() + length);

return `${deadline.getUTCDate()}/${deadline.getUTCMonth()}/${deadline.getFullYear()}`

// Last period change + current period duration = deadline
return new Date(1000 * (arbitratorData.lastPeriodChange + (await this._Arbitrator.getTimeForPeriod(arbitratorAddress, period))))
}

/**
@@ -498,6 +498,7 @@ describe('Kleros', () => {

const disputesForJuror = await KlerosInstance.disputes.getDisputesForUser(klerosCourt.address, juror)
expect(disputesForJuror.length).toEqual(1)
expect(disputesForJuror[0].deadline.getTime()).toBe(1000 * (newState.lastPeriodChange + (await klerosPOCInstance.timePerPeriod(newState.period)).toNumber()))
expect(disputesForJuror[0].arbitrableContractAddress).toEqual(contractArbitrableTransactionData.address)
expect(disputesForJuror[0].votes).toEqual([1,2,3])

0 comments on commit 7ee05f5

Please sign in to comment.
You can’t perform that action at this time.