PullPayment.test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { balance, ether } = require('@openzeppelin/test-helpers');
  3. const { expect } = require('chai');
  4. const PullPaymentMock = contract.fromArtifact('PullPaymentMock');
  5. describe('PullPayment', function () {
  6. const [ payer, payee1, payee2 ] = accounts;
  7. const amount = ether('17');
  8. beforeEach(async function () {
  9. this.contract = await PullPaymentMock.new({ value: amount });
  10. });
  11. describe('payments', function () {
  12. it('can record an async payment correctly', async function () {
  13. await this.contract.callTransfer(payee1, 100, { from: payer });
  14. expect(await this.contract.payments(payee1)).to.be.bignumber.equal('100');
  15. });
  16. it('can add multiple balances on one account', async function () {
  17. await this.contract.callTransfer(payee1, 200, { from: payer });
  18. await this.contract.callTransfer(payee1, 300, { from: payer });
  19. expect(await this.contract.payments(payee1)).to.be.bignumber.equal('500');
  20. });
  21. it('can add balances on multiple accounts', async function () {
  22. await this.contract.callTransfer(payee1, 200, { from: payer });
  23. await this.contract.callTransfer(payee2, 300, { from: payer });
  24. expect(await this.contract.payments(payee1)).to.be.bignumber.equal('200');
  25. expect(await this.contract.payments(payee2)).to.be.bignumber.equal('300');
  26. });
  27. });
  28. describe('withdrawPayments', function () {
  29. it('can withdraw payment', async function () {
  30. const balanceTracker = await balance.tracker(payee1);
  31. await this.contract.callTransfer(payee1, amount, { from: payer });
  32. expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
  33. await this.contract.withdrawPayments(payee1);
  34. expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
  35. expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
  36. });
  37. });
  38. });