diff --git a/src/contractWrappers/ArbitrableTransactionWrapper.js b/src/contractWrappers/ArbitrableTransactionWrapper.js index 709cd09..b1b1a80 100644 --- a/src/contractWrappers/ArbitrableTransactionWrapper.js +++ b/src/contractWrappers/ArbitrableTransactionWrapper.js @@ -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, } } diff --git a/src/contractWrappers/KlerosWrapper.js b/src/contractWrappers/KlerosWrapper.js index 4fcfdbe..a27733a 100644 --- a/src/contractWrappers/KlerosWrapper.js +++ b/src/contractWrappers/KlerosWrapper.js @@ -120,7 +120,7 @@ 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 @@ -128,7 +128,7 @@ class KlerosWrapper extends ContractWrapper { 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, @@ -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) } @@ -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() } diff --git a/src/test/kleros.test.js b/src/test/kleros.test.js index d84b41a..3fe9508 100644 --- a/src/test/kleros.test.js +++ b/src/test/kleros.test.js @@ -147,7 +147,7 @@ describe('Kleros', () => { const mockArbitratorExtraData = '' const mockEmail = 'test@kleros.io' 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, @@ -206,7 +206,7 @@ describe('Kleros', () => { const mockArbitratorExtraData = '' const mockEmail = 'test@kleros.io' 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, @@ -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 @@ -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 @@ -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) @@ -338,13 +336,13 @@ 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) @@ -352,7 +350,7 @@ describe('Kleros', () => { 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' @@ -360,7 +358,7 @@ describe('Kleros', () => { const mockArbitratorExtraData = '' const mockEmail = 'test@kleros.io' 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, @@ -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 @@ -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 @@ -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) diff --git a/util/Web3Wrapper.js b/util/Web3Wrapper.js index 8158203..b91ee2e 100644 --- a/util/Web3Wrapper.js +++ b/util/Web3Wrapper.js @@ -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)