Skip to content

Commit

Permalink
fix: Amount of choices for inheriting contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricexit committed Jun 30, 2018
1 parent ec38cfd commit 2866689
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 50 deletions.
11 changes: 5 additions & 6 deletions contracts/standard/arbitration/ArbitrableKitty.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/


pragma solidity 0.4.24;
pragma solidity ^0.4.24;
import "./TwoPartyArbitrable.sol";
import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "./CriptoKitties/KittyCore.sol";
Expand Down Expand Up @@ -45,6 +45,7 @@ contract ArbitrableKitty is TwoPartyArbitrable{

string constant RULING_OPTIONS = "Give to partyA;Give to partyB;Grant shared custody";
uint8 constant SHARED_CUSTODY = 3;
uint8 constant AMOUNT_OF_CHOICES = 3; // The number of ruling options available.

uint256 constant CUSTODY_TIME = 1 weeks;
address public winner;
Expand Down Expand Up @@ -115,25 +116,23 @@ contract ArbitrableKitty is TwoPartyArbitrable{
* @param _kittyCore CriptoKitty core smart contract.
* @param _partyB The partner sharing the kitty.
* @param _hashContract Keccak hash of the plain English contract.
* @param _timeout Time after which a party automatically loose a dispute.
* @param _amountOfChoices The number of ruling options available.
* @param _timeout Time after which a party automatically loose a dispute.
* @param _arbitratorExtraData Extra data for the arbitrator.
*/
constructor(
Arbitrator _arbitrator,
KittyCore _kittyCore,
address _partyB,
bytes32 _hashContract,
uint _timeout,
uint8 _amountOfChoices,
uint _timeout,
bytes _arbitratorExtraData
)
TwoPartyArbitrable(
_arbitrator,
_hashContract,
_timeout,
_partyB,
_amountOfChoices,
AMOUNT_OF_CHOICES,
_arbitratorExtraData
)
payable
Expand Down
9 changes: 4 additions & 5 deletions contracts/standard/arbitration/ArbitrableTransaction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "./TwoPartyArbitrable.sol";
*/
contract ArbitrableTransaction is TwoPartyArbitrable {
string constant RULING_OPTIONS = "Reimburse partyA;Pay partyB";
uint8 constant AMOUNT_OF_CHOICES = 2; // The number of ruling options available.

uint public amount; // Amount sent by party A.

Expand All @@ -23,24 +24,22 @@ contract ArbitrableTransaction is TwoPartyArbitrable {
* @param _arbitrator The arbitrator of the contract.
* @param _hashContract Keccak hash of the plain English contract.
* @param _timeout Time after which a party automatically loose a dispute.
* @param _partyB The recipient of the transaction.
* @param _amountOfChoices The number of ruling options available.
* @param _partyB The recipient of the transaction.
* @param _arbitratorExtraData Extra data for the arbitrator.
*/
constructor(
Arbitrator _arbitrator,
bytes32 _hashContract,
uint _timeout,
address _partyB,
uint8 _amountOfChoices,
address _partyB,
bytes _arbitratorExtraData
)
TwoPartyArbitrable(
_arbitrator,
_hashContract,
_timeout,
_partyB,
_amountOfChoices,
AMOUNT_OF_CHOICES,
_arbitratorExtraData)
public
payable
Expand Down
11 changes: 5 additions & 6 deletions contracts/standard/arbitration/Rental.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import "./TwoPartyArbitrable.sol";
*/
contract Rental is TwoPartyArbitrable {
string constant RULING_OPTIONS = "Rule for party A (renter);Rule for Party B (owner)";

uint8 constant AMOUNT_OF_CHOICES = 2; // The number of ruling options available.

uint public amount; // Amount sent by party A.
uint public damagesClaimedByPartyA; // The amount party A agrees to pay to compensate damages.
uint public damagesClaimedByPartyB; // The amount party B claims to compensate damages.
Expand All @@ -26,24 +27,22 @@ contract Rental is TwoPartyArbitrable {
* @param _arbitrator The arbitrator of the contract.
* @param _hashContract Keccak hash of the plain English contract.
* @param _timeout Time after which a party automatically loose a dispute.
* @param _partyB The owner.
* @param _amountOfChoices The number of ruling options available.
* @param _partyB The owner.
* @param _arbitratorExtraData Extra data for the arbitrator.
*/
constructor(
Arbitrator _arbitrator,
bytes32 _hashContract,
uint _timeout,
address _partyB,
uint8 _amountOfChoices,
address _partyB,
bytes _arbitratorExtraData
)
TwoPartyArbitrable(
_arbitrator,
_hashContract,
_timeout,
_partyB,
_amountOfChoices,
AMOUNT_OF_CHOICES,
_arbitratorExtraData
)
public
Expand Down
2 changes: 0 additions & 2 deletions test/arbitrableKitty.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract('ArbitrableKitty', (accounts) => {
OTHER_USER: accounts[3],
TIMEOUT: 100,
ARBITRATION_FEE: 20,
AMOUNT_OF_CHOICES: 3,
EXTRA_DATA: 0x08575,
CONTRACT_HASH: 0x6aa0bb2779ab006be0739900654a89f1f8a2d7373ed38490a7cbab9c9392e1ff,
PARTY_A_WINS: 1,
Expand Down Expand Up @@ -111,7 +110,6 @@ contract('ArbitrableKitty', (accounts) => {
PARTY_B,
CONTRACT_HASH,
TIMEOUT,
AMOUNT_OF_CHOICES,
EXTRA_DATA,
{from: PARTY_A}
)
Expand Down
34 changes: 17 additions & 17 deletions test/arbitrableTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract('ArbitrableTransaction', function (accounts) {

// Constructor
it('Should put 1000 wei in the contract', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
assert.equal(web3.eth.getBalance(arbitrableTransaction.address), 1000, "The contract hasn't received the wei correctly.")

let amountSending = await arbitrableTransaction.amount()
Expand All @@ -26,20 +26,20 @@ contract('ArbitrableTransaction', function (accounts) {
// Pay
it('Should pay the payee', async () => {
let initialPayeeBalance = web3.eth.getBalance(payee)
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.pay({from: payer})
let newPayeeBalance = web3.eth.getBalance(payee)
assert.equal(newPayeeBalance.toString(), initialPayeeBalance.plus(1000).toString(), "The payee hasn't been paid properly")
})

it('Should not pay the payee', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await expectThrow(arbitrableTransaction.pay({from: payee}))
})

// Reimburse
it('Should reimburse 507 to the payer', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer)
await arbitrableTransaction.reimburse(507, {from: payee})
let newPayerBalance = web3.eth.getBalance(payer)
Expand All @@ -52,7 +52,7 @@ contract('ArbitrableTransaction', function (accounts) {
})

it('Should reimburse 1000 (all) to the payer', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer)
await arbitrableTransaction.reimburse(1000, {from: payee})
let newPayerBalance = web3.eth.getBalance(payer)
Expand All @@ -65,19 +65,19 @@ contract('ArbitrableTransaction', function (accounts) {
})

it('Should fail if we try to reimburse more', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await expectThrow(arbitrableTransaction.reimburse(1003, {from: payee}))
})

it('Should fail if the payer to it', async () => {
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(0x0, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await expectThrow(arbitrableTransaction.reimburse(1000, {from: payer}))
})

// executeRuling
it('Should reimburse the payer (including arbitration fee) when the arbitrator decides so', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer)
Expand All @@ -88,7 +88,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('Should pay the payee and reimburse him the arbitration fee when the arbitrator decides so', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})

await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
Expand All @@ -100,7 +100,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('It should do nothing if the arbitrator decides so', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
let payeeBalanceBeforePay = web3.eth.getBalance(payee)
Expand All @@ -114,7 +114,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('Should reimburse the payer in case of timeout of the payee', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
increaseTime(timeout + 1)
let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer)
Expand All @@ -126,7 +126,7 @@ contract('ArbitrableTransaction', function (accounts) {

it("Shouldn't work before timeout for the payer", async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await expectThrow(arbitrableTransaction.timeOutByPartyA({from: payer, gasPrice: gasPrice}))
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
increaseTime(1)
Expand All @@ -135,7 +135,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('Should pay and reimburse the payee in case of timeout of the payer', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
increaseTime(timeout + 1)
let payeeBalanceBeforeReimbursment = web3.eth.getBalance(payee)
Expand All @@ -147,7 +147,7 @@ contract('ArbitrableTransaction', function (accounts) {

it("Shouldn't work before timeout for the payee", async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await expectThrow(arbitrableTransaction.timeOutByPartyB({from: payee, gasPrice: gasPrice}))
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
increaseTime(1)
Expand All @@ -157,7 +157,7 @@ contract('ArbitrableTransaction', function (accounts) {
// submitEvidence
it('Should create events when evidence is submitted by the payer', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
let tx = await arbitrableTransaction.submitEvidence('ipfs:/X', {from: payer})
Expand All @@ -169,7 +169,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('Should create events when evidence is submitted by the payee', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
let tx = await arbitrableTransaction.submitEvidence('ipfs:/X', {from: payee})
Expand All @@ -181,7 +181,7 @@ contract('ArbitrableTransaction', function (accounts) {

it('Should fail if someone else try to submit', async () => {
let centralizedArbitrator = await CentralizedArbitrator.new(arbitrationFee, {from: arbitrator})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 2, 0x0, {from: payer, value: amount})
let arbitrableTransaction = await ArbitrableTransaction.new(centralizedArbitrator.address, contractHash, timeout, payee, 0x0, {from: payer, value: amount})
await arbitrableTransaction.payArbitrationFeeByPartyA({from: payer, value: arbitrationFee})
await arbitrableTransaction.payArbitrationFeeByPartyB({from: payee, value: arbitrationFee})
await expectThrow(arbitrableTransaction.submitEvidence('ipfs:/X', {from: other}))
Expand Down
Loading

0 comments on commit 2866689

Please sign in to comment.