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

Commit bec8aea

Browse files
committed
test: update tests and lints
1 parent 2d34da7 commit bec8aea

File tree

6 files changed

+27
-38
lines changed

6 files changed

+27
-38
lines changed

src/contracts/abstractions/Arbitrator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22

33
import * as arbitratorConstants from '../../constants/arbitrator'
44
import AbstractContract from '../AbstractContract'
5-
import EventListener from '../../utils/EventListener'
65

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

5051
if (!disputeCreationLog)
5152
throw new Error('Could not fetch dispute creation event log')

src/contracts/implementations/arbitrator/KlerosPOC.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,6 @@ class KlerosPOC extends ContractImplementation {
580580
* @returns {number[]} an array of timestamps
581581
*/
582582
getAppealRuledAtTimestamps = async (blockNumber, appeal = 0) => {
583-
584-
585583
const eventLogs = await this._getNewPeriodEventLogs(
586584
blockNumber,
587585
arbitratorConstants.PERIOD.APPEAL,
@@ -645,10 +643,8 @@ class KlerosPOC extends ContractImplementation {
645643
numberOfAppeals + 1
646644
)
647645

648-
const creationTimestamp = await this._getTimestampForBlock(
649-
blockNumber
650-
)
651-
const eventLogTimestamps = [(creationTimestamp * 1000)]
646+
const creationTimestamp = await this._getTimestampForBlock(blockNumber)
647+
const eventLogTimestamps = [creationTimestamp * 1000]
652648

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

679675
for (let i = 0; i < eventLogs.length; i++) {
@@ -697,7 +693,7 @@ class KlerosPOC extends ContractImplementation {
697693
'TokenShift',
698694
0,
699695
'latest',
700-
{ "_account": account }
696+
{ _account: account }
701697
)
702698

703699
let netPNK = 0

src/resources/Disputes.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Disputes {
191191
* @param {number} appeal - The appeal number. 0 if there have been no appeals.
192192
* @returns {number} timestamp of the appeal
193193
*/
194-
getDisputeDeadline = async (disputeId, account, appeal=0) => {
194+
getDisputeDeadline = async (disputeId, account, appeal = 0) => {
195195
const cachedDispute = this.disputeCache[disputeId]
196196
if (
197197
cachedDispute &&
@@ -211,7 +211,9 @@ class Disputes {
211211

212212
// cache the deadline for the appeal
213213
if (deadlineTimestamps.length > 0)
214-
this._updateDisputeCache(disputeId, { appealDeadlines: deadlineTimestamps })
214+
this._updateDisputeCache(disputeId, {
215+
appealDeadlines: deadlineTimestamps
216+
})
215217

216218
return deadlineTimestamps[appeal]
217219
}
@@ -223,7 +225,7 @@ class Disputes {
223225
* @param {number} appeal - The appeal number. 0 if there have been no appeals.
224226
* @returns {number} timestamp of the appeal
225227
*/
226-
getAppealRuledAt = async (disputeId, account, appeal=0) => {
228+
getAppealRuledAt = async (disputeId, account, appeal = 0) => {
227229
const cachedDispute = this.disputeCache[disputeId]
228230
if (
229231
cachedDispute &&
@@ -243,7 +245,9 @@ class Disputes {
243245

244246
// cache the deadline for the appeal
245247
if (appealRuledAtTimestamps.length > 0) {
246-
this._updateDisputeCache(disputeId, { appealRuledAt: appealRuledAtTimestamps })
248+
this._updateDisputeCache(disputeId, {
249+
appealRuledAt: appealRuledAtTimestamps
250+
})
247251
}
248252

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

277281
// cache the deadline for the appeal
278282
if (appealCreatedAtTimestamps) {
279-
this._updateDisputeCache(
280-
disputeId,
281-
{ appealCreatedAt: appealCreatedAtTimestamps }
282-
)
283+
this._updateDisputeCache(disputeId, {
284+
appealCreatedAt: appealCreatedAtTimestamps
285+
})
283286
}
284287

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

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

359362
// Extra info for the last appeal
360363
if (isLastAppeal) {
361-
console.log(draws)
362364
if (draws.length > 0)
363365
rulingPromises.push(
364366
this._ArbitratorInstance.canRuleDispute(disputeId, draws, account)

src/utils/StoreProviderWrapper.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ class StoreProviderWrapper {
101101
*/
102102
getContractByAddress = async (userAddress, addressContract) => {
103103
const userProfile = await this.getUserProfile(userAddress)
104-
if (!userProfile)
105-
return {}
104+
if (!userProfile) return {}
106105

107106
let contract = _.filter(
108107
userProfile.contracts,
@@ -304,8 +303,6 @@ class StoreProviderWrapper {
304303
params.disputeId = disputeId
305304
params.arbitratorAddress = arbitratorAddress
306305

307-
console.log(params)
308-
309306
return JSON.stringify({ ...currentDisputeProfile, ...params })
310307
}
311308

tests/unit/contracts/abstractions/Arbitrator.test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ describe('Arbitrator', () => {
8383
const mockGetDisputesForUser = jest.fn()
8484
const mockSetUpUserProfile = jest.fn()
8585
const mockGetDisputesForJuror = jest.fn()
86-
const mockUpdateUserProfile = jest.fn()
8786
const mockUpdateDisputeProfile = jest.fn()
8887
const mockDispute = {
8988
arbitratorAddress: arbitratorAddress,
@@ -99,7 +98,6 @@ describe('Arbitrator', () => {
9998
session: 1
10099
})
101100
),
102-
updateUserProfile: mockUpdateUserProfile,
103101
updateDisputeProfile: mockUpdateDisputeProfile
104102
}
105103

@@ -111,12 +109,11 @@ describe('Arbitrator', () => {
111109
getDispute: jest.fn().mockReturnValue(_asyncMockResponse(mockDispute)),
112110
getDisputesForJuror: mockGetDisputesForJuror.mockReturnValue(
113111
_asyncMockResponse([mockDispute])
114-
)
112+
),
113+
getDisputeCreationEvent: jest.fn().mockReturnValue({ blockNumber: 1 })
115114
}
116115
arbitratorInstance._contractImplementation = mockArbitrator
117116

118-
arbitratorInstance.updateUserProfile = mockUpdateUserProfile
119-
120117
const disputes = await arbitratorInstance.getDisputesForUser(account)
121118

122119
expect(disputes.length).toBe(1)
@@ -136,13 +133,8 @@ describe('Arbitrator', () => {
136133
mockDispute.disputeId
137134
)
138135
expect(mockUpdateDisputeProfile.mock.calls[0][3]).toEqual({
139-
appealDraws: mockDispute.appealDraws
140-
})
141-
142-
expect(mockUpdateUserProfile.mock.calls.length).toBe(1)
143-
expect(mockUpdateUserProfile.mock.calls[0][0]).toBe(account)
144-
expect(mockUpdateUserProfile.mock.calls[0][1]).toEqual({
145-
session: 2
136+
appealDraws: mockDispute.appealDraws,
137+
blockNumber: 1
146138
})
147139
})
148140
})

tests/unit/resources/Disputes.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('Disputes', () => {
138138
const partyA = '0x0'
139139
const partyB = '0x1'
140140
const appealDeadlines = [1]
141-
const appealRuledAt = [2]
141+
const appealRuledAt = []
142142
const appealCreatedAt = [3]
143143

144144
const mockArbitratorGetDispute = jest.fn().mockReturnValue(
@@ -231,6 +231,7 @@ describe('Disputes', () => {
231231
const appealData = disputeData.appealRulings[0]
232232
expect(appealData.voteCounter).toEqual(voteCounters[numberOfAppeals])
233233
expect(appealData.ruledAt).toBeFalsy()
234+
expect(appealData.deadline).toEqual(appealDeadlines[numberOfAppeals])
234235
expect(appealData.ruling).toEqual(2)
235236
expect(appealData.canRepartition).toBeFalsy()
236237
expect(appealData.canExecute).toBeFalsy()

0 commit comments

Comments
 (0)