ConditionalEscrow.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 (accounts) {
  10. const owner = accounts[0];
  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(accounts.map(payee => this.escrow.setAllowed(payee, true)));
  17. });
  18. shouldBehaveLikeEscrow(owner, accounts.slice(1));
  19. });
  20. context('when withdrawal is disallowed', function () {
  21. const amount = web3.toWei(23.0, 'ether');
  22. const payee = accounts[1];
  23. beforeEach(async function () {
  24. await this.escrow.setAllowed(payee, false);
  25. });
  26. it('reverts on withdrawals', async function () {
  27. await this.escrow.deposit(payee, { from: owner, value: amount });
  28. await expectThrow(this.escrow.withdraw(payee, { from: owner }), EVMRevert);
  29. });
  30. });
  31. });