Skip to content

Commit

Permalink
fix: Merge conflict bug on TwoPartyArbitrable.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricexit committed Jul 25, 2018
1 parent 50006de commit fa3700a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 59 deletions.
Empty file added .node-xmlhttprequest-sync-10272
Empty file.
15 changes: 7 additions & 8 deletions contracts/standard/arbitration/TwoPartyArbitrable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ contract TwoPartyArbitrable is Arbitrable {
uint public disputeID;
enum Status {NoDispute, WaitingPartyA, WaitingPartyB, DisputeCreated, Resolved}
Status public status;

uint8 constant AMOUNT_OF_CHOICES = 2;

uint8 constant PARTY_A_WINS = 1;
uint8 constant PARTY_B_WINS = 2;
string constant RULING_OPTIONS = "Party A wins;Party B wins"; // A plain English of what rulings do. Need to be redefined by the child class.
Expand Down Expand Up @@ -62,9 +61,9 @@ contract TwoPartyArbitrable is Arbitrable {
Arbitrable(_arbitrator,_arbitratorExtraData)
public
{
timeout=_timeout;
partyA=msg.sender;
partyB=_partyB;
timeout = _timeout;
partyA = msg.sender;
partyB = _partyB;
amountOfChoices = _amountOfChoices;
emit MetaEvidence(0, _metaEvidence);
}
Expand Down Expand Up @@ -106,7 +105,7 @@ contract TwoPartyArbitrable is Arbitrable {
lastInteraction = now;
if (partyAFee < arbitrationCost) {
// The partyA still has to pay. This can also happens if he has paid, but arbitrationCost has increased.
status=Status.WaitingPartyA;
status = Status.WaitingPartyA;
emit HasToPayFee(Party.PartyA);
} else {
// The partyA has also paid the fee. We create the dispute
Expand All @@ -119,7 +118,7 @@ contract TwoPartyArbitrable is Arbitrable {
*/
function raiseDispute(uint _arbitrationCost) internal {
status = Status.DisputeCreated;
disputeID = arbitrator.createDispute.value(_arbitrationCost)(AMOUNT_OF_CHOICES,arbitratorExtraData);
disputeID = arbitrator.createDispute.value(_arbitrationCost)(amountOfChoices,arbitratorExtraData);
emit Dispute(arbitrator,disputeID,RULING_OPTIONS);
emit LinkMetaEvidence(arbitrator,disputeID,0);
}
Expand Down Expand Up @@ -166,7 +165,7 @@ contract TwoPartyArbitrable is Arbitrable {
*/
function executeRuling(uint _disputeID, uint _ruling) internal {
require(_disputeID==disputeID);
require(_ruling<=AMOUNT_OF_CHOICES);
require(_ruling<=amountOfChoices);

// Give the arbitration fee back.
// Note that we use send to prevent a party from blocking the execution.
Expand Down
28 changes: 16 additions & 12 deletions contracts/standard/permission/ArbitrablePermissionList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import "./PermissionInterface.sol";
/**
* @title Arbitrable Permission List
* @dev This is an arbitrator curated registry. Anyone can post an item with a deposit. If no one complains within a defined time period, the item is added to the registry.
* Someone can complain and also post a deposit, if, someone does, a dispute is created. The winner of the dispute gets the deposit of the other party and the item is added or removed accordingly.
* During the time of the dispute, the item is shown as blacklisted unless it already won a previous dispute. This follows the philosophy that it is better to show the user a warning about a potentially harmless listing than to take the risk of the user being scammed or exposed to inappropriate content without warning.
* Anyone can complain and also post a deposit. If someone does, a dispute is created. The winner of the dispute gets the deposit of the other party and the item is added or removed accordingly.
* To make a request, parties have to deposit a stake and the arbitration fees. If the arbitration fees change between the submitter's payment and the challenger's payment, a part of the submitter stake can be used as an arbitration fee deposit.
* In case the arbitrator refuses to rule, the item is put in the initial absent status and the balance is split equally between parties.
*/
Expand All @@ -35,7 +34,7 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
struct Item {
ItemStatus status; // Status of the item.
uint lastAction; // Time of the last action.
address submitter; // Address of the submitter, if any.
address submitter; // Address of the submitter of the item status change request, if any.
address challenger; // Address of the challenger, if any.
uint balance; // The total amount of funds to be given to the winner of a potential dispute. Includes stake and reimbursement of arbitration fees.
bool disputed; // True if a dispute is taking place.
Expand Down Expand Up @@ -65,13 +64,12 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
// Settings
bool public blacklist; // True if the list should function as a blacklist, false if it should function as a whitelist.
bool public appendOnly; // True if the list should be append only.
uint public stake;
uint public timeToChallenge;
uint public stake; // The stake to put to submit/clear/challenge and item in addition of arbitration fees.
uint public timeToChallenge; // The time before which an action is executable if not challenged.

// Ruling Options
uint8 constant REGISTER = 1;
uint8 constant CLEAR = 2;
string constant RULING_OPTIONS = "Register;Clear";

// Items
mapping(bytes32 => Item) public items;
Expand All @@ -87,7 +85,7 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
* @param _metaEvidence The URL of the meta evidence object.
* @param _blacklist True if the list should function as a blacklist, false if it should function as a whitelist.
* @param _appendOnly True if the list should be append only.
* @param _stake The amount in Weis of deposit required for a submission or a challenge.
* @param _stake The amount in Weis of deposit required for a submission or a challenge in addition of the arbitration fees.
* @param _timeToChallenge The time in seconds, other parties have to challenge.
*/
constructor(
Expand Down Expand Up @@ -180,7 +178,7 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
item.disputeID = arbitrator.createDispute.value(arbitratorCost)(2,arbitratorExtraData);
disputeIDToItem[item.disputeID] = _value;
emit LinkMetaEvidence(arbitrator, item.disputeID, 0);
} else { // In the case the arbitration fees increase so much that the deposit of the requester is not high enough. Cancel the request.
} else { // In the case the arbitration fees increased so much that the deposit of the requester is not high enough. Cancel the request.
if (item.status == ItemStatus.Resubmitted)
item.status = ItemStatus.Cleared;
else
Expand Down Expand Up @@ -214,7 +212,7 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
item.disputeID = arbitrator.createDispute.value(arbitratorCost)(2,arbitratorExtraData);
disputeIDToItem[item.disputeID] = _value;
emit LinkMetaEvidence(arbitrator, item.disputeID, 0);
} else { // In the case the arbitration fees increase so much that the deposit of the requester is not high enough. Cancel the request.
} else { // In the case the arbitration fees increased so much that the deposit of the requester is not high enough. Cancel the request.
if (item.status == ItemStatus.ClearingRequested)
item.status = ItemStatus.Registered;
else
Expand Down Expand Up @@ -263,7 +261,8 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
/* Public Views */

/**
* @dev Return true if the item is allowed. We take a conservative approach and return false if the status of the item is contested and it has not won a previous dispute.
* @dev Return true if the item is allowed.
* We consider the item to be in the list if its status is contested and it has not won a dispute previously.
* @param _value The value of the item to check.
* @return allowed True if the item is allowed, false otherwise.
*/
Expand Down Expand Up @@ -300,7 +299,12 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {

item.status = ItemStatus.Cleared;
} else { // Split the balance 50-50 and give the item the initial status.
item.status = ItemStatus.Absent;
if (item.status==ItemStatus.Resubmitted)
item.status==ItemStatus.Cleared;
else if (item.status==ItemStatus.ClearingRequested)
item.status==ItemStatus.Submitted;
else
item.status==ItemStatus.Absent;
item.submitter.send(item.balance / 2);
item.challenger.send(item.balance / 2);
}
Expand Down Expand Up @@ -373,4 +377,4 @@ contract ArbitrablePermissionList is PermissionInterface, Arbitrable {
}
}
}
}
}
20 changes: 11 additions & 9 deletions test/arbitrableKitty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract('ArbitrableKitty', (accounts) => {
TIMEOUT: 100,
ARBITRATION_FEE: 20,
EXTRA_DATA: 0x08575,
CONTRACT_HASH: 0x6aa0bb2779ab006be0739900654a89f1f8a2d7373ed38490a7cbab9c9392e1ff,
META_EVIDENCE: 'https://kleros.io',
PARTY_A_WINS: 1,
PARTY_B_WINS: 2,
SHARED_CUSTODY: 3,
Expand All @@ -42,7 +42,7 @@ contract('ArbitrableKitty', (accounts) => {
params.kittyId = await mintKitty(4000, params.PARTY_A)

// Deploy arbitrable contract
arbitrable = await deployArbitrableKitty(params, arbitrator, kittyCore, { from: PARTY_A })
arbitrable = await deployArbitrableKitty(params, arbitrator, kittyCore)

// Transfer kitty to contract
await kittyCore.transfer(arbitrable.address, params.kittyId, { from: PARTY_A })
Expand Down Expand Up @@ -102,15 +102,15 @@ contract('ArbitrableKitty', (accounts) => {
}

const deployArbitrableKitty = async (params, arbitrator, kittyCore) => {
const { CONTRACT_HASH, TIMEOUT, PARTY_B, EXTRA_DATA, PARTY_A, AMOUNT_OF_CHOICES } = params
const { META_EVIDENCE, TIMEOUT, PARTY_B, EXTRA_DATA, PARTY_A } = params

return ArbitrableKitty.new(
arbitrator.address,
kittyCore.address,
PARTY_B,
CONTRACT_HASH,
TIMEOUT,
EXTRA_DATA,
META_EVIDENCE,
{from: PARTY_A}
)
}
Expand Down Expand Up @@ -462,7 +462,7 @@ contract('ArbitrableKitty', (accounts) => {
await arbitrable.payArbitrationFeeByPartyA({from: PARTY_A, value: ARBITRATION_FEE})
await arbitrable.payArbitrationFeeByPartyB({from: PARTY_B, value: ARBITRATION_FEE})

// Grant shared custody
// // Grant shared custody
await arbitrator.giveRuling(0, SHARED_CUSTODY, { from: ARBITRATOR })
})

Expand All @@ -480,11 +480,11 @@ contract('ArbitrableKitty', (accounts) => {
assert.isFalse(await arbitrable.underSendersCustody({ from: PARTY_A }),"should not be available yet")

increaseTime(1)

assert.isTrue(await arbitrable.underSendersCustody({ from: PARTY_A }),"should be under A's custody")
assert.isFalse(await arbitrable.underSendersCustody({ from: PARTY_B }),"should be under A's custody")

increaseTime(60 * 60 * 24 * 7)
increaseTime(60 * 60 * 24 * 7)
assert.isTrue(await arbitrable.underSendersCustody({ from: PARTY_B }),"should be under B's custody")
assert.isFalse(await arbitrable.underSendersCustody({ from: PARTY_A }),"should be under B's custody")
})
Expand Down Expand Up @@ -530,7 +530,7 @@ contract('ArbitrableKitty', (accounts) => {
await mintKitty(2000, OTHER_USER),
OTHER_USER
)

await expectThrow(
arbitrable.bidOnSiringAuction(otherKittyId, kittyId, { from: PARTY_A, value: 200 })
)
Expand All @@ -544,12 +544,13 @@ contract('ArbitrableKitty', (accounts) => {

await arbitrable.giveBirth(kittyId, { from: PARTY_B })
})

})

describe('Custody math checker', () => {
beforeEach(deployAndPrepare)

it('should calculate modulus correctly', async () => {
it('should calculate modulus correctly', async () => {
assert.equal((await arbitrable.modulus(21999,1661)).toNumber(),406)
assert.equal((await arbitrable.modulus(2,4)).toNumber(),2)
await expectThrow(
Expand All @@ -565,4 +566,5 @@ contract('ArbitrableKitty', (accounts) => {
assert.equal((await arbitrable.custodyTurn(10000,10300,300)).toNumber(),partyB)
})
})

})
28 changes: 15 additions & 13 deletions test/arbitrablePermissionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ contract('ArbitrablePermissionList', function(accounts) {
appendOnly = false;

arbitrablePermissionList = await ArbitrablePermissionList.new(
blacklist,
appendOnly,
centralizedArbitrator.address,
arbitratorExtraData,
"Test",
blacklist,
appendOnly,
stake,
timeToChallenge, {
from: arbitrator
Expand Down Expand Up @@ -143,10 +144,11 @@ contract('ArbitrablePermissionList', function(accounts) {
});

arbitrablePermissionList = await ArbitrablePermissionList.new(
blacklist,
appendOnly,
centralizedArbitrator.address,
arbitratorExtraData,
"Test",
blacklist,
appendOnly,
stake,
timeToChallenge, {
from: arbitrator
Expand Down Expand Up @@ -513,7 +515,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.CLEARED)
});

it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the absent state', async function() {
it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the resubmitted state', async function() {

const submitter = (await arbitrablePermissionList.items(ARBITRARY_STRING))[2];
const challenger = (await arbitrablePermissionList.items(ARBITRARY_STRING))[3];
Expand All @@ -533,7 +535,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert(actualBalanceOfSubmitter.equals(expectedBalanceOfSubmitter), "Actual: " + actualBalanceOfSubmitter + "\t0Expected: " + expectedBalanceOfSubmitter)
assert(actualBalanceOfChallenger.equals(expectedBalanceOfChallenger), "1Differece: " + actualBalanceOfChallenger.minus(expectedBalanceOfChallenger))

assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.ABSENT)
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.RESUBMITTED)

})
})
Expand Down Expand Up @@ -718,7 +720,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.CLEARED)
});

it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the absent state', async function() {
it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the submitted state', async function() {
const submitter = (await arbitrablePermissionList.items(ARBITRARY_STRING))[2];
const challenger = (await arbitrablePermissionList.items(ARBITRARY_STRING))[3];
const submitterBalance = web3.eth.getBalance(submitter);
Expand All @@ -739,7 +741,7 @@ contract('ArbitrablePermissionList', function(accounts) {

assert(actualBalanceOfSubmitter.equals(expectedBalanceOfSubmitter), "Actual: " + actualBalanceOfSubmitter + "\tExpected: " + expectedBalanceOfSubmitter)
assert(actualBalanceOfChallenger.equals(expectedBalanceOfChallenger), "Actual: " + actualBalanceOfChallenger + "\tExpected: " + expectedBalanceOfChallenger)
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.ABSENT)
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.SUBMITTED)
})
})
});
Expand Down Expand Up @@ -861,7 +863,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.CLEARED)
});

it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the absent state', async function() {
it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the submitted state', async function() {
const submitter = (await arbitrablePermissionList.items(ARBITRARY_STRING))[2];
const challenger = (await arbitrablePermissionList.items(ARBITRARY_STRING))[3];
const submitterBalance = web3.eth.getBalance(submitter);
Expand All @@ -881,7 +883,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert(actualBalanceOfSubmitter.equals(expectedBalanceOfSubmitter), "Difference: " + actualBalanceOfSubmitter.minus(expectedBalanceOfSubmitter));
assert(actualBalanceOfChallenger.equals(expectedBalanceOfChallenger), "Difference: " + actualBalanceOfChallenger.minus(expectedBalanceOfChallenger));

assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.ABSENT);
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.CLEARING_REQUESTED);
})
})
});
Expand Down Expand Up @@ -1001,7 +1003,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.CLEARED)
});

it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the absent state', async function() {
it('calling executeRuling with OTHER should split item.balance between challenger and submitter and move item into the preventive clearing requested state', async function() {
const submitter = (await arbitrablePermissionList.items(ARBITRARY_STRING))[2];
const challenger = (await arbitrablePermissionList.items(ARBITRARY_STRING))[3];
const submitterBalance = web3.eth.getBalance(submitter);
Expand All @@ -1021,7 +1023,7 @@ contract('ArbitrablePermissionList', function(accounts) {
assert(actualBalanceOfSubmitter.equals(expectedBalanceOfSubmitter), "Difference: " + actualBalanceOfSubmitter.minus(expectedBalanceOfSubmitter));
assert(actualBalanceOfChallenger.equals(expectedBalanceOfChallenger), "Difference: " + actualBalanceOfChallenger.minus(expectedBalanceOfChallenger));

assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.ABSENT);
assert.equal((await arbitrablePermissionList.items(ARBITRARY_STRING))[0].toNumber(), ITEM_STATUS.PREVENTIVE_CLEARING_REQUESTED);
})
})
})
Expand All @@ -1030,4 +1032,4 @@ contract('ArbitrablePermissionList', function(accounts) {
})
}
}
});
});
Loading

0 comments on commit fa3700a

Please sign in to comment.