You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
5 years ago
|
const { balance, ether } = require('@openzeppelin/test-helpers');
|
||
7 years ago
|
|
||
6 years ago
|
const { expect } = require('chai');
|
||
|
|
||
4 years ago
|
const PullPaymentMock = artifacts.require('PullPaymentMock');
|
||
5 years ago
|
|
||
4 years ago
|
contract('PullPayment', function (accounts) {
|
||
5 years ago
|
const [ payer, payee1, payee2 ] = accounts;
|
||
8 years ago
|
|
||
6 years ago
|
const amount = ether('17');
|
||
7 years ago
|
|
||
7 years ago
|
beforeEach(async function () {
|
||
7 years ago
|
this.contract = await PullPaymentMock.new({ value: amount });
|
||
8 years ago
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('payments', function () {
|
||
|
it('can record an async payment correctly', async function () {
|
||
|
await this.contract.callTransfer(payee1, 100, { from: payer });
|
||
|
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('100');
|
||
|
});
|
||
|
|
||
|
it('can add multiple balances on one account', async function () {
|
||
|
await this.contract.callTransfer(payee1, 200, { from: payer });
|
||
|
await this.contract.callTransfer(payee1, 300, { from: payer });
|
||
|
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('500');
|
||
|
});
|
||
|
|
||
|
it('can add balances on multiple accounts', async function () {
|
||
|
await this.contract.callTransfer(payee1, 200, { from: payer });
|
||
|
await this.contract.callTransfer(payee2, 300, { from: payer });
|
||
|
|
||
|
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('200');
|
||
|
|
||
|
expect(await this.contract.payments(payee2)).to.be.bignumber.equal('300');
|
||
|
});
|
||
8 years ago
|
});
|
||
|
|
||
5 years ago
|
describe('withdrawPayments', function () {
|
||
|
it('can withdraw payment', async function () {
|
||
|
const balanceTracker = await balance.tracker(payee1);
|
||
8 years ago
|
|
||
5 years ago
|
await this.contract.callTransfer(payee1, amount, { from: payer });
|
||
|
expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
|
||
8 years ago
|
|
||
5 years ago
|
await this.contract.withdrawPayments(payee1);
|
||
6 years ago
|
|
||
5 years ago
|
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
|
||
|
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
|
||
|
});
|
||
8 years ago
|
});
|
||
8 years ago
|
});
|