PullPayment.test.js 1.7 KB

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