|
@@ -4,6 +4,7 @@ const { ZERO_ADDRESS } = constants;
|
|
|
const { expect } = require('chai');
|
|
|
|
|
|
const PaymentSplitter = artifacts.require('PaymentSplitter');
|
|
|
+const Token = artifacts.require('ERC20Mock');
|
|
|
|
|
|
contract('PaymentSplitter', function (accounts) {
|
|
|
const [ owner, payee1, payee2, payee3, nonpayee1, payer1 ] = accounts;
|
|
@@ -50,6 +51,7 @@ contract('PaymentSplitter', function (accounts) {
|
|
|
this.shares = [20, 10, 70];
|
|
|
|
|
|
this.contract = await PaymentSplitter.new(this.payees, this.shares);
|
|
|
+ this.token = await Token.new('MyToken', 'MT', owner, ether('1000'));
|
|
|
});
|
|
|
|
|
|
it('has total shares', async function () {
|
|
@@ -63,10 +65,18 @@ contract('PaymentSplitter', function (accounts) {
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
- it('accepts payments', async function () {
|
|
|
- await send.ether(owner, this.contract.address, amount);
|
|
|
+ describe('accepts payments', async function () {
|
|
|
+ it('Ether', async function () {
|
|
|
+ await send.ether(owner, this.contract.address, amount);
|
|
|
|
|
|
- expect(await balance.current(this.contract.address)).to.be.bignumber.equal(amount);
|
|
|
+ expect(await balance.current(this.contract.address)).to.be.bignumber.equal(amount);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Token', async function () {
|
|
|
+ await this.token.transfer(this.contract.address, amount, { from: owner });
|
|
|
+
|
|
|
+ expect(await this.token.balanceOf(this.contract.address)).to.be.bignumber.equal(amount);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('shares', async function () {
|
|
@@ -80,51 +90,107 @@ contract('PaymentSplitter', function (accounts) {
|
|
|
});
|
|
|
|
|
|
describe('release', async function () {
|
|
|
- it('reverts if no funds to claim', async function () {
|
|
|
- await expectRevert(this.contract.release(payee1),
|
|
|
- 'PaymentSplitter: account is not due payment',
|
|
|
- );
|
|
|
+ describe('Ether', async function () {
|
|
|
+ it('reverts if no funds to claim', async function () {
|
|
|
+ await expectRevert(this.contract.release(payee1),
|
|
|
+ 'PaymentSplitter: account is not due payment',
|
|
|
+ );
|
|
|
+ });
|
|
|
+ it('reverts if non-payee want to claim', async function () {
|
|
|
+ await send.ether(payer1, this.contract.address, amount);
|
|
|
+ await expectRevert(this.contract.release(nonpayee1),
|
|
|
+ 'PaymentSplitter: account has no shares',
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|
|
|
- it('reverts if non-payee want to claim', async function () {
|
|
|
- await send.ether(payer1, this.contract.address, amount);
|
|
|
- await expectRevert(this.contract.release(nonpayee1),
|
|
|
- 'PaymentSplitter: account has no shares',
|
|
|
- );
|
|
|
+
|
|
|
+ describe('Token', async function () {
|
|
|
+ it('reverts if no funds to claim', async function () {
|
|
|
+ await expectRevert(this.contract.release(this.token.address, payee1),
|
|
|
+ 'PaymentSplitter: account is not due payment',
|
|
|
+ );
|
|
|
+ });
|
|
|
+ it('reverts if non-payee want to claim', async function () {
|
|
|
+ await this.token.transfer(this.contract.address, amount, { from: owner });
|
|
|
+ await expectRevert(this.contract.release(this.token.address, nonpayee1),
|
|
|
+ 'PaymentSplitter: account has no shares',
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- it('distributes funds to payees', async function () {
|
|
|
- await send.ether(payer1, this.contract.address, amount);
|
|
|
+ describe('distributes funds to payees', async function () {
|
|
|
+ it('Ether', async function () {
|
|
|
+ await send.ether(payer1, this.contract.address, amount);
|
|
|
+
|
|
|
+ // receive funds
|
|
|
+ const initBalance = await balance.current(this.contract.address);
|
|
|
+ expect(initBalance).to.be.bignumber.equal(amount);
|
|
|
+
|
|
|
+ // distribute to payees
|
|
|
|
|
|
- // receive funds
|
|
|
- const initBalance = await balance.current(this.contract.address);
|
|
|
- expect(initBalance).to.be.bignumber.equal(amount);
|
|
|
+ const tracker1 = await balance.tracker(payee1);
|
|
|
+ const { logs: logs1 } = await this.contract.release(payee1);
|
|
|
+ const profit1 = await tracker1.delta();
|
|
|
+ expect(profit1).to.be.bignumber.equal(ether('0.20'));
|
|
|
+ expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
|
|
|
|
|
|
- // distribute to payees
|
|
|
+ const tracker2 = await balance.tracker(payee2);
|
|
|
+ const { logs: logs2 } = await this.contract.release(payee2);
|
|
|
+ const profit2 = await tracker2.delta();
|
|
|
+ expect(profit2).to.be.bignumber.equal(ether('0.10'));
|
|
|
+ expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
|
|
|
|
|
|
- const tracker1 = await balance.tracker(payee1);
|
|
|
- const { logs: logs1 } = await this.contract.release(payee1);
|
|
|
- const profit1 = await tracker1.delta();
|
|
|
- expect(profit1).to.be.bignumber.equal(ether('0.20'));
|
|
|
- expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
|
|
|
+ const tracker3 = await balance.tracker(payee3);
|
|
|
+ const { logs: logs3 } = await this.contract.release(payee3);
|
|
|
+ const profit3 = await tracker3.delta();
|
|
|
+ expect(profit3).to.be.bignumber.equal(ether('0.70'));
|
|
|
+ expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
|
|
|
|
|
|
- const tracker2 = await balance.tracker(payee2);
|
|
|
- const { logs: logs2 } = await this.contract.release(payee2);
|
|
|
- const profit2 = await tracker2.delta();
|
|
|
- expect(profit2).to.be.bignumber.equal(ether('0.10'));
|
|
|
- expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
|
|
|
+ // end balance should be zero
|
|
|
+ expect(await balance.current(this.contract.address)).to.be.bignumber.equal('0');
|
|
|
|
|
|
- const tracker3 = await balance.tracker(payee3);
|
|
|
- const { logs: logs3 } = await this.contract.release(payee3);
|
|
|
- const profit3 = await tracker3.delta();
|
|
|
- expect(profit3).to.be.bignumber.equal(ether('0.70'));
|
|
|
- expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
|
|
|
+ // check correct funds released accounting
|
|
|
+ expect(await this.contract.totalReleased()).to.be.bignumber.equal(initBalance);
|
|
|
+ });
|
|
|
|
|
|
- // end balance should be zero
|
|
|
- expect(await balance.current(this.contract.address)).to.be.bignumber.equal('0');
|
|
|
+ it('Token', async function () {
|
|
|
+ expect(await this.token.balanceOf(payee1)).to.be.bignumber.equal('0');
|
|
|
+ expect(await this.token.balanceOf(payee2)).to.be.bignumber.equal('0');
|
|
|
+ expect(await this.token.balanceOf(payee3)).to.be.bignumber.equal('0');
|
|
|
|
|
|
- // check correct funds released accounting
|
|
|
- expect(await this.contract.totalReleased()).to.be.bignumber.equal(initBalance);
|
|
|
+ await this.token.transfer(this.contract.address, amount, { from: owner });
|
|
|
+
|
|
|
+ expectEvent(
|
|
|
+ await this.contract.release(this.token.address, payee1),
|
|
|
+ 'ERC20PaymentReleased',
|
|
|
+ { token: this.token.address, to: payee1, amount: ether('0.20') },
|
|
|
+ );
|
|
|
+
|
|
|
+ await this.token.transfer(this.contract.address, amount, { from: owner });
|
|
|
+
|
|
|
+ expectEvent(
|
|
|
+ await this.contract.release(this.token.address, payee1),
|
|
|
+ 'ERC20PaymentReleased',
|
|
|
+ { token: this.token.address, to: payee1, amount: ether('0.20') },
|
|
|
+ );
|
|
|
+
|
|
|
+ expectEvent(
|
|
|
+ await this.contract.release(this.token.address, payee2),
|
|
|
+ 'ERC20PaymentReleased',
|
|
|
+ { token: this.token.address, to: payee2, amount: ether('0.20') },
|
|
|
+ );
|
|
|
+
|
|
|
+ expectEvent(
|
|
|
+ await this.contract.release(this.token.address, payee3),
|
|
|
+ 'ERC20PaymentReleased',
|
|
|
+ { token: this.token.address, to: payee3, amount: ether('1.40') },
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(await this.token.balanceOf(payee1)).to.be.bignumber.equal(ether('0.40'));
|
|
|
+ expect(await this.token.balanceOf(payee2)).to.be.bignumber.equal(ether('0.20'));
|
|
|
+ expect(await this.token.balanceOf(payee3)).to.be.bignumber.equal(ether('1.40'));
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
});
|