|
| 1 | +import Web3 from 'web3' |
| 2 | + |
| 3 | +import { _deplyTestArbitrableContract } from '../../utils.js' |
| 4 | +import Arbitrable from '../../../src/standards/Arbitrable' |
| 5 | + |
| 6 | +const provider = new Web3.providers.HttpProvider('http://localhost:8545') |
| 7 | + |
| 8 | +/** |
| 9 | + * Deploy a basic Arbitrable contract |
| 10 | + * @param {string[]} arguments - The argument array for the Arbitrable Contract |
| 11 | + * @example |
| 12 | + * ["0x211f01e59b425253c0a0e9a7bf612605b42ce82c", "0x0"] // [arbitratorAddress, extraData] |
| 13 | + * @returns {object} web3 contract object |
| 14 | + */ |
| 15 | + |
| 16 | +describe('Ruling', () => { |
| 17 | + let web3 |
| 18 | + let arbitrableInstance |
| 19 | + let accounts |
| 20 | + |
| 21 | + beforeAll(async () => { |
| 22 | + web3 = new Web3(provider) |
| 23 | + accounts = await web3.eth.getAccounts() |
| 24 | + arbitrableInstance = new Arbitrable(provider) |
| 25 | + }) |
| 26 | + |
| 27 | + it('get ruling on dispute', async () => { |
| 28 | + // deploy arbitrable contract to test with |
| 29 | + const arbitrableContract = await _deplyTestArbitrableContract(provider) |
| 30 | + expect(arbitrableContract.options.address).toBeTruthy() |
| 31 | + |
| 32 | + const arbitratorAddress = '0x0000000000000000000000000000000000000000' |
| 33 | + const disputeID = 0 |
| 34 | + const ruling = 1 |
| 35 | + // emit evidence with evidence = fakeURI |
| 36 | + let receipt = await arbitrableContract.methods |
| 37 | + .emitRuling(arbitratorAddress, disputeID, ruling) |
| 38 | + .send({ |
| 39 | + from: accounts[0], |
| 40 | + gas: 500000 |
| 41 | + }) |
| 42 | + expect(receipt.transactionHash).toBeTruthy() |
| 43 | + |
| 44 | + const _ruling = await arbitrableInstance.getRuling( |
| 45 | + arbitrableContract.options.address, |
| 46 | + arbitratorAddress, |
| 47 | + disputeID |
| 48 | + ) |
| 49 | + expect(_ruling).toEqual(`${ruling}`) |
| 50 | + }) |
| 51 | + it('get ruling on dispute -- no ruling yet', async () => { |
| 52 | + // deploy arbitrable contract to test with |
| 53 | + const arbitrableContract = await _deplyTestArbitrableContract(provider) |
| 54 | + expect(arbitrableContract.options.address).toBeTruthy() |
| 55 | + |
| 56 | + const arbitratorAddress = '0x0000000000000000000000000000000000000000' |
| 57 | + const disputeID = 0 |
| 58 | + |
| 59 | + const _ruling = await arbitrableInstance.getRuling( |
| 60 | + arbitrableContract.options.address, |
| 61 | + arbitratorAddress, |
| 62 | + disputeID |
| 63 | + ) |
| 64 | + expect(_ruling).toEqual(null) |
| 65 | + }) |
| 66 | + it('get ruling on dispute -- multiple rulings same dispute', async () => { |
| 67 | + // deploy arbitrable contract to test with |
| 68 | + const arbitrableContract = await _deplyTestArbitrableContract(provider) |
| 69 | + expect(arbitrableContract.options.address).toBeTruthy() |
| 70 | + |
| 71 | + const arbitratorAddress = '0x0000000000000000000000000000000000000000' |
| 72 | + const disputeID = 0 |
| 73 | + const ruling = 1 |
| 74 | + // emit evidence with evidence = fakeURI |
| 75 | + let receipt = await arbitrableContract.methods |
| 76 | + .emitRuling(arbitratorAddress, disputeID, ruling) |
| 77 | + .send({ |
| 78 | + from: accounts[0], |
| 79 | + gas: 500000 |
| 80 | + }) |
| 81 | + expect(receipt.transactionHash).toBeTruthy() |
| 82 | + // emit evidence with evidence = fakeURI |
| 83 | + receipt = await arbitrableContract.methods |
| 84 | + .emitRuling(arbitratorAddress, disputeID, ruling + 1) |
| 85 | + .send({ |
| 86 | + from: accounts[0], |
| 87 | + gas: 500000 |
| 88 | + }) |
| 89 | + expect(receipt.transactionHash).toBeTruthy() |
| 90 | + |
| 91 | + let errored = false |
| 92 | + try { |
| 93 | + const _ruling = await arbitrableInstance.getRuling( |
| 94 | + arbitrableContract.options.address, |
| 95 | + arbitratorAddress, |
| 96 | + disputeID |
| 97 | + ) |
| 98 | + } catch (err) { |
| 99 | + expect(err).toBeTruthy() |
| 100 | + errored = true |
| 101 | + } |
| 102 | + expect(errored).toBeTruthy() |
| 103 | + }) |
| 104 | +}) |
0 commit comments