ConditionalEscrow.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import shouldBehaveLikeEscrow from './Escrow.behaviour';
  2. import EVMRevert from '../helpers/EVMRevert';
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
  8. contract('ConditionalEscrow', function (accounts) {
  9. const owner = accounts[0];
  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(accounts.map(payee => this.escrow.setAllowed(payee, true)));
  16. });
  17. shouldBehaveLikeEscrow(owner, accounts.slice(1));
  18. });
  19. context('when withdrawal is disallowed', function () {
  20. const amount = web3.toWei(23.0, 'ether');
  21. const payee = accounts[1];
  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 this.escrow.withdraw(payee, { from: owner }).should.be.rejectedWith(EVMRevert);
  28. });
  29. });
  30. });