ConditionalEscrow.test.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. const { ether, shouldFail } = require('openzeppelin-test-helpers');
  2. const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
  3. const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
  4. contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
  5. beforeEach(async function () {
  6. this.escrow = await ConditionalEscrowMock.new({ from: owner });
  7. });
  8. context('when withdrawal is allowed', function () {
  9. beforeEach(async function () {
  10. await Promise.all(otherAccounts.map(payee => this.escrow.setAllowed(payee, true)));
  11. });
  12. shouldBehaveLikeEscrow(owner, otherAccounts);
  13. });
  14. context('when withdrawal is disallowed', function () {
  15. const amount = ether('23');
  16. beforeEach(async function () {
  17. await this.escrow.setAllowed(payee, false);
  18. });
  19. it('reverts on withdrawals', async function () {
  20. await this.escrow.deposit(payee, { from: owner, value: amount });
  21. await shouldFail.reverting(this.escrow.withdraw(payee, { from: owner }));
  22. });
  23. });
  24. });