GSNRecipient.test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const { balance, ether, expectRevert } = require('openzeppelin-test-helpers');
  2. const gsn = require('@openzeppelin/gsn-helpers');
  3. const { expect } = require('chai');
  4. const GSNRecipientMock = artifacts.require('GSNRecipientMock');
  5. contract('GSNRecipient', function ([_, payee]) {
  6. beforeEach(async function () {
  7. this.recipient = await GSNRecipientMock.new();
  8. });
  9. it('returns the RelayHub address address', async function () {
  10. expect(await this.recipient.getHubAddr()).to.equal('0xD216153c06E857cD7f72665E0aF1d7D82172F494');
  11. });
  12. it('returns the compatible RelayHub version', async function () {
  13. expect(await this.recipient.relayHubVersion()).to.equal('1.0.0');
  14. });
  15. context('with deposited funds', async function () {
  16. const amount = ether('1');
  17. beforeEach(async function () {
  18. await gsn.fundRecipient(web3, { recipient: this.recipient.address, amount });
  19. });
  20. it('funds can be withdrawn', async function () {
  21. const balanceTracker = await balance.tracker(payee);
  22. await this.recipient.withdrawDeposits(amount, payee);
  23. expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
  24. });
  25. it('partial funds can be withdrawn', async function () {
  26. const balanceTracker = await balance.tracker(payee);
  27. await this.recipient.withdrawDeposits(amount.divn(2), payee);
  28. expect(await balanceTracker.delta()).to.be.bignumber.equal(amount.divn(2));
  29. });
  30. it('reverts on overwithdrawals', async function () {
  31. await expectRevert(this.recipient.withdrawDeposits(amount.addn(1), payee), 'insufficient funds');
  32. });
  33. });
  34. });