Trouble migrating from truffle to openzeppelin's test environment. Doesn't seem to be connecting to ganache

Hello. I’m trying to take advantage of test-helpers, but I cannot seem to figure this out. Everything “just worked” with truffle and ganache. It doesn’t seem like test-environment is even talking to ganache, it just fails my tests telling my that the contract is not deployed to the “detected network”

I’ve tried test-helpers config to define the provider as my ganache url, but I still see no activity from ganache console like I do with truffle, and I still get the same error.

Why won’t test-environment talk to ganache?

:1234: Code to reproduce

require('@openzeppelin/test-helpers/configure')({
provider: 'http://127.0.0.1:7545',
singletons: {
abstraction: 'truffle'
}
});

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

const Wrapped = contract.fromArtifact("Wrapped")

describe("Wrapped", async function () {
const [sender, receiver] = accounts;
it("should connect to my deployed contract", async () => {
const wrapped = await Wrapped.deployed()
});

Returns:
Error: Contract has not been deployed to detected network (network/artifact mismatch)

Extra info: When connecting “time” test-helper and querying time.latestblock, I’m getting words: [ 0 ] in the BN response. It should be the blocknumber reported by ganache, but it is not.

:computer: Environment

Truffle, ganache, openzeppelin test-environment with mocha chai.

Solved

I had to manually define a new web3 instance with my ganache url, then pass that as the provider, instead of using the url as the provider.

Sorry. I marked this solved too soon. I’m getting the correct block number now, and seeing activity in Ganache, BUT still getting same error
Error: Contract has not been deployed to detected network (network/artifact mismatch)

Even though I’ve deployed my contracts before running tests.

Edit: It seems I’ve updated web3, but not the test-environment provider itself. Openzeppelin is still using some simulated provider, and not my web3 instance.

Update: Solved in a roundabout way, by editing setup-provider in test-environment to override for my own web3 instance, and then manually telling my tests what address each contract is located at. Seems like I’m still missing something, but this was enough to get my back to work.

Test Environment spins up its own Ganache instance. If you want to connect to your own Ganache instance, you should use something else.

I’ll probably just keep with the current workaround to force test environment to use my ganache. Unless there is a much simpler way to get test-helpers into truffle environment.

test-helpers can be used on its own with Truffle. You don’t need test-environment for that.

Well don’t I feel silly.

I swear I had tried that and it was still using a weird instance, though now it makes sense that I may just not have had it configured.

1 Like

Can somebody add a more detailed description with a code snippet of the changes? I'm potentially facing a similar error as outlined in stackexchange and looking forward to try out the solution.

@frangio Can you provide a good source where the different instances of ganache are explained in more detailed and potentially some approaches on its configuration are shown? Looking forward your help!

@ndrslmpk What is the problem you're facing exactly? The StackExchange question looks unrelated to me.