ConditionalEscrow.test.js 1.1 KB

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