`useGSN` doesn't work in OpenZeppelin Test Environment tests

I’m using OZ test environment example, but useGSN doesn’t work. Funds are still debited from the sender.

    const { accounts, contract, web3 } = require("@openzeppelin/test-environment");

    const gsn = require("@openzeppelin/gsn-helpers");

    const Counter = contract.fromArtifact("Counter");
    const Recipient = contract.fromArtifact("Recipient");
    const IRelayHub = contract.fromArtifact("IRelayHub");

    describe("GSNRecipient", function() {
      const [sender] = accounts;

      before(async function() {
        await gsn.deployRelayHub(web3);
        await gsn.runRelayer(web3, { quiet: true });
      });

      beforeEach(async function() {
        this.counter = await Counter.new();
        this.recipient = await Recipient.new(this.counter.address);
      });

      context("when called directly", function() {
        it("setOwner", async function() {
          const senderPreBalance = await web3.eth.getBalance(sender);
          console.log("senderPreBalance: ", senderPreBalance.toString());

          await this.recipient.setOwner(this.counter.address, {
            from: sender,
          });

          const senderPostBalance = await web3.eth.getBalance(sender);
          console.log("senderPostBalance: ", senderPostBalance.toString());
        });
      });

      context("when relay-called", function() {
        beforeEach(async function() {
          await gsn.fundRecipient(web3, { recipient: this.recipient.address });
          this.relayHub = await IRelayHub.at(
            "0xD216153c06E857cD7f72665E0aF1d7D82172F494"
          );
        });

        it("setOwner", async function() {
          const recipientPreBalance = await this.relayHub.balanceOf(
            this.recipient.address
          );

          console.log("recipientPreBalance: ", recipientPreBalance.toString());

          const senderPreBalance = await web3.eth.getBalance(sender);
          console.log("senderPreBalance: ", senderPreBalance.toString());

          await this.recipient.setOwner(this.counter.address, {
            from: sender,
            useGSN: true,
          });

          const senderPostBalance = await web3.eth.getBalance(sender);
          console.log("senderPostBalance: ", senderPostBalance.toString());

          const recipientPostBalance = await this.relayHub.balanceOf(
            this.recipient.address
          );

          console.log("recipientPostBalance: ", recipientPostBalance.toString());
        });
      });
    });

Output:

 GSNRecipient
Starting relayer
/Users/user/Library/Caches/gsn-nodejs/gsn-relay-v0.2.1
 -Port 8090
 -Url localhost:8090
 -GasPricePercent 0
 -Workdir /var/folders/bw/w2nzhsf11qg8f3s1vnbyy0zr0000gn/T/tmp-89624Wr6XbCVieWtF
 -DevMode
    `when called directly`
2020/07/07 21:54:04 RelayHttpServer.go:44: RelayHttpServer starting. version: 0.4.1
2020/07/07 21:54:04 RelayHttpServer.go:211: Using RelayHub address: 0x537F27a04470242ff6b2c3ad247A05248d0d27CE
2020/07/07 21:54:04 RelayHttpServer.go:212: Using workdir: /var/folders/bw/w2nzhsf11qg8f3s1vnbyy0zr0000gn/T/tmp-89624Wr6XbCVieWtF
2020/07/07 21:54:04 RelayHttpServer.go:214: Using dev mode
2020/07/07 21:54:04 RelayHttpServer.go:222: Constructing relay server in url  localhost:8090
2020/07/07 21:54:04 utils.go:40: ks accounts len 0
`senderPreBalance:  100000000000000000000`
`senderPostBalance:  99999448880000000000`
      ✓ setOwner (105ms)
    `when relay-called`
2020/07/07 21:54:05 utils.go:66: key extracted. addr: 0xbf8069F88A62a0B5d859997f7aEd433389D279dF
2020/07/07 21:54:05 RelayHttpServer.go:224: relay server address:  0xbf8069F88A62a0B5d859997f7aEd433389D279dF
2020/07/07 21:54:05 RelayHttpServer.go:62: RelayHttpServer started. Listening on port:  8090
2020/07/07 21:54:05 RelayHttpServer.go:65: listen tcp :8090: bind: address already in use
`recipientPreBalance:  1000000000000000000`
`senderPreBalance:  99999448880000000000`
`senderPostBalance:  99998897760000000000`
`recipientPostBalance:  1000000000000000000`
      ✓ setOwner (181ms)


  2 passing (2s)

Solution: I didn’t use the environment settings.

1 Like

Welcome to the community @ilyakmet! Feel free to introduce yourself in the Introduce yourself here! - #241 by abcoathup topic.

I'm glad to see you were able to solve this by yourself, I'm referencing the solution in here and marking it as solved so it's easier for people to find.

1 Like

Hi @ilyakmet,

Welcome to the community :wave:

Regards the GSN:

  • GSNv1 : Use in production now (though you may want to run your own relayer on mainnet to ensure availability).
  • GSNv2 : In development at OpenGSN.org.

See Doubling down on security for more details.

Assuming you are just getting started and depending on your development roadmap, you could look at the upcoming improvements in GSNv2. I suggest joining the OpenGSN telegram to get the latest news on GSNv2 development and timescales.