ConditionalEscrow.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour');
  2. const { expectThrow } = require('../helpers/expectThrow');
  3. const { EVMRevert } = require('../helpers/EVMRevert');
  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 = web3.toWei(23.0, 'ether');
  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 expectThrow(this.escrow.withdraw(payee, { from: owner }), EVMRevert);
  27. });
  28. });
  29. });