Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)

* Now compiling using truffle 5.

* Migrated some test files, missing BN scientific notation usage.

* Now using BN time values.

* Migrate ERC20 tests.

* Migrate all ERC20 tests.

* Migrate utils, payment and ownership tests.

* All tests save ERC721 migrated.

* Migrated ERC721 tests.

* Fix lint errors.

* Delete old test helpers.

* Fix remaining crowdsale tests.

* Fix signature bouncer tests.

* Update how constants is used.

* Compile script pre-removes the build dir.

* Fix SafeMath tests.

* Revert "Compile script pre-removes the build dir."

This reverts commit 247e745113.

* Fix linter errors.

* Upgrade openzeppelin-test-helpers dependency.

* Update openzeppelin-test-helpers dependency.

* Define math constants globally.

* Remove unnecessary ether unit.

* Roll back reduced ether amounts in tests.

* Remove unnecessary toNumber conversions.

* Delete compile script.

* Fixed failing test.
This commit is contained in:
Nicolás Venturo
2019-01-14 19:11:55 -03:00
committed by GitHub
parent 089f14aa06
commit 3e82db2f6f
86 changed files with 834 additions and 2626 deletions

View File

@ -1,10 +1,6 @@
const { ether, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const shouldFail = require('../../helpers/shouldFail');
const { ether } = require('../../helpers/ether');
require('../../helpers/setup');
const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
@ -21,7 +17,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
});
context('when withdrawal is disallowed', function () {
const amount = ether(23.0);
const amount = ether('23');
beforeEach(async function () {
await this.escrow.setAllowed(payee, false);

View File

@ -1,20 +1,14 @@
const expectEvent = require('../../helpers/expectEvent');
const shouldFail = require('../../helpers/shouldFail');
const { ethGetBalance } = require('../../helpers/web3');
const { balanceDifference } = require('../../helpers/balanceDifference');
const { ether } = require('../../helpers/ether');
require('../../helpers/setup');
const { balance, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
const amount = ether(42.0);
const amount = ether('42');
describe('as an escrow', function () {
describe('deposits', function () {
it('can accept a single deposit', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
});
@ -37,34 +31,34 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
it('can add multiple deposits on a single account', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.deposit(payee1, { from: primary, value: amount * 2 });
await this.escrow.deposit(payee1, { from: primary, value: amount.muln(2) });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount * 3);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount.muln(3));
});
it('can track deposits to multiple accounts', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.deposit(payee2, { from: primary, value: amount * 2 });
await this.escrow.deposit(payee2, { from: primary, value: amount.muln(2) });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
(await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount * 2);
(await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount.muln(2));
});
});
describe('withdrawals', async function () {
it('can withdraw payments', async function () {
(await balanceDifference(payee1, async () => {
(await balance.difference(payee1, async () => {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.withdraw(payee1, { from: primary });
})).should.be.bignumber.equal(amount);
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(0);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(0);
(await balance.current(this.escrow.address)).should.be.bignumber.equal('0');
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal('0');
});
it('can do an empty withdrawal', async function () {

View File

@ -1,3 +1,4 @@
require('openzeppelin-test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const Escrow = artifacts.require('Escrow');

View File

@ -1,15 +1,10 @@
const shouldFail = require('../../helpers/shouldFail');
const expectEvent = require('../../helpers/expectEvent');
const { balanceDifference } = require('../../helpers/balanceDifference');
const { ether } = require('../../helpers/ether');
const { ZERO_ADDRESS } = require('../../helpers/constants');
require('../../helpers/setup');
const { balance, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const RefundEscrow = artifacts.require('RefundEscrow');
contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) {
const amount = ether(54.0);
const amount = ether('54');
const refundees = [refundee1, refundee2];
it('requires a non-null beneficiary', async function () {
@ -26,7 +21,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
context('active state', function () {
it('has beneficiary and state', async function () {
(await this.escrow.beneficiary()).should.be.equal(beneficiary);
(await this.escrow.state()).should.be.bignumber.equal(0);
(await this.escrow.state()).should.be.bignumber.equal('0');
});
it('accepts deposits', async function () {
@ -69,9 +64,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('allows beneficiary withdrawal', async function () {
(await balanceDifference(beneficiary, () =>
(await balance.difference(beneficiary, () =>
this.escrow.beneficiaryWithdraw()
)).should.be.bignumber.equal(amount * refundees.length);
)).should.be.bignumber.equal(amount.muln(refundees.length));
});
it('prevents entering the refund state', async function () {
@ -103,7 +98,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
it('refunds refundees', async function () {
for (const refundee of [refundee1, refundee2]) {
(await balanceDifference(refundee, () =>
(await balance.difference(refundee, () =>
this.escrow.withdraw(refundee, { from: primary }))
).should.be.bignumber.equal(amount);
}