From 0b1d526e2f0e51c1da65bf621d46cd7f5238ba0d Mon Sep 17 00:00:00 2001 From: Nicolas Wagner Date: Thu, 28 Sep 2017 02:06:54 +0200 Subject: [PATCH 1/2] CS --- code/test/arbitrableTransaction.js | 192 +++++++++++++++++++++-------- 1 file changed, 139 insertions(+), 53 deletions(-) diff --git a/code/test/arbitrableTransaction.js b/code/test/arbitrableTransaction.js index 0d437b01..2c7c3b64 100644 --- a/code/test/arbitrableTransaction.js +++ b/code/test/arbitrableTransaction.js @@ -1,85 +1,171 @@ -const {expectThrow, waitForMined} = require('../helpers/utils'); -const ArbitrableTransaction = artifacts.require("./ArbitrableTransaction.sol") -const CentralizedArbitrator = artifacts.require("./CentralizedArbitrator.sol") - - - +const { expectThrow, waitForMined } = require('../helpers/utils') +const ArbitrableTransaction = artifacts.require('./ArbitrableTransaction.sol') +const CentralizedArbitrator = artifacts.require('./CentralizedArbitrator.sol') contract('ArbitrableTransaction', function(accounts) { - + let payer = accounts[0] - let payee = accounts[1] + let payee = accounts[1] let other = accounts[2] let amount = 1000 let timeout = 100 - + // Constructor - it("Should put 1000 wei in the contract", async () => { - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) - assert.equal(web3.eth.getBalance(arbitrableTransaction.address), 1000, "The contract hasn't received the wei correctly.") - - let a = await arbitrableTransaction.amount() - assert.equal(a.toNumber(), 1000, "The contract hasn't updated its amount correctly.") + it('Should put 1000 wei in the contract', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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() + + assert.equal( + amountSending.toNumber(), + 1000, + 'The contract hasn\'t updated its amount correctly.' + ) }) - + // Pay - it("Should pay the payee", async () => { + it('Should pay the payee', async () => { let initialPayeeBalance = web3.eth.getBalance(payee) - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) - await arbitrableTransaction.pay({from:payer}) + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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") + + assert.equal( + newPayeeBalance.toString(), + initialPayeeBalance.plus(1000).toString(), + 'The payee hasn\'t been paid properly' + ) }) - - it("Should not pay the payee", async () => { + + it('Should not pay the payee', async () => { let initialPayeeBalance = web3.eth.getBalance(payee) - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) - await expectThrow(arbitrableTransaction.pay({from:payee})) + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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", timeout, payee, "0x0",{from:payer,value:amount}) + it('Should reimburse 507 to the payer', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) + let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await arbitrableTransaction.reimburse(507,{from:payee}) + await arbitrableTransaction.reimburse(507,{ from: payee }) let newPayerBalance = web3.eth.getBalance(payer) let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) let newAmount = await arbitrableTransaction.amount() - - - assert.equal(newPayerBalance.toString(), payerBalanceBeforeReimbursment.plus(507).toString(), "The payer has not been reimbursed correctly") - assert.equal(newContractBalance.toNumber(), 493, "Bad amount in the contract") - assert.equal(newAmount.toNumber(), 493, "Amount not updated correctly") + + assert.equal( + newPayerBalance.toString(), + payerBalanceBeforeReimbursment.plus(507).toString(), + 'The payer has not been reimbursed correctly' + ) + assert.equal( + newContractBalance.toNumber(), + 493, 'Bad amount in the contract' + ) + assert.equal(newAmount.toNumber(), 493, 'Amount not updated correctly') }) - it("Should reimburse 1000 (all) to the payer", async () => { - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) + it('Should reimburse 1000 (all) to the payer', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) + let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await arbitrableTransaction.reimburse(1000,{from:payee}) + await arbitrableTransaction.reimburse(1000,{ from:payee }) let newPayerBalance = web3.eth.getBalance(payer) let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) let newAmount = await arbitrableTransaction.amount() - - assert.equal(newPayerBalance.toString(), payerBalanceBeforeReimbursment.plus(1000).toString(), "The payer has not been reimbursed correctly") - assert.equal(newContractBalance.toNumber(), 0, "Bad amount in the contract") - assert.equal(newAmount.toNumber(), 0, "Amount not updated correctly") + + assert.equal( + newPayerBalance.toString(), + payerBalanceBeforeReimbursment.plus(1000).toString(), + 'The payer has not been reimbursed correctly' + ) + assert.equal(newContractBalance.toNumber(), 0, 'Bad amount in the contract') + assert.equal(newAmount.toNumber(), 0, 'Amount not updated correctly') }) - - it("Should fail if we try to reimburse more", async () => { - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) + + it('Should fail if we try to reimburse more', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) + let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await expectThrow(arbitrableTransaction.reimburse(1003,{from:payee})) + await expectThrow(arbitrableTransaction.reimburse(1003, { from: payee })) }) - - it("Should fail if the payer to it", async () => { - let arbitrableTransaction = await ArbitrableTransaction.new("0x0", timeout, payee, "0x0",{from:payer,value:amount}) + + it('Should fail if the payer to it', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await expectThrow(arbitrableTransaction.reimburse(1000,{from:payer})) + await expectThrow(arbitrableTransaction.reimburse(1000, { from: payer } )) }) - + // executeRuling - - - }) - From 58485e38de243cb998a04c9d7bef223d99099d28 Mon Sep 17 00:00:00 2001 From: Nicolas Wagner Date: Thu, 28 Sep 2017 02:12:18 +0200 Subject: [PATCH 2/2] remove tabs --- code/test/arbitrableTransaction.js | 326 ++++++++++++++--------------- 1 file changed, 163 insertions(+), 163 deletions(-) diff --git a/code/test/arbitrableTransaction.js b/code/test/arbitrableTransaction.js index 2c7c3b64..a49291a2 100644 --- a/code/test/arbitrableTransaction.js +++ b/code/test/arbitrableTransaction.js @@ -4,168 +4,168 @@ const CentralizedArbitrator = artifacts.require('./CentralizedArbitrator.sol') contract('ArbitrableTransaction', function(accounts) { - let payer = accounts[0] + let payer = accounts[0] let payee = accounts[1] - let other = accounts[2] - let amount = 1000 - let timeout = 100 - - // Constructor - it('Should put 1000 wei in the contract', async () => { - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - 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() - - assert.equal( - amountSending.toNumber(), - 1000, - 'The contract hasn\'t updated its amount correctly.' - ) - }) - - // Pay - it('Should pay the payee', async () => { - let initialPayeeBalance = web3.eth.getBalance(payee) - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - 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 initialPayeeBalance = web3.eth.getBalance(payee) - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - 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', - 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) - let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) - let newAmount = await arbitrableTransaction.amount() - - assert.equal( - newPayerBalance.toString(), - payerBalanceBeforeReimbursment.plus(507).toString(), - 'The payer has not been reimbursed correctly' - ) - assert.equal( - newContractBalance.toNumber(), - 493, 'Bad amount in the contract' - ) - assert.equal(newAmount.toNumber(), 493, 'Amount not updated correctly') - }) - - it('Should reimburse 1000 (all) to the payer', async () => { - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - 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) - let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) - let newAmount = await arbitrableTransaction.amount() - - assert.equal( - newPayerBalance.toString(), - payerBalanceBeforeReimbursment.plus(1000).toString(), - 'The payer has not been reimbursed correctly' - ) - assert.equal(newContractBalance.toNumber(), 0, 'Bad amount in the contract') - assert.equal(newAmount.toNumber(), 0, 'Amount not updated correctly') - }) - - it('Should fail if we try to reimburse more', async () => { - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - timeout, - payee, - '0x0', - { - from: payer, - value: amount - } - ) - - let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await expectThrow(arbitrableTransaction.reimburse(1003, { from: payee })) - }) - - it('Should fail if the payer to it', async () => { - let arbitrableTransaction = await ArbitrableTransaction.new( - '0x0', - timeout, - payee, - '0x0', - { - from: payer, - value: amount - } - ) - let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) - await expectThrow(arbitrableTransaction.reimburse(1000, { from: payer } )) - }) - - // executeRuling + let other = accounts[2] + let amount = 1000 + let timeout = 100 + + // Constructor + it('Should put 1000 wei in the contract', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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() + + assert.equal( + amountSending.toNumber(), + 1000, + 'The contract hasn\'t updated its amount correctly.' + ) + }) + + // Pay + it('Should pay the payee', async () => { + let initialPayeeBalance = web3.eth.getBalance(payee) + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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 initialPayeeBalance = web3.eth.getBalance(payee) + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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', + 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) + let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) + let newAmount = await arbitrableTransaction.amount() + + assert.equal( + newPayerBalance.toString(), + payerBalanceBeforeReimbursment.plus(507).toString(), + 'The payer has not been reimbursed correctly' + ) + assert.equal( + newContractBalance.toNumber(), + 493, 'Bad amount in the contract' + ) + assert.equal(newAmount.toNumber(), 493, 'Amount not updated correctly') + }) + + it('Should reimburse 1000 (all) to the payer', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + 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) + let newContractBalance = web3.eth.getBalance(arbitrableTransaction.address) + let newAmount = await arbitrableTransaction.amount() + + assert.equal( + newPayerBalance.toString(), + payerBalanceBeforeReimbursment.plus(1000).toString(), + 'The payer has not been reimbursed correctly' + ) + assert.equal(newContractBalance.toNumber(), 0, 'Bad amount in the contract') + assert.equal(newAmount.toNumber(), 0, 'Amount not updated correctly') + }) + + it('Should fail if we try to reimburse more', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) + + let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) + await expectThrow(arbitrableTransaction.reimburse(1003, { from: payee })) + }) + + it('Should fail if the payer to it', async () => { + let arbitrableTransaction = await ArbitrableTransaction.new( + '0x0', + timeout, + payee, + '0x0', + { + from: payer, + value: amount + } + ) + let payerBalanceBeforeReimbursment = web3.eth.getBalance(payer) + await expectThrow(arbitrableTransaction.reimburse(1000, { from: payer } )) + }) + + // executeRuling })