-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
155 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
pragma solidity ^0.4.15; | ||
|
||
contract TestArbitrable { | ||
|
||
/* EVENTS */ | ||
event MetaEvidence(uint indexed _metaEvidenceID, string _evidence); | ||
|
||
/** @dev To be emmited when a dispute is created to link the correct meta-evidence to the disputeID | ||
* @param _arbitrator The arbitrator of the contract. | ||
* @param _disputeID ID of the dispute in the Arbitrator contract. | ||
* @param _metaEvidenceID Unique identifier of meta-evidence. | ||
*/ | ||
event Dispute(address indexed _arbitrator, uint indexed _disputeID, uint _metaEvidenceID); | ||
|
||
/** @dev To be raised when evidence are submitted. Should point to the ressource (evidences are not to be stored on chain due to gas considerations). | ||
* @param _arbitrator The arbitrator of the contract. | ||
* @param _disputeID ID of the dispute in the Arbitrator contract. | ||
* @param _party The address of the party submiting the evidence. Note that 0x0 refers to evidence not submitted by any party. | ||
* @param _evidence A URI to the evidence JSON file whose name should be its keccak256 hash followed by .json. | ||
*/ | ||
event Evidence(address indexed _arbitrator, uint indexed _disputeID, address _party, string _evidence); | ||
|
||
event Ruling(address indexed _arbitrator, uint indexed _disputeID, uint _ruling); | ||
|
||
/* EVENT EMITTERS */ | ||
function emitMetaEvidence(uint _metaEvidenceID, string _evidence) public { | ||
emit MetaEvidence(_metaEvidenceID, _evidence); | ||
} | ||
|
||
function emitEvidence(address _arbitrator, uint _disputeID, address _party, string _evidence) public { | ||
emit Evidence(_arbitrator, _disputeID, _party, _evidence); | ||
} | ||
|
||
function emitRuling(address _arbitrator, uint _disputeID, uint _ruling) public { | ||
emit Ruling(_arbitrator, _disputeID, _ruling); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Web3 from 'web3' | ||
|
||
import { _deplyTestArbitrableContract } from '../../utils.js' | ||
import Arbitrable from '../../../src/standards/Arbitrable' | ||
|
||
const provider = new Web3.providers.HttpProvider('http://localhost:8545') | ||
|
||
/** | ||
* Deploy a basic Arbitrable contract | ||
* @param {string[]} arguments - The argument array for the Arbitrable Contract | ||
* @example | ||
* ["0x211f01e59b425253c0a0e9a7bf612605b42ce82c", "0x0"] // [arbitratorAddress, extraData] | ||
* @returns {object} web3 contract object | ||
*/ | ||
|
||
describe('Ruling', () => { | ||
let web3 | ||
let arbitrableInstance | ||
let accounts | ||
|
||
beforeAll(async () => { | ||
web3 = new Web3(provider) | ||
accounts = await web3.eth.getAccounts() | ||
arbitrableInstance = new Arbitrable(provider) | ||
}) | ||
|
||
it('get ruling on dispute', async () => { | ||
// deploy arbitrable contract to test with | ||
const arbitrableContract = await _deplyTestArbitrableContract(provider) | ||
expect(arbitrableContract.options.address).toBeTruthy() | ||
|
||
const arbitratorAddress = '0x0000000000000000000000000000000000000000' | ||
const disputeID = 0 | ||
const ruling = 1 | ||
// emit evidence with evidence = fakeURI | ||
let receipt = await arbitrableContract.methods | ||
.emitRuling(arbitratorAddress, disputeID, ruling) | ||
.send({ | ||
from: accounts[0], | ||
gas: 500000 | ||
}) | ||
expect(receipt.transactionHash).toBeTruthy() | ||
|
||
const _ruling = await arbitrableInstance.getRuling( | ||
arbitrableContract.options.address, | ||
arbitratorAddress, | ||
disputeID | ||
) | ||
expect(_ruling).toEqual(`${ruling}`) | ||
}) | ||
it('get ruling on dispute -- no ruling yet', async () => { | ||
// deploy arbitrable contract to test with | ||
const arbitrableContract = await _deplyTestArbitrableContract(provider) | ||
expect(arbitrableContract.options.address).toBeTruthy() | ||
|
||
const arbitratorAddress = '0x0000000000000000000000000000000000000000' | ||
const disputeID = 0 | ||
|
||
const _ruling = await arbitrableInstance.getRuling( | ||
arbitrableContract.options.address, | ||
arbitratorAddress, | ||
disputeID | ||
) | ||
expect(_ruling).toEqual(null) | ||
}) | ||
it('get ruling on dispute -- multiple rulings same dispute', async () => { | ||
// deploy arbitrable contract to test with | ||
const arbitrableContract = await _deplyTestArbitrableContract(provider) | ||
expect(arbitrableContract.options.address).toBeTruthy() | ||
|
||
const arbitratorAddress = '0x0000000000000000000000000000000000000000' | ||
const disputeID = 0 | ||
const ruling = 1 | ||
// emit evidence with evidence = fakeURI | ||
let receipt = await arbitrableContract.methods | ||
.emitRuling(arbitratorAddress, disputeID, ruling) | ||
.send({ | ||
from: accounts[0], | ||
gas: 500000 | ||
}) | ||
expect(receipt.transactionHash).toBeTruthy() | ||
// emit evidence with evidence = fakeURI | ||
receipt = await arbitrableContract.methods | ||
.emitRuling(arbitratorAddress, disputeID, ruling + 1) | ||
.send({ | ||
from: accounts[0], | ||
gas: 500000 | ||
}) | ||
expect(receipt.transactionHash).toBeTruthy() | ||
|
||
let errored = false | ||
try { | ||
const _ruling = await arbitrableInstance.getRuling( | ||
arbitrableContract.options.address, | ||
arbitratorAddress, | ||
disputeID | ||
) | ||
} catch (err) { | ||
expect(err).toBeTruthy() | ||
errored = true | ||
} | ||
expect(errored).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters