PullPayment.test.js 2.1 KB

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