ConditionalEscrow.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. const { ether, expectRevert } = 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 expectRevert(this.escrow.withdraw(payee, { from: owner }),
  22. 'ConditionalEscrow: payee is not allowed to withdraw'
  23. );
  24. });
  25. });
  26. });