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

Commit

Permalink
refactor: rename Arbitrator.js -> StatefulContractWrapper.js + PR rev…
Browse files Browse the repository at this point in the history
…iew updates
  • Loading branch information
satello committed Mar 29, 2018
1 parent 2eafee6 commit e854963
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 58 deletions.
7 changes: 3 additions & 4 deletions src/constants/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export const CONTRACT_NOT_DEPLOYED =
export const UNABLE_TO_LOAD_CONTRACT =
'Unable to load contract. Are you sure the contract artifact is correct?'

// Arbitrator
export const UNABLE_TO_LOAD_ARBITRATOR =
'Unable to load arbitrator. Missing address or artifact'
export const ARBITRATOR_NOT_SET = 'No arbitrator instance. Use setArbitrator'
// StatefulContractWrapper
export const CONTRACT_INSTANCE_NOT_SET =
'No contract instance. Use setContractInstance'

// PinakionWrapper
export const UNABLE_TO_SET_KLEROS = 'Unable to set Kleros.'
Expand Down
6 changes: 2 additions & 4 deletions src/contractWrappers/PNK/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import PinakionPOC from './PinakionPOC'
import _PinakionPOC from './PinakionPOC'

export default {
PinakionPOC
}
export const PinakionPOC = _PinakionPOC
6 changes: 2 additions & 4 deletions src/contractWrappers/RNG/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import BlockHashRNG from './BlockHashRNG'
import _BlockHashRNG from './BlockHashRNG'

export default {
BlockHashRNG
}
export const BlockHashRNG = _BlockHashRNG
6 changes: 2 additions & 4 deletions src/contractWrappers/arbitrableContracts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ArbitrableTransaction from './ArbitrableTransaction'
import _ArbitrableTransaction from './ArbitrableTransaction'

export default {
ArbitrableTransaction
}
export const ArbitrableTransaction = _ArbitrableTransaction
6 changes: 3 additions & 3 deletions src/contractWrappers/arbitrator/KlerosPOC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import _ from 'lodash'
import * as ethConstants from '../../../constants/eth'
import * as errorConstants from '../../../constants/error'
import * as arbitratorConstants from '../../../constants/arbitrator'
import Arbitrator from '../Arbitrator'
import StatefulContract from '../StatefulContractWrapper'

