Truffle upgrade test errors with Cannot read property 'send' of undefined

:computer: Environment

"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/truffle-upgrades": "^1.5.0",
"truffle": "^5.1.67",
"@openzeppelin/contracts-upgradeable": "^3.4.0"


I am following truffle upgrade docs And Truffle upgrades’s deployProxy works on migration but not work on test. Which raised ‘send’ of undefined and by looking at the code seems issue with the undefined provider and when using in migration it passes in deployer so it works. Therefore I think the doc need to update that it only works on migration.

TypeError: Cannot read property 'send' of undefined
      at Object.wrapProvider (node_modules/@openzeppelin/truffle-upgrades/src/wrap-provider.ts:9:39)

:1234: Code to reproduce

1 Like

Hi @leckylao,

Can you share exactly what version of Truffle you’re using? Run npx truffle version and share the output.

deployProxy is meant to work on tests, so the documentation is correct and this is an unexpected error that we need to debug and fix.

1 Like

╰─$ npx truffle version
Truffle v5.1.67 (core: 5.1.67)
Solidity - v0.6.12 (solc-js)
Node v14.15.1
Web3.js v1.2.9

Can I ask how could deployProxy works by pass in deployer and in test don’t need to pass in deployer and can still works? The error seems like can’t find the web3 provider.

1 Like

There is a global config variable that contains the provider. We use that.

Are you running your tests in a special network? Can you share the networks part of your Truffle config? Thank you!

1 Like

Thank you @frangio for the reply.

  networks: {
    development: {
      host: "",
      port: 8545,
      gasPrice: 30000000000,
      network_id: "*",
      skipDryRun: true

But the issue is deployProxy does work in migration but not test and they use the same network. The only difference I can see is in test missing the deployer which I don’t know how it can still work in test.

1 Like

The deployer is only needed in migrations for the deployments to register with the migration deployer (so that they show in the console, for example). In tests it can take the provider from the global environment.

So you run your tests against a local node, right? Are you using Ganache for that?

1 Like

Yes, using Ganache. So how does it take provider from the global? I can see there’s provider in other network but not in local/development. Maybe that’s the issue? So I need to define provider?

1 Like

No, the provider is created by Truffle based on your settings. If you want to test this, try to run console.log(config.provider) in a test.

I will take a look in a short while.

1 Like

I’ve tried using your network settings and I can’t reproduce this issue. Using the plugin in tests works fine for me.

Can you create a minimal repository that reproduces this error so I can take a look at that?

1 Like

Thank you @frangio for your help. I’ve just recall that the localhost is actually hardhat and the reason I need to use deployProxy in test is because need to write it in fixture instead of migration in hardhat then countered this issue. As it doesn’t work so I have changed back to use truffle. However today I revisited with the hardhat fixture setup now the deployProxy works! Using config.provider can return provider value. Don’t know why this time it can find provider so weird. But I am glad can use Hardhat with deployProxy in fixture! So much faster!

1 Like

OK, I’ve found out how to reproduce. Was confusing when using both truffle and hardhat. So it was caused by running npx hardhat test instead of npx truffle test when running with hardhat node.

So my current set up is using hardhat node as local network and using deployProxy on truffle fixture then run test with truffle test. This way the same test file can work on both hardhat with fixture and ganache with migration.

1 Like

Right, if you will be using hardhat test you need to use @openzeppelin/hardhat-upgrades instead of @openzeppelin/truffle-upgrades.

But using the hardhat node together with Truffle tests is fine. Glad you got it working.

1 Like