Issue with @opengsn/gsn/dist/GsnTestEnvironment package

Hi,

I have this code in my migration file
const FrontProxyFactory = artifacts.require(“FrontProxyFactory”);
const { GsnTestEnvironment } = require(’@opengsn/gsn/dist/GsnTestEnvironment’ )

module.exports = async (deployer, _network) => {
  let gsnInstance = await GsnTestEnvironment.startGsn('localhost')
  await deployer.deploy(FrontProxyFactory, gsnInstance.deploymentResult.forwarderAddress);
};

I have the “@opengsn/gsn”: “^2.0.1”, installed I am on mac and node version is v12.6.0 am I missing something ?

Frankly, I never used the GsnTestEnvironment with truffle migration (since anyway, it will only be available within this test.
I used it in a before() block in the test.

If you do want to test your migration script, you’d better start GSN beforehand, using gsn start.
From within the test, you can get the forwarder using require(./build/gsn/Forwarder).address

I actually start GSN with run-with-testrpc 'gsn start' , which brings up both ganache and GSN

@drortirosh I tried running node_modules/.bin/gsn start

I went inside .bin in node_modules

and ran gsn start

and I get zsh: command not found: gsn
I follwed the docs
Am I missing something ?

In your project (which has “@opengsn/gsn” in its package.json), you can run it with npx gsn start
which is a nicer form of calling ./node_modules/.bin/gsn

@drortirosh resolved that but test fails here
At the point of transferring eth to paymaster in test ? await paymaster.send(1e17, {from: owner}) reverts

The paymaster that is deployed by GsnTestEnvironment.startGsn() (or gsn start, which uses startGsn internally()) deposit 1eth into the paymaster.
it uses the RelayHub.depositFor() api see here
When sending eth into the paymaster, it calls the same method from its “receive” method here

From command-line, I just did:

gsn start

and from another terminal (in the same folder):

truffle console
truffle(development)> pmAddress = require( './build/gsn/Paymaster').address
truffle(development)> accs = await web3.eth.getAccounts()
truffle(development)> p = await IPaymaster.at(pmAddress)
truffle(development)> p.getRelayHubDeposit().then(x=>x.toString())
'1000000000000000000'
truffle(development)> await web3.eth.sendTransaction( {from:accs[0], to:p.address, value:1e18})
truffle(development)> p.getRelayHubDeposit().then(x=>x.toString())
'2000000000000000000'

Which shows it does work.

@drortirosh yeah I have like gone through the code and I know how it works I get the relay hub address in my truffle test from gsn start and have my own custom paymaster I am able to set the relay hub address but sendTransaction reverts for me I don’t understand why

I don’t really know what’s the problem is.
you can try:

  • try to “fund” the default paymaster. does that work? if so, then it must be something with your paymaster code
  • try to fund the paymaster directly through the hub, using relayHub.depositFor() .