Problem migrating from Truffle to oz-test-environment

Hi,

I’m trying to migrate our project from truffle to openzeppelin libraries for compilation and tests, to see if i can fix this:

And I’m following this https://docs.openzeppelin.com/test-environment/0.1/migrating-from-truffle

but I’m getting this error message running my tests:

Nothing to compile, all contracts are up to date.
Cannot find contract ./storage/EthicHubStorage.sol: Cannot find module './storage/build/contracts/EthicHubStorage.sol.json'
Require stack:
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/@openzeppelin/contract-loader/lib/index.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/@openzeppelin/test-environment/lib/setup-loader.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/@openzeppelin/test-environment/lib/index.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/test/EthicHubArbitrage.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/mocha/lib/mocha.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/mocha/lib/cli/one-and-dones.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/mocha/lib/cli/options.js
- /Users/raul/Development/gitrepos/EthicHub/platform-contracts/node_modules/mocha/bin/mocha

Maybe contract-loader is not traveling well our folder structure in the contracts folder?

Link to the WIP branch here

Thanks!

2 Likes

Hi @ethicraul,

We can configure OpenZeppelin Test Environment artifacts directory, see the following:

Hi @ethicraul,

Were you able to resolve?

Hey @abcoathup

Not yet I’m afraid.

artifactsDir is the default one, so that mus not be the issue.

I’m getting desperate, trying to ditch mocha and use jest to see if it works that way.

Tests work with non upgradeable, non GSN tests until I reached the test file related to a contract that is:

  • Upgradeable
  • GSNRecipient

The test uses TestHelper to create as upgradeable,

const { TestHelper } = require('@openzeppelin/cli')
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades')

Then has methods to interact with it with GSN and without.
This worked with truffle and mocha, but now I get:

DeployError: Failed deployment of dependency @openzeppelin/contracts-ethereum-package with error: Provider not set or invalidError: Provider not set or invalid

  51 |         await mockStorage.setBool(utils.soliditySha3("user", "representative", owner), true)
  52 |         
> 53 |         project = await TestHelper()

Previously to run the test, i followed this instructions to launch a ganache instance and a RelayHub with a bash script:
https://docs.openzeppelin.com/gsn-helpers/0.2/preparing-a-testing-environment

truffle.js used to load a GSNDevProvider for the tests

development: {
            provider: function() {
                return new GSNDevProvider('http://localhost:8545', {
                    txfee: 70,
                    useGSN: false,
                    // The last two accounts defined in test.sh
                    ownerAddress: '0x26be9c03ca7f61ad3d716253ee1edcae22734698',
                    relayerAddress: '0xdc5fd04802ea70f6e27aec12d56716624c98e749',
                })
            },
            network_id: "*" // Match any network id
        },

And it worked, but now it looks like it’s getting ignored. Trying to use a network.js file with same config does nothing.

Maybe is because of this line in the docs?:

By including require('@openzeppelin/test-environment') in your test files, a local ganache-powered blockchain with unlocked accounts will be spun up, and all tools configured to work with it.

So im using 2 ganaches and ZWeb3 does not know which is which? How can I point it to the right one?

The GSN Starter Kit doesn’t actually test anything related to GSN in their contract, nor sets up a test relayer with the bash script.

Could you please provide an example project with the following?:

  • Has an upgradeable contract
  • That contract is GSNRecipient
  • Project uses OZ stuff (test-helpers, gsn-helpers, upgrade, compile, test-environment, gsn)
  • Tests use truffle artifacts
  • Tests with jest test runner
  • The test for the contract uses GSNProvider and TestHelper

Thank you.

1 Like

Hi @ethicraul,

Testing with the GSN requires using an undocumented OpenZeppelin Test Environment feature, which lets you change the provider to a different one.

It is used in OpenZeppelin Contracts test to create a GSNDevProvider connected to the underlying ganache:

setupProvider has now been added to the OpenZeppelin Test Environment documentation:

https://docs.openzeppelin.com/test-environment/0.1/getting-started#setupprovider