Files
openzeppelin-contracts/test/payment/PaymentSplitter.test.js
nikeshnazareth 0dded493a0 Nonfunctional typos #1643 (#1652)
* Add IntelliJ IDE config to .gitignore

* Fix variable name in ERC20 function comments

* Fix typos in Arrays function comment

* Fix typos in ownership test names

* Fix typo in Pausable test name

* Fix grammar in Ownable function comment

* Fix grammar in Crowdsale contract comment

* Fix typo in Counters contract comment

* Fix typo in ERC721Enumerable comment

* Fix typo in ERC721PausedToken test name

* Fix typo in Crowdsale function comment

* Fix typo in IncreasingPriceCrowdsale function comment

* Fix grammar in IncreasingPriceCrowdsale test name

* Fix typo in AllowanceCrowdsale test name

* Fix typo in RefundEscrow function comment

* Fix typo in ERC20Migrator contract comment

* Fix typos in SignatureBouncer comments

* Fix typo in SignedSafeMath test name

* Fix typo in TokenVesting contract comment

* Move Ownable comment from @notice section to @dev

The Ownable contract has a comment explaining that renouncing
ownership will prevent execution of functions with the onlyOwner
modifier.

This commit moves that comment to the @dev section and replaces it
with a description suitable for a generic user.

* Clarify purpose of ERC20 transfer function

* Clarify registration of ERC721Enumerable interface

* Clarify purpose of AllowanceCrowdsale test

* Increase specificity of inheritance comments

FinalizableCrowdsale and RefundableCrowsale both have comments
indicating that they are extensions of the Crowdsale contract.

This commit refines those comments to the most immediate ancestor
( TimedCrowdsale and RefundableCrowdsale respectively )

* Remove unused parameter in PaymentSplitter test

* Rename parameter in SignatureBouncer functions

The SignatureBouncer contract has modifiers to validate the
message sender is authorised to perform an action. They pass
msg.sender to internal functions as the variable `account`, but
the function comments refer to the variable as `sender`

This commit changes the variable name to `sender`

* Clarify comments in SignatureBouncer functions

The SignatureBouncer has comments that use the description
`sender` to refer to the variable `account`.

This commit updates the comments for consistency.

Maintainer Note: this reverts changes in the previous commit,
which renamed the variable `account` instead.
2019-02-28 11:46:13 -03:00

110 lines
4.3 KiB
JavaScript

const { balance, constants, ether, expectEvent, send, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const PaymentSplitter = artifacts.require('PaymentSplitter');
contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = ether('1');
it('rejects an empty set of payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([], []));
});
it('rejects more payees than shares', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, payee2, payee3], [20, 30]));
});
it('rejects more shares than payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, payee2], [20, 30, 40]));
});
it('rejects null payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, ZERO_ADDRESS], [20, 30]));
});
it('rejects zero-valued shares', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, payee2], [20, 0]));
});
it('rejects repeated payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([payee1, payee1], [20, 30]));
});
context('once deployed', function () {
beforeEach(async function () {
this.payees = [payee1, payee2, payee3];
this.shares = [20, 10, 70];
this.contract = await PaymentSplitter.new(this.payees, this.shares);
});
it('should have total shares', async function () {
(await this.contract.totalShares()).should.be.bignumber.equal('100');
});
it('should have payees', async function () {
await Promise.all(this.payees.map(async (payee, index) => {
(await this.contract.payee(index)).should.be.equal(payee);
(await this.contract.released(payee)).should.be.bignumber.equal('0');
}));
});
it('should accept payments', async function () {
await send.ether(owner, this.contract.address, amount);
(await balance.current(this.contract.address)).should.be.bignumber.equal(amount);
});
it('should store shares if address is payee', async function () {
(await this.contract.shares(payee1)).should.be.bignumber.not.equal('0');
});
it('should not store shares if address is not payee', async function () {
(await this.contract.shares(nonpayee1)).should.be.bignumber.equal('0');
});
it('should throw if no funds to claim', async function () {
await shouldFail.reverting(this.contract.release(payee1));
});
it('should throw if non-payee want to claim', async function () {
await send.ether(payer1, this.contract.address, amount);
await shouldFail.reverting(this.contract.release(nonpayee1));
});
it('should distribute funds to payees', async function () {
await send.ether(payer1, this.contract.address, amount);
// receive funds
const initBalance = await balance.current(this.contract.address);
initBalance.should.be.bignumber.equal(amount);
// distribute to payees
const initAmount1 = await balance.current(payee1);
const { logs: logs1 } = await this.contract.release(payee1, { gasPrice: 0 });
const profit1 = (await balance.current(payee1)).sub(initAmount1);
profit1.should.be.bignumber.equal(ether('0.20'));
expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
const initAmount2 = await balance.current(payee2);
const { logs: logs2 } = await this.contract.release(payee2, { gasPrice: 0 });
const profit2 = (await balance.current(payee2)).sub(initAmount2);
profit2.should.be.bignumber.equal(ether('0.10'));
expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
const initAmount3 = await balance.current(payee3);
const { logs: logs3 } = await this.contract.release(payee3, { gasPrice: 0 });
const profit3 = (await balance.current(payee3)).sub(initAmount3);
profit3.should.be.bignumber.equal(ether('0.70'));
expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
// end balance should be zero
(await balance.current(this.contract.address)).should.be.bignumber.equal('0');
// check correct funds released accounting
(await this.contract.totalReleased()).should.be.bignumber.equal(initBalance);
});
});
});