ConditionalEscrow.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { ether, expectRevert } = require('@openzeppelin/test-helpers');
  3. const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
  4. const ConditionalEscrowMock = contract.fromArtifact('ConditionalEscrowMock');
  5. describe('ConditionalEscrow', function () {
  6. const [ owner, payee, ...otherAccounts ] = accounts;
  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');
  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 expectRevert(this.escrow.withdraw(payee, { from: owner }),
  24. 'ConditionalEscrow: payee is not allowed to withdraw'
  25. );
  26. });
  27. });
  28. });