ConditionalEscrow.test.js 1.1 KB

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