I’m updating our test files to use the OZ test environment but am getting this error: Please call setProvider() first before calling new(). I’ve read through all the documentation and can’t manage to setProvider()
Environment
Truffle v5.1.11 (core: 5.1.11)
Solidity v0.5.16 (solc-js)
Node v13.7.0
Web3.js v1.2.1
"@openzeppelin/test-environment": "^0.1.4",
"@openzeppelin/test-helpers": "^0.5.4",
Details
I’m updating one of our projects to use the new test-environment repo. We are using Chainlink in the project so I’m using the Chainlink contracts for testing purposes. I’ve made all the updates necessary to use the OpenZeppelin test-environment, and I am running into this error:
Error: LinkToken error: Please call setProvider() first before calling new().
It’s specific to the LinkToken Chainlink contract. In the Chainlink documentation, they say:
" For ease of use with testing, if the environment variable NODE_ENV is set, the imported truffle contract abstraction will automatically set its provider to web3.currentProvider , avoiding the need to perform a setProvider call before using it during your truffle tests."
So all I had to do was run NODE_ENV=true truffle test and I wouldn’t get the setProvider error. Running NODE_ENV=true npm test with the OZ test environment doesn’t work though and I get the error.
I tried adding the setupProvider function to the test-environment.config file but I’m not exactly sure how to use it.
Code to reproduce
const { LinkToken } = require('@chainlink/contracts/truffle/v0.4/LinkToken');
const { Oracle } = require('@chainlink/contracts/truffle/v0.4/Oracle');
// set up Chainlink
link = await LinkToken.new({ from: creator });
oc = await Oracle.new(link.address, { from: creator });
await oc.setFulfillmentPermission(oracleNode, true, { from: creator });
I’ve tried calling setProvider() before the LinkToken.new() function bc that is where the error occurs, but nothing that i’ve tried has worked. I’m not exactly sure what the issue is…whether I simply can’t use the OZ test environment for testing Chainlink contracts?
Any advice?
Thanks for your help, that worked!