PullPayment.test.js 1.8 KB

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