Escrows (#1014)
* Added basic Escrow * PullPayment now uses an Escrow, removing all trust from the contract * Abstracted the Escrow tests to a behaviour * Added ConditionalEscrow * Added RefundableEscrow. * RefundableCrowdsale now uses a RefundEscrow, removed RefundVault. * Renaming after code review. * Added log test helper. * Now allowing empty deposits and withdrawals. * Style fixes. * Minor review comments. * Add Deposited and Withdrawn events, removed Refunded * The base Escrow is now Ownable, users of it (owners) must provide methods to access it.
This commit is contained in:
committed by
Francisco Giordano
parent
c2ad8c3f57
commit
8fd072cf8e
@ -1,71 +1,62 @@
|
||||
var PullPaymentMock = artifacts.require('PullPaymentMock');
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
require('chai')
|
||||
.use(require('chai-bignumber')(BigNumber))
|
||||
.should();
|
||||
|
||||
const PullPaymentMock = artifacts.require('PullPaymentMock');
|
||||
|
||||
contract('PullPayment', function (accounts) {
|
||||
let ppce;
|
||||
let amount = 17 * 1e18;
|
||||
const amount = web3.toWei(17.0, 'ether');
|
||||
|
||||
beforeEach(async function () {
|
||||
ppce = await PullPaymentMock.new({ value: amount });
|
||||
this.contract = await PullPaymentMock.new({ value: amount });
|
||||
});
|
||||
|
||||
it('can\'t call asyncSend externally', async function () {
|
||||
assert.isUndefined(ppce.asyncSend);
|
||||
assert.isUndefined(this.contract.asyncSend);
|
||||
});
|
||||
|
||||
it('can record an async payment correctly', async function () {
|
||||
let AMOUNT = 100;
|
||||
await ppce.callSend(accounts[0], AMOUNT);
|
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
const AMOUNT = 100;
|
||||
await this.contract.callTransfer(accounts[0], AMOUNT);
|
||||
|
||||
assert.equal(totalPayments, AMOUNT);
|
||||
assert.equal(paymentsToAccount0, AMOUNT);
|
||||
const paymentsToAccount0 = await this.contract.payments(accounts[0]);
|
||||
paymentsToAccount0.should.be.bignumber.equal(AMOUNT);
|
||||
});
|
||||
|
||||
it('can add multiple balances on one account', async function () {
|
||||
await ppce.callSend(accounts[0], 200);
|
||||
await ppce.callSend(accounts[0], 300);
|
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
|
||||
assert.equal(totalPayments, 500);
|
||||
assert.equal(paymentsToAccount0, 500);
|
||||
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);
|
||||
});
|
||||
|
||||
it('can add balances on multiple accounts', async function () {
|
||||
await ppce.callSend(accounts[0], 200);
|
||||
await ppce.callSend(accounts[1], 300);
|
||||
await this.contract.callTransfer(accounts[0], 200);
|
||||
await this.contract.callTransfer(accounts[1], 300);
|
||||
|
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||
assert.equal(paymentsToAccount0, 200);
|
||||
const paymentsToAccount0 = await this.contract.payments(accounts[0]);
|
||||
paymentsToAccount0.should.be.bignumber.equal(200);
|
||||
|
||||
let paymentsToAccount1 = await ppce.payments(accounts[1]);
|
||||
assert.equal(paymentsToAccount1, 300);
|
||||
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
assert.equal(totalPayments, 500);
|
||||
const paymentsToAccount1 = await this.contract.payments(accounts[1]);
|
||||
paymentsToAccount1.should.be.bignumber.equal(300);
|
||||
});
|
||||
|
||||
it('can withdraw payment', async function () {
|
||||
let payee = accounts[1];
|
||||
let initialBalance = web3.eth.getBalance(payee);
|
||||
const payee = accounts[1];
|
||||
const initialBalance = web3.eth.getBalance(payee);
|
||||
|
||||
await ppce.callSend(payee, amount);
|
||||
await this.contract.callTransfer(payee, amount);
|
||||
|
||||
let payment1 = await ppce.payments(payee);
|
||||
assert.equal(payment1, amount);
|
||||
const payment1 = await this.contract.payments(payee);
|
||||
payment1.should.be.bignumber.equal(amount);
|
||||
|
||||
let totalPayments = await ppce.totalPayments();
|
||||
assert.equal(totalPayments, amount);
|
||||
await this.contract.withdrawPayments({ from: payee });
|
||||
const payment2 = await this.contract.payments(payee);
|
||||
payment2.should.be.bignumber.equal(0);
|
||||
|
||||
await ppce.withdrawPayments({ from: payee });
|
||||
let payment2 = await ppce.payments(payee);
|
||||
assert.equal(payment2, 0);
|
||||
|
||||
totalPayments = await ppce.totalPayments();
|
||||
assert.equal(totalPayments, 0);
|
||||
|
||||
let balance = web3.eth.getBalance(payee);
|
||||
assert(Math.abs(balance - initialBalance - amount) < 1e16);
|
||||
const balance = web3.eth.getBalance(payee);
|
||||
Math.abs(balance - initialBalance - amount).should.be.lt(1e16);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user