Skip to content

Commit

Permalink
fix(multiple-arbitrable-payment): handle no ruling
Browse files Browse the repository at this point in the history
  • Loading branch information
n1c01a5 committed Oct 21, 2018
1 parent ccc2fce commit a2bf326
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ contract MultipleArbitrableTransaction {
} else if (_ruling == BUYER_WINS) {
transaction.buyer.send(transaction.sellerFee > transaction.buyerFee ? transaction.sellerFee : transaction.buyerFee);
transaction.buyer.send(transaction.amount);
} else if (_ruling == 0) {
uint split_anount = ((transaction.sellerFee > transaction.buyerFee ? transaction.sellerFee : transaction.buyerFee) + transaction.amount) / 2;
transaction.buyer.send(split_anount);
transaction.seller.send(split_anount);
}

transaction.amount = 0;
Expand Down
24 changes: 13 additions & 11 deletions test/multiple-arbitrable-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ contract('MultipleArbitrableTransaction', function(accounts) {
)
})

it('It should do nothing if the arbitrator decides so', async () => {
it('Should split the amount if there is no ruling', async () => {
const centralizedArbitrator = await CentralizedArbitrator.new(
arbitrationFee,
{ from: arbitrator }
Expand Down Expand Up @@ -468,20 +468,22 @@ contract('MultipleArbitrableTransaction', function(accounts) {
from: payee,
value: arbitrationFee
})
const payeeBalanceBeforePay = web3.eth.getBalance(payee)
const payerBalanceBeforeReimbursment = web3.eth.getBalance(payer)
const payerBalanceBeforeRuling = web3.eth.getBalance(payer)
const payeeBalanceBeforeRuling = web3.eth.getBalance(payee)

await centralizedArbitrator.giveRuling(0, 0, { from: arbitrator })
const newPayeeBalance = web3.eth.getBalance(payee)
const newPayerBalance = web3.eth.getBalance(payer)
const payerBalanceAfterRuling = web3.eth.getBalance(payer)
const payeeBalanceAfterRuling = web3.eth.getBalance(payee)

assert.equal(
newPayeeBalance.toString(),
payeeBalanceBeforePay.toString(),
"The payee got wei while it shouldn't"
payerBalanceAfterRuling.toString(),
payerBalanceBeforeRuling.plus(510).toString(),
'The payee has not been paid properly'
)
assert.equal(
newPayerBalance.toString(),
payerBalanceBeforeReimbursment.toString(),
"The payer got wei while it shouldn't"
payeeBalanceAfterRuling.toString(),
payeeBalanceBeforeRuling.plus(510).toString(),
'The payer has not been reimbursed correctly'
)
})

Expand Down

0 comments on commit a2bf326

Please sign in to comment.