All tests now use account names, and dont use accounts[0] (except ERC… (#1137)

* All tests now use account names, and dont use accounts[0] (except ERC721)

* Added account names to some missing contracts.
This commit is contained in:
Nicolás Venturo
2018-08-02 16:55:31 -03:00
committed by GitHub
parent f49721576f
commit 4544df47da
41 changed files with 210 additions and 300 deletions

View File

@ -10,24 +10,21 @@ require('chai')
const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
contract('ConditionalEscrow', function (accounts) {
const owner = accounts[0];
contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
beforeEach(async function () {
this.escrow = await ConditionalEscrowMock.new({ from: owner });
});
context('when withdrawal is allowed', function () {
beforeEach(async function () {
await Promise.all(accounts.map(payee => this.escrow.setAllowed(payee, true)));
await Promise.all(otherAccounts.map(payee => this.escrow.setAllowed(payee, true)));
});
shouldBehaveLikeEscrow(owner, accounts.slice(1));
shouldBehaveLikeEscrow(owner, otherAccounts);
});
context('when withdrawal is disallowed', function () {
const amount = web3.toWei(23.0, 'ether');
const payee = accounts[1];
beforeEach(async function () {
await this.escrow.setAllowed(payee, false);

View File

@ -2,12 +2,10 @@ const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour');
const Escrow = artifacts.require('Escrow');
contract('Escrow', function (accounts) {
const owner = accounts[0];
contract('Escrow', function ([_, owner, ...otherAccounts]) {
beforeEach(async function () {
this.escrow = await Escrow.new({ from: owner });
});
shouldBehaveLikeEscrow(owner, accounts.slice(1));
shouldBehaveLikeEscrow(owner, otherAccounts);
});

View File

@ -8,7 +8,7 @@ require('chai')
const PullPaymentMock = artifacts.require('PullPaymentMock');
contract('PullPayment', function (accounts) {
contract('PullPayment', function ([_, payer, payee1, payee2]) {
const amount = web3.toWei(17.0, 'ether');
beforeEach(async function () {
@ -21,44 +21,43 @@ contract('PullPayment', function (accounts) {
it('can record an async payment correctly', async function () {
const AMOUNT = 100;
await this.contract.callTransfer(accounts[0], AMOUNT);
await this.contract.callTransfer(payee1, AMOUNT, { from: payer });
const paymentsToAccount0 = await this.contract.payments(accounts[0]);
paymentsToAccount0.should.be.bignumber.equal(AMOUNT);
const paymentsToPayee1 = await this.contract.payments(payee1);
paymentsToPayee1.should.be.bignumber.equal(AMOUNT);
});
it('can add multiple balances on one account', async function () {
await this.contract.callTransfer(accounts[0], 200);
await this.contract.callTransfer(accounts[0], 300);
const paymentsToAccount0 = await this.contract.payments(accounts[0]);
paymentsToAccount0.should.be.bignumber.equal(500);
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee1, 300, { from: payer });
const paymentsToPayee1 = await this.contract.payments(payee1);
paymentsToPayee1.should.be.bignumber.equal(500);
});
it('can add balances on multiple accounts', async function () {
await this.contract.callTransfer(accounts[0], 200);
await this.contract.callTransfer(accounts[1], 300);
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee2, 300, { from: payer });
const paymentsToAccount0 = await this.contract.payments(accounts[0]);
paymentsToAccount0.should.be.bignumber.equal(200);
const paymentsToPayee1 = await this.contract.payments(payee1);
paymentsToPayee1.should.be.bignumber.equal(200);
const paymentsToAccount1 = await this.contract.payments(accounts[1]);
paymentsToAccount1.should.be.bignumber.equal(300);
const paymentsToPayee2 = await this.contract.payments(payee2);
paymentsToPayee2.should.be.bignumber.equal(300);
});
it('can withdraw payment', async function () {
const payee = accounts[1];
const initialBalance = await ethGetBalance(payee);
const initialBalance = await ethGetBalance(payee1);
await this.contract.callTransfer(payee, amount);
await this.contract.callTransfer(payee1, amount, { from: payer });
const payment1 = await this.contract.payments(payee);
const payment1 = await this.contract.payments(payee1);
payment1.should.be.bignumber.equal(amount);
await this.contract.withdrawPayments({ from: payee });
const payment2 = await this.contract.payments(payee);
await this.contract.withdrawPayments({ from: payee1 });
const payment2 = await this.contract.payments(payee1);
payment2.should.be.bignumber.equal(0);
const balance = await ethGetBalance(payee);
const balance = await ethGetBalance(payee1);
Math.abs(balance - initialBalance - amount).should.be.lt(1e16);
});
});

View File

@ -11,7 +11,7 @@ require('chai')
const RefundEscrow = artifacts.require('RefundEscrow');
contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
contract('RefundEscrow', function ([_, owner, beneficiary, refundee1, refundee2]) {
const amount = web3.toWei(54.0, 'ether');
const refundees = [refundee1, refundee2];
@ -92,7 +92,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {
it('refunds refundees', async function () {
for (const refundee of [refundee1, refundee2]) {
const refundeeInitialBalance = await ethGetBalance(refundee);
await this.escrow.withdraw(refundee);
await this.escrow.withdraw(refundee, { from: owner });
const refundeeFinalBalance = await ethGetBalance(refundee);
refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount);

View File

@ -10,7 +10,7 @@ const { expectThrow } = require('../helpers/expectThrow');
const EVMThrow = require('../helpers/EVMThrow.js');
const SplitPayment = artifacts.require('SplitPayment');
contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, payer1]) {
contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = web3.toWei(1.0, 'ether');
beforeEach(async function () {