PullPayment.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { balanceDifference } = require('../helpers/balanceDifference');
  2. const { ether } = require('../helpers/ether');
  3. require('../helpers/setup');
  4. const PullPaymentMock = artifacts.require('PullPaymentMock');
  5. contract('PullPayment', function ([_, payer, payee1, payee2]) {
  6. const amount = ether(17.0);
  7. beforeEach(async function () {
  8. this.contract = await PullPaymentMock.new({ value: amount });
  9. });
  10. it('can record an async payment correctly', async function () {
  11. await this.contract.callTransfer(payee1, 100, { from: payer });
  12. (await this.contract.payments(payee1)).should.be.bignumber.equal(100);
  13. });
  14. it('can add multiple balances on one account', async function () {
  15. await this.contract.callTransfer(payee1, 200, { from: payer });
  16. await this.contract.callTransfer(payee1, 300, { from: payer });
  17. (await this.contract.payments(payee1)).should.be.bignumber.equal(500);
  18. });
  19. it('can add balances on multiple accounts', async function () {
  20. await this.contract.callTransfer(payee1, 200, { from: payer });
  21. await this.contract.callTransfer(payee2, 300, { from: payer });
  22. (await this.contract.payments(payee1)).should.be.bignumber.equal(200);
  23. (await this.contract.payments(payee2)).should.be.bignumber.equal(300);
  24. });
  25. it('can withdraw payment', async function () {
  26. (await balanceDifference(payee1, async () => {
  27. await this.contract.callTransfer(payee1, amount, { from: payer });
  28. (await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
  29. await this.contract.withdrawPayments(payee1);
  30. })).should.be.bignumber.equal(amount);
  31. (await this.contract.payments(payee1)).should.be.bignumber.equal(0);
  32. });
  33. });