The above answers (How to test/use the GSN network locally) did help in some aspects, but I’m having some issues regarding writing tests
The following is what I have, and works. But I would like something more clean, like https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/GSN/GSNRecipient.test.js#L78 But when I do it like that, it actually makes the sender pays. Could you guys help me please? Thanks
import { should } from 'chai';
import { MyContractInstance } from '../types/truffle-contracts';
import { fromConnection } from "@openzeppelin/network";
const gsn = require('@openzeppelin/gsn-helpers');
const MyContractJSON = require('../build/contracts/MyContract.json');
const MyContract = artifacts.require('./MyContract.sol') as Truffle.Contract<MyContractInstance>;
should();
contract('MyContract', ([payee, sender, newRelayHub, user]) => {
it('get a stamp', async () => {
const myContract = await MyContract.new();
console.log((await web3.eth.getBalance(user)).toString());
await gsn.fundRecipient(web3, { recipient: myContract.address });
const context = await fromConnection('http://localhost:8545', {
gsn: {
dev: true,
}
} as any);
const { lib } = context;
const instance = new lib.eth.Contract(
MyContractJSON.abi as any,
myContract.address,
);
console.log((await web3.eth.getBalance(user)).toString());
const tx = await instance.methods.addStore(5).send({ from: user });
console.log((await web3.eth.getBalance(user)).toString());
console.log(user, tx.events);
});
});