Files
openzeppelin-contracts/test/payment/escrow/ConditionalEscrow.test.js
2019-01-11 16:43:15 -03:00

33 lines
1.0 KiB
JavaScript

const { ether, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
beforeEach(async function () {
this.escrow = await ConditionalEscrowMock.new({ from: owner });
});
context('when withdrawal is allowed', function () {
beforeEach(async function () {
await Promise.all(otherAccounts.map(payee => this.escrow.setAllowed(payee, true)));
});
shouldBehaveLikeEscrow(owner, otherAccounts);
});
context('when withdrawal is disallowed', function () {
const amount = ether('2.3', 'ether');
beforeEach(async function () {
await this.escrow.setAllowed(payee, false);
});
it('reverts on withdrawals', async function () {
await this.escrow.deposit(payee, { from: owner, value: amount });
await shouldFail.reverting(this.escrow.withdraw(payee, { from: owner }));
});
});
});