PullPayment.test.js 1.6 KB

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