ConditionalEscrow.test.js 1.2 KB

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