Files
openzeppelin-contracts/test/payment/escrow/Escrow.behavior.js
Nicolás Venturo 308a4c9907 Draft EIP 1820 (#1677)
* Add barebones EIP1820 support.

* Update openzeppelin-test-helpers dependency to have ERC1820 support.

* Add tests for ERC1820.

* Improve inline documentation.

* Add changelog entry.

* Update test-helpers, refactor tests to use new helpers.

* Rename ERC1820 to ERC1820Implementer.

* Improve implementer docstring.

* Remove _implementsInterfaceForAddress.

* update openzeppelin-test-helpers to 0.2.0

* Update contracts/drafts/ERC1820Implementer.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Fix how solidity coverage is run to allow for free events.

* Fix coverage testing script.
2019-03-19 15:13:55 -03:00

89 lines
3.3 KiB
JavaScript

const { balance, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
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 balance.current(this.escrow.address)).should.be.bignumber.equal(amount);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
});
it('can accept an empty deposit', async function () {
await this.escrow.deposit(payee1, { from: primary, value: 0 });
});
it('only the primary account can deposit', async function () {
await shouldFail.reverting(this.escrow.deposit(payee1, { from: payee2 }));
});
it('emits a deposited event', async function () {
const { logs } = await this.escrow.deposit(payee1, { from: primary, value: amount });
expectEvent.inLogs(logs, 'Deposited', {
payee: payee1,
weiAmount: amount,
});
});
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.muln(2) });
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(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.muln(2) });
(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.muln(2));
});
});
describe('withdrawals', async function () {
it('can withdraw payments', async function () {
const balanceTracker = await balance.tracker(payee1);
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.withdraw(payee1, { from: primary });
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
(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 () {
await this.escrow.withdraw(payee1, { from: primary });
});
it('only the primary account can withdraw', async function () {
await shouldFail.reverting(this.escrow.withdraw(payee1, { from: payee1 }));
});
it('emits a withdrawn event', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
const { logs } = await this.escrow.withdraw(payee1, { from: primary });
expectEvent.inLogs(logs, 'Withdrawn', {
payee: payee1,
weiAmount: amount,
});
});
});
});
}
module.exports = {
shouldBehaveLikeEscrow,
};