ConditionalEscrow.test.js 1.2 KB

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