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

Commit

Permalink
test(disputes): unit tests for getEvidenceForArbitrableContract and g…
Browse files Browse the repository at this point in the history
…etUserDisputeFromStore
  • Loading branch information
satello committed Mar 23, 2018
1 parent 5b87aa0 commit 242eeaf
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 22 deletions.
21 changes: 0 additions & 21 deletions src/abstractWrappers/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,27 +463,6 @@ class Disputes extends AbstractWrapper {
return partyAEvidence.concat(partyBEvidence)
}

/**
* Get ruling options for dispute.
* @param {string} arbitratorAddress - Address of arbitrator contract.
* @param {string} disputeId - Dispute ID.
* @returns {object[]} - Array of ruling objects.
*/
getRulingOptions = async (arbitratorAddress, disputeId) => {
this._checkArbitrableWrappersSet()
this._checkArbitratorWrappersSet()

const arbitrableContractAddress = (await this._Arbitrator.getDispute(
arbitratorAddress,
disputeId
)).arbitrableContractAddress
return this._ArbitrableContract.getRulingOptions(
arbitrableContractAddress,
arbitratorAddress,
disputeId
)
}

/**
* Get data for a dispute.
* @param {string} arbitratorAddress - The arbitrator contract's address.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/disputeResolution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ describe('Dispute Resolution', () => {
)

// check fetch resolution options
const resolutionOptions = await KlerosInstance.disputes.getRulingOptions(
const resolutionOptions = await KlerosInstance.arbitrableTransaction.getRulingOptions(
arbitrableContractAddress,
klerosPOCAddress,
0
)
Expand Down
139 changes: 139 additions & 0 deletions tests/unit/abstractWrappers/Disputes.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expectThrow } from 'kleros-interaction/helpers/utils'

import DisputesApi from '../../../src/abstractWrappers/Disputes'

describe('Disputes', () => {
Expand Down Expand Up @@ -349,4 +351,141 @@ describe('Disputes', () => {
})
})
})

describe('getUserDisputeFromStore', async () => {
it('fetches dispute', async () => {
const mockGetUserProfile = jest.fn()
const mockDispute = {
arbitratorAddress,
disputeId: 0
}
const mockStoreProvider = {
getUserProfile: mockGetUserProfile.mockReturnValue(
_asyncMockResponse({
disputes: [mockDispute]
})
)
}

disputesInstance.setStoreProvider(mockStoreProvider)

const dispute = await disputesInstance.getUserDisputeFromStore(
mockDispute.arbitratorAddress,
mockDispute.disputeId,
account
)

expect(dispute).toBeTruthy()
expect(dispute).toEqual(mockDispute)
})
it('cannot fetch dispute', async () => {
const mockGetUserProfile = jest.fn()
const mockDispute = {
arbitratorAddress,
disputeId: 0
}
const mockStoreProvider = {
getUserProfile: mockGetUserProfile.mockReturnValue(
_asyncMockResponse({
disputes: [mockDispute]
})
)
}

disputesInstance.setStoreProvider(mockStoreProvider)

expectThrow(
disputesInstance.getUserDisputeFromStore(
mockDispute.arbitratorAddress,
mockDispute.disputeId + 1,
account
)
)
})
})

describe('getEvidenceForArbitrableContract', async () => {
it('combines evidence from both parties', async () => {
const partyA = '0x0'
const partyB = '0x1'
const arbitrableContractAddress = '0xfakeaddress'
const mockData = {
partyA,
partyB
}
const mockGetData = jest.fn()
disputesInstance._ArbitrableContract.getData = mockGetData.mockReturnValue(
_asyncMockResponse(mockData)
)

const mockGetContractByAddress = jest.fn()
// return partyA then partyB contract
mockGetContractByAddress.mockReturnValueOnce({
evidences: [
{
name: 'testPartyA'
}
]
})
mockGetContractByAddress.mockReturnValueOnce({
evidences: [
{
name: 'testPartyB'
}
]
})

const mockStore = {
getContractByAddress: mockGetContractByAddress
}

disputesInstance.setStoreProvider(mockStore)

const evidence = await disputesInstance.getEvidenceForArbitrableContract(
arbitrableContractAddress
)

expect(evidence).toBeTruthy()
expect(evidence.length).toBe(2)
expect(evidence[0].submitter).toEqual(partyA)
})
it('still fetches evidence when one party has none', async () => {
const partyA = '0x0'
const partyB = '0x1'
const arbitrableContractAddress = '0xfakeaddress'
const mockData = {
partyA,
partyB
}
const mockGetData = jest.fn()
disputesInstance._ArbitrableContract.getData = mockGetData.mockReturnValue(
_asyncMockResponse(mockData)
)

const mockGetContractByAddress = jest.fn()
// return partyA then partyB contract
mockGetContractByAddress.mockReturnValueOnce({
evidences: [
{
name: 'testPartyA'
}
]
})
mockGetContractByAddress.mockReturnValueOnce(null)

const mockStore = {
getContractByAddress: mockGetContractByAddress
}

disputesInstance.setStoreProvider(mockStore)

const evidence = await disputesInstance.getEvidenceForArbitrableContract(
arbitrableContractAddress
)

expect(evidence).toBeTruthy()
expect(evidence.length).toBe(1)
expect(evidence[0].submitter).toEqual(partyA)
})
})
})

0 comments on commit 242eeaf

Please sign in to comment.