/**
* Kleros API
*/
class KlerosWrapper extends Arbitrator {
class KlerosWrapper extends StatefulContract {
/**
* Constructor Kleros.
* @param {object} web3Provider - web3 instance.
Expand Down Expand Up @@ -44,7 +44,7 @@ class KlerosWrapper extends Arbitrator {
timesPerPeriod
)
// load arbitrator based on new contract
await this.setArbitrator(contractDeployed.address)
await this.setContractInstance(contractDeployed.address)

return contractDeployed
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ContractWrapper from '../ContractWrapper'
import * as errorConstants from '../../constants/error'

class ArbitratorContract extends ContractWrapper {
class StatefulContract extends ContractWrapper {
constructor(web3Wrapper, contractAddress, artifact) {
super(web3Wrapper)
this.contractAddress = contractAddress
Expand All @@ -10,7 +10,7 @@ class ArbitratorContract extends ContractWrapper {
}

/**
* Load an existing contract from the current arbitrator artifact and address
* Load an existing contract from the current artifact and address
* @returns {object} - The contract instance.
*/
_load = async () => {
Expand All @@ -23,7 +23,7 @@ class ArbitratorContract extends ContractWrapper {
return this.contractInstance
} catch (err) {
console.error(err)
throw new Error(errorConstants.UNABLE_TO_LOAD_ARBITRATOR)
throw new Error(errorConstants.UNABLE_TO_LOAD_CONTRACT)
}
}

Expand All @@ -36,19 +36,22 @@ class ArbitratorContract extends ContractWrapper {
if (!this.contractInstance) {
if (this.contractAddress && this.artifact) return this._load()

throw new Error(errorConstants.ARBITRATOR_NOT_SET)
throw new Error(errorConstants.CONTRACT_INSTANCE_NOT_SET)
}
}

/**
* Set a new arbitrator
* Set a new contract instance
* @param {string} contractAddress - The address of the contract
* @param {object} artifact - Contract artifact to use to load contract
* @returns {object} contractInstance object
*/
setArbitrator = async (contractAddress, artifact) => {
this.contractAddress = contractAddress || this.contractAddress
this.artifact = artifact || this.artifact
setContractInstance = async (
contractAddress = this.contractAddress,
artifact = this.artifact
) => {
this.contractAddress = contractAddress
this.artifact = artifact
return this._load()
}

Expand All @@ -57,4 +60,4 @@ class ArbitratorContract extends ContractWrapper {
getContractAddress = () => this.contractAddress
}

export default ArbitratorContract
export default StatefulContract
6 changes: 2 additions & 4 deletions src/contractWrappers/arbitrator/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import KlerosPOC from './KlerosPOC'
import _KlerosPOC from './KlerosPOC'

export default {
KlerosPOC
}
export const KlerosPOC = _KlerosPOC
18 changes: 8 additions & 10 deletions src/contractWrappers/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import arbitrator from './arbitrator'
import arbitrableTransaction from './arbitrableContracts'
import PNK from './PNK'
import RNG from './RNG'
import * as _arbitrator from './arbitrator'
import * as _arbitrableContracts from './arbitrableContracts'
import * as _PNK from './PNK'
import * as _RNG from './RNG'

export default {
arbitrator,
arbitrableTransaction,
PNK,
RNG
}
export const arbitrator = _arbitrator
export const arbitrableContracts = _arbitrableContracts
export const PNK = _PNK
export const RNG = _RNG
6 changes: 3 additions & 3 deletions src/kleros.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Web3Wrapper from './utils/Web3Wrapper'
import StoreProviderWrapper from './utils/StoreProviderWrapper'
import contracts from './contractWrappers'
import resources from './resourceWrappers'
import * as contracts from './contractWrappers'
import * as resources from './resourceWrappers'
import Arbitrator from './abstractWrappers/arbitrator'
import ArbitrableContracts from './abstractWrappers/arbitrableContracts'

Expand Down Expand Up @@ -35,7 +35,7 @@ class Kleros {
this._web3Wrapper,
arbitratorAddress
)
this._arbitrableTransaction = new this.contracts.arbitrableTransaction.ArbitrableTransaction(
this._arbitrableTransaction = new this.contracts.arbitrableContracts.ArbitrableTransaction(
this._web3Wrapper
)

Expand Down
14 changes: 6 additions & 8 deletions src/resourceWrappers/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Disputes from './Disputes'
import EventListeners from './EventListeners'
import Notifications from './Notifications'
import _Disputes from './Disputes'
import _EventListeners from './EventListeners'
import _Notifications from './Notifications'

export default {
Disputes,
EventListeners,
Notifications
}
export const Disputes = _Disputes
export const EventListeners = _EventListeners
export const Notifications = _Notifications
10 changes: 5 additions & 5 deletions tests/integration/contracts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ describe('Contracts', () => {
expect(newKlerosPOC.address).toBeTruthy()

try {
await KlerosInstance.arbitrator.setArbitrator('badAddress')
await KlerosInstance.arbitrator.setContractInstance('badAddress')
} catch (err) {
expect(err.message).toEqual(errorConstants.UNABLE_TO_LOAD_ARBITRATOR)
expect(err.message).toEqual(errorConstants.UNABLE_TO_LOAD_CONTRACT)
}
})
it('setArbitrator throws with undefined parameters', async () => {
it('setContractInstance throws with undefined parameters', async () => {
const KlerosInstance = new Kleros(undefined, provider)
// deploy KlerosPOC with no PNK or RNG
const newKlerosPOC = await KlerosInstance.arbitrator.deploy(
Expand All @@ -102,9 +102,9 @@ describe('Contracts', () => {
const noAddressKlerosPOC = new KlerosApi(KlerosInstance.getWeb3Wrapper())

try {
await noAddressKlerosPOC.setArbitrator()
await noAddressKlerosPOC.setContractInstance()
} catch (err) {
expect(err.message).toEqual(errorConstants.UNABLE_TO_LOAD_ARBITRATOR)
expect(err.message).toEqual(errorConstants.UNABLE_TO_LOAD_CONTRACT)
}
})
})
Expand Down

0 comments on commit e854963

Please sign in to comment.