Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
test: update tests and lints
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Jun 7, 2018
1 parent 2d34da7 commit bec8aea
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
5 changes: 3 additions & 2 deletions src/contracts/abstractions/Arbitrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'lodash'

import * as arbitratorConstants from '../../constants/arbitrator'
import AbstractContract from '../AbstractContract'
import EventListener from '../../utils/EventListener'

/**
* Arbitrator Abstract Contarct API. This wraps an arbitrator contract. It provides
Expand Down Expand Up @@ -45,7 +44,9 @@ class Arbitrator extends AbstractContract {
// update user profile for each dispute
await Promise.all(
myDisputes.map(async dispute => {
const disputeCreationLog = await this._contractImplementation.getDisputeCreationEvent(dispute.disputeId)
const disputeCreationLog = await this._contractImplementation.getDisputeCreationEvent(
dispute.disputeId
)

if (!disputeCreationLog)
throw new Error('Could not fetch dispute creation event log')
Expand Down
12 changes: 4 additions & 8 deletions src/contracts/implementations/arbitrator/KlerosPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,6 @@ class KlerosPOC extends ContractImplementation {
* @returns {number[]} an array of timestamps
*/
getAppealRuledAtTimestamps = async (blockNumber, appeal = 0) => {


const eventLogs = await this._getNewPeriodEventLogs(
blockNumber,
arbitratorConstants.PERIOD.APPEAL,
Expand Down Expand Up @@ -645,10 +643,8 @@ class KlerosPOC extends ContractImplementation {
numberOfAppeals + 1
)

const creationTimestamp = await this._getTimestampForBlock(
blockNumber
)
const eventLogTimestamps = [(creationTimestamp * 1000)]
const creationTimestamp = await this._getTimestampForBlock(blockNumber)
const eventLogTimestamps = [creationTimestamp * 1000]

// skip first execute phase as this is the original ruling
for (let i = 1; i < eventLogs.length; i++) {
Expand All @@ -673,7 +669,7 @@ class KlerosPOC extends ContractImplementation {
'DisputeCreation',
0,
'latest',
{ "_disputeId": disputeId}
{ _disputeId: disputeId }
)

for (let i = 0; i < eventLogs.length; i++) {
Expand All @@ -697,7 +693,7 @@ class KlerosPOC extends ContractImplementation {
'TokenShift',
0,
'latest',
{ "_account": account }
{ _account: account }
)

let netPNK = 0
Expand Down
24 changes: 13 additions & 11 deletions src/resources/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Disputes {
* @param {number} appeal - The appeal number. 0 if there have been no appeals.
* @returns {number} timestamp of the appeal
*/
getDisputeDeadline = async (disputeId, account, appeal=0) => {
getDisputeDeadline = async (disputeId, account, appeal = 0) => {
const cachedDispute = this.disputeCache[disputeId]
if (
cachedDispute &&
Expand All @@ -211,7 +211,9 @@ class Disputes {

// cache the deadline for the appeal
if (deadlineTimestamps.length > 0)
this._updateDisputeCache(disputeId, { appealDeadlines: deadlineTimestamps })
this._updateDisputeCache(disputeId, {
appealDeadlines: deadlineTimestamps
})

return deadlineTimestamps[appeal]
}
Expand All @@ -223,7 +225,7 @@ class Disputes {
* @param {number} appeal - The appeal number. 0 if there have been no appeals.
* @returns {number} timestamp of the appeal
*/
getAppealRuledAt = async (disputeId, account, appeal=0) => {
getAppealRuledAt = async (disputeId, account, appeal = 0) => {
const cachedDispute = this.disputeCache[disputeId]
if (
cachedDispute &&
Expand All @@ -243,7 +245,9 @@ class Disputes {

// cache the deadline for the appeal
if (appealRuledAtTimestamps.length > 0) {
this._updateDisputeCache(disputeId, { appealRuledAt: appealRuledAtTimestamps })
this._updateDisputeCache(disputeId, {
appealRuledAt: appealRuledAtTimestamps
})
}

return appealRuledAtTimestamps[appeal]
Expand All @@ -256,7 +260,7 @@ class Disputes {
* @param {number} appeal - The appeal number. 0 if there have been no appeals.
* @returns {number} timestamp of the appeal
*/
getAppealCreatedAt = async (disputeId, account, appeal=0) => {
getAppealCreatedAt = async (disputeId, account, appeal = 0) => {
const cachedDispute = this.disputeCache[disputeId]
if (
cachedDispute &&
Expand All @@ -276,10 +280,9 @@ class Disputes {

// cache the deadline for the appeal
if (appealCreatedAtTimestamps) {
this._updateDisputeCache(
disputeId,
{ appealCreatedAt: appealCreatedAtTimestamps }
)
this._updateDisputeCache(disputeId, {
appealCreatedAt: appealCreatedAtTimestamps
})
}

return appealCreatedAtTimestamps[appeal]
Expand Down Expand Up @@ -331,7 +334,7 @@ class Disputes {
// eslint-disable-next-line no-unused-vars
} catch (err) {
// Dispute exists on chain but not in store. We have lost draws for past disputes.
console.error("Dispute does not exist in store.")
console.error('Dispute does not exist in store.')
}

const netPNK = await this._ArbitratorInstance.getNetTokensForDispute(
Expand All @@ -358,7 +361,6 @@ class Disputes {

// Extra info for the last appeal
if (isLastAppeal) {
console.log(draws)
if (draws.length > 0)
rulingPromises.push(
this._ArbitratorInstance.canRuleDispute(disputeId, draws, account)
Expand Down
5 changes: 1 addition & 4 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ class StoreProviderWrapper {
*/
getContractByAddress = async (userAddress, addressContract) => {
const userProfile = await this.getUserProfile(userAddress)
if (!userProfile)
return {}
if (!userProfile) return {}

let contract = _.filter(
userProfile.contracts,
Expand Down Expand Up @@ -304,8 +303,6 @@ class StoreProviderWrapper {
params.disputeId = disputeId
params.arbitratorAddress = arbitratorAddress

console.log(params)

return JSON.stringify({ ...currentDisputeProfile, ...params })
}

Expand Down
16 changes: 4 additions & 12 deletions tests/unit/contracts/abstractions/Arbitrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('Arbitrator', () => {
const mockGetDisputesForUser = jest.fn()
const mockSetUpUserProfile = jest.fn()
const mockGetDisputesForJuror = jest.fn()
const mockUpdateUserProfile = jest.fn()
const mockUpdateDisputeProfile = jest.fn()
const mockDispute = {
arbitratorAddress: arbitratorAddress,
Expand All @@ -99,7 +98,6 @@ describe('Arbitrator', () => {
session: 1
})
),
updateUserProfile: mockUpdateUserProfile,
updateDisputeProfile: mockUpdateDisputeProfile
}

Expand All @@ -111,12 +109,11 @@ describe('Arbitrator', () => {
getDispute: jest.fn().mockReturnValue(_asyncMockResponse(mockDispute)),
getDisputesForJuror: mockGetDisputesForJuror.mockReturnValue(
_asyncMockResponse([mockDispute])
)
),
getDisputeCreationEvent: jest.fn().mockReturnValue({ blockNumber: 1 })
}
arbitratorInstance._contractImplementation = mockArbitrator

arbitratorInstance.updateUserProfile = mockUpdateUserProfile

const disputes = await arbitratorInstance.getDisputesForUser(account)

expect(disputes.length).toBe(1)
Expand All @@ -136,13 +133,8 @@ describe('Arbitrator', () => {
mockDispute.disputeId
)
expect(mockUpdateDisputeProfile.mock.calls[0][3]).toEqual({
appealDraws: mockDispute.appealDraws
})

expect(mockUpdateUserProfile.mock.calls.length).toBe(1)
expect(mockUpdateUserProfile.mock.calls[0][0]).toBe(account)
expect(mockUpdateUserProfile.mock.calls[0][1]).toEqual({
session: 2
appealDraws: mockDispute.appealDraws,
blockNumber: 1
})
})
})
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/resources/Disputes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Disputes', () => {
const partyA = '0x0'
const partyB = '0x1'
const appealDeadlines = [1]
const appealRuledAt = [2]
const appealRuledAt = []
const appealCreatedAt = [3]

const mockArbitratorGetDispute = jest.fn().mockReturnValue(
Expand Down Expand Up @@ -231,6 +231,7 @@ describe('Disputes', () => {
const appealData = disputeData.appealRulings[0]
expect(appealData.voteCounter).toEqual(voteCounters[numberOfAppeals])
expect(appealData.ruledAt).toBeFalsy()
expect(appealData.deadline).toEqual(appealDeadlines[numberOfAppeals])
expect(appealData.ruling).toEqual(2)
expect(appealData.canRepartition).toBeFalsy()
expect(appealData.canExecute).toBeFalsy()
Expand Down

0 comments on commit bec8aea

Please sign in to comment.