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

Commit

Permalink
fix: test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras authored and satello committed Feb 15, 2018
1 parent d0d40f8 commit 98b777d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/contractWrappers/ArbitrableTransactionWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ class ArbitrableTransactionWrapper extends ContractWrapper {
status: status.toNumber(),
arbitratorExtraData,
disputeId: disputeId.toNumber(),
partyAFee: this._Web3Wrapper.fromWei(partyAFee.toNumber(), 'ether'),
partyBFee: this._Web3Wrapper.fromWei(partyBFee.toNumber(), 'ether'),
partyAFee: this._Web3Wrapper.fromWei(partyAFee, 'ether'),
partyBFee: this._Web3Wrapper.fromWei(partyBFee, 'ether'),
lastInteraction,
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/contractWrappers/KlerosWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ class KlerosWrapper extends ContractWrapper {
if (!juror) throw new Error(`${account} is not a juror for contract ${contractAddress}`)

// total tokens stored in contract
const contractBalance = this._Web3Wrapper.fromWei(juror[0].toNumber(), 'ether')
const contractBalance = this._Web3Wrapper.fromWei(juror[0], 'ether')
// tokens activated in court session
const currentSession = await contractInstance.session.call()
let activatedTokens = 0
if (juror[2].toNumber() === currentSession.toNumber()) {
activatedTokens = this._Web3Wrapper.fromWei((juror[4].toNumber() - juror[3].toNumber()), 'ether')
}
// tokens locked into disputes
const lockedTokens = this._Web3Wrapper.fromWei(juror[2].toNumber(), 'ether')
const lockedTokens = this._Web3Wrapper.fromWei(juror[2], 'ether')

return {
activatedTokens,
Expand Down Expand Up @@ -184,7 +184,7 @@ class KlerosWrapper extends ContractWrapper {
try {
const arbitrationCost = await contractInstance.arbitrationCost(contractExtraData)

return this._Web3Wrapper.fromWei(arbitrationCost.toNumber(), 'ether')
return this._Web3Wrapper.fromWei(arbitrationCost, 'ether')
} catch (e) {
throw new Error(e)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ class KlerosWrapper extends ContractWrapper {
numberOfAppeals: dispute[2].toNumber(),
rulingChoices: dispute[3].toNumber(),
initialNumberJurors: dispute[4].toNumber(),
arbitrationFeePerJuror: this._Web3Wrapper.fromWei(dispute[5].toNumber(), 'ether'),
arbitrationFeePerJuror: this._Web3Wrapper.fromWei(dispute[5], 'ether'),
state: dispute[6].toNumber(),
status: (await contractInstance.disputeStatus(disputeId)).toNumber()
}
Expand Down
36 changes: 15 additions & 21 deletions src/test/kleros.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Kleros', () => {
const mockArbitratorExtraData = ''
const mockEmail = '[email protected]'
const mockDescription = 'test description'
const contractPaymentAmount = web3.toWei(1, 'ether') // contract payment be 1 ether
const contractPaymentAmount = KlerosInstance._web3Wrapper.toWei(1, 'ether') // contract payment be 1 ether
let contractArbitrableTransactionData = await KlerosInstance.arbitrableContract
.deployContract(
partyA,
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('Kleros', () => {
const mockArbitratorExtraData = ''
const mockEmail = '[email protected]'
const mockDescription = 'test description'
const contractPaymentAmount = web3.toWei(1, 'ether') // contract payment be 1 ether
const contractPaymentAmount = KlerosInstance._web3Wrapper.toWei(1, 'ether') // contract payment be 1 ether
let contractArbitrableTransactionData = await KlerosInstance.arbitrableContract
.deployContract(
partyA,
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('Kleros', () => {
let extraDataContractInstance = await arbitrableContractInstance
.arbitratorExtraData()

// return a bigint with the default value : 10000 wei fees
// return a bigint with the default value : 10000 wei fees in ether
const arbitrationCost = await KlerosInstance.klerosPOC.getArbitrationCost(
klerosCourt.address,
extraDataContractInstance
Expand All @@ -253,9 +253,7 @@ describe('Kleros', () => {
.raiseDisputePartyA(
partyA,
contractArbitrableTransactionData.address,
web3.fromWei(
arbitrationCost - partyAFeeContractInstance.toNumber(), 'ether'
)
arbitrationCost - KlerosInstance._web3Wrapper.fromWei(partyAFeeContractInstance, 'ether')
)
expect(txHashRaiseDisputeByPartyA)
.toEqual(expect.stringMatching(/^0x[a-f0-9]{64}$/)) // tx hash
Expand Down Expand Up @@ -329,7 +327,7 @@ describe('Kleros', () => {

// Juror should have no balance to start with
const initialBalance = await KlerosInstance.arbitrator.getPNKBalance(klerosCourt.address, juror)
expect(initialBalance.tokenBalance).toEqual('0')
expect(initialBalance.tokenBalance).toEqual(0)

// stateful notifications juror
let jurorStatefullNotifications = await KlerosInstance.notifications.getStatefulNotifications(juror, true)
Expand All @@ -338,29 +336,29 @@ describe('Kleros', () => {

// buy 1 PNK
const newBalance = await KlerosInstance.arbitrator.buyPNK(1, klerosCourt.address, juror)
expect(newBalance.tokenBalance).toEqual('1')
expect(newBalance.tokenBalance).toEqual(1)

// activate PNK
const activatedTokenAmount = 0.5
const balance = await KlerosInstance.arbitrator.activatePNK(activatedTokenAmount, klerosCourt.address, juror)
expect(balance.tokenBalance).toEqual('1')
expect(balance.activatedTokens).toEqual('0.5')
expect(balance.tokenBalance).toEqual(1)
expect(balance.activatedTokens).toEqual(0.5)

// stateful notifications juror
jurorStatefullNotifications = await KlerosInstance.notifications.getStatefulNotifications(juror, true)
expect(jurorStatefullNotifications.length).toEqual(0)

const jurorData = await klerosPOCInstance.jurors(juror)
expect(jurorData[2].toNumber()).toEqual((await klerosPOCInstance.session()).toNumber())
expect((jurorData[4].toNumber() - jurorData[3].toNumber())).toEqual(parseInt(web3.toWei(activatedTokenAmount, 'ether')))
expect((jurorData[4].toNumber() - jurorData[3].toNumber())).toEqual(KlerosInstance._web3Wrapper.toWei(activatedTokenAmount, 'ether'))

// deploy a contract and create dispute
const mockHash = 'mock-hash-contract'
const mockTimeout = 1
const mockArbitratorExtraData = ''
const mockEmail = '[email protected]'
const mockDescription = 'test description'
const contractPaymentAmount = web3.toWei(1, 'ether') // contract payment be 1 ether
const contractPaymentAmount = KlerosInstance._web3Wrapper.toWei(1, 'ether') // contract payment be 1 ether
let contractArbitrableTransactionData = await KlerosInstance.arbitrableContract
.deployContract(
partyA,
Expand Down Expand Up @@ -396,20 +394,18 @@ describe('Kleros', () => {
let extraDataContractInstance = await arbitrableContractInstance
.arbitratorExtraData()

// return a bigint with the default value : 10000 wei fees
// return a bigint with the default value : 10000 wei fees in ether
const arbitrationCost = await KlerosInstance.klerosPOC.getArbitrationCost(
klerosCourt.address,
extraDataContractInstance
)

// raise dispute party A
const txHashRaiseDisputeByPartyA = await KlerosInstance.disputes
.raiseDisputePartyA(
partyA,
contractArbitrableTransactionData.address,
web3.fromWei(
arbitrationCost - partyAFeeContractInstance.toNumber(), 'ether'
)
arbitrationCost - KlerosInstance._web3Wrapper.fromWei(partyAFeeContractInstance, 'ether')
)
expect(txHashRaiseDisputeByPartyA)
.toEqual(expect.stringMatching(/^0x[a-f0-9]{64}$/)) // tx hash
Expand All @@ -428,9 +424,7 @@ describe('Kleros', () => {
.raiseDisputePartyB(
partyB,
contractArbitrableTransactionData.address,
web3.fromWei(
arbitrationCost - partyBFeeContractInstance.toNumber(), 'ether'
)
arbitrationCost - KlerosInstance._web3Wrapper.fromWei(partyBFeeContractInstance, 'ether')
)
expect(txHashRaiseDisputeByPartyB)
.toEqual(expect.stringMatching(/^0x[a-f0-9]{64}$/)) // tx hash
Expand Down Expand Up @@ -568,7 +562,7 @@ describe('Kleros', () => {
await KlerosInstance.klerosPOC.executeRuling(klerosCourt.address, 0, other)
// balances after ruling
// partyA wins so they should recieve their arbitration fee as well as the value locked in contract
expect(web3.eth.getBalance(partyA).toNumber() - partyABalance).toEqual(arbitrationCost + parseInt(contractPaymentAmount))
expect(web3.eth.getBalance(partyA).toNumber() - partyABalance).toEqual(KlerosInstance._web3Wrapper.toWei(arbitrationCost, 'ether') + contractPaymentAmount)
// partyB lost so their balance should remain the same
expect(web3.eth.getBalance(partyB).toNumber()).toEqual(partyBBalance)

Expand Down
10 changes: 8 additions & 2 deletions util/Web3Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ class Web3Wrapper {

getCoinbase = () => this._web3.eth.coinbase

toWei = (amount, unit) => this._web3.toWei(amount, unit)
toWei = (amount, unit) => {
const newAmount = this._web3.toWei(amount, unit)
return newAmount.toNumber ? newAmount.toNumber() : Number(newAmount)
}

fromWei = (amount, unit) => this._web3.fromWei(amount, unit)
fromWei = (amount, unit) => {
const newAmount = this._web3.fromWei(amount, unit)
return newAmount.toNumber ? newAmount.toNumber() : Number(newAmount)
}

toBigNumber = (number) => this._web3.toBigNumber(number)

Expand Down

0 comments on commit 98b777d

Please sign in to comment.