ERC721GSNRecipientMock.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { constants, expectEvent } = require('openzeppelin-test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const gsn = require('@openzeppelin/gsn-helpers');
  4. const { fixSignature } = require('../helpers/sign');
  5. const { utils: { toBN } } = require('web3');
  6. const ERC721GSNRecipientMock = artifacts.require('ERC721GSNRecipientMock');
  7. contract('ERC721GSNRecipient (integration)', function ([_, signer, sender]) {
  8. const tokenId = '42';
  9. beforeEach(async function () {
  10. this.token = await ERC721GSNRecipientMock.new(signer);
  11. });
  12. async function testMintToken (token, from, tokenId, options = {}) {
  13. const { tx } = await token.mint(tokenId, { from, ...options });
  14. await expectEvent.inTransaction(tx, ERC721GSNRecipientMock, 'Transfer', { from: ZERO_ADDRESS, to: from, tokenId });
  15. }
  16. context('when called directly', function () {
  17. it('sender can mint tokens', async function () {
  18. await testMintToken(this.token, sender, tokenId);
  19. });
  20. });
  21. context('when relay-called', function () {
  22. beforeEach(async function () {
  23. await gsn.fundRecipient(web3, { recipient: this.token.address });
  24. });
  25. it('sender can mint tokens', async function () {
  26. const approveFunction = async (data) =>
  27. fixSignature(
  28. await web3.eth.sign(
  29. web3.utils.soliditySha3(
  30. // eslint-disable-next-line max-len
  31. data.relayerAddress, data.from, data.encodedFunctionCall, toBN(data.txFee), toBN(data.gasPrice), toBN(data.gas), toBN(data.nonce), data.relayHubAddress, this.token.address
  32. ), signer
  33. )
  34. );
  35. await testMintToken(this.token, sender, tokenId, { useGSN: true, approveFunction });
  36. });
  37. });
  38. });