Test upgradeable contract with OpenZeppelin Test Environment

Hi everyone,
I'll ask my question here too, because it's related.
I have an upgradeable contract, and I want to test it using test-environment. My test looks like this

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

const { expect } = require("chai");
require("chai").should();

const Contract = contract.fromArtifact("Executor");
let c: any = null
describe('contract', async () => {
    beforeEach(async () => {
        c = await deployProxy(Contract, {initializer: "__init_Executor" });
    })
    
    it("should execute contract", async () => {
      //whatever
    });
})

My package.json

{
  "name": "te",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "ts-mocha --exit --recursive test/**.test.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@openzeppelin/contracts": "^3.3.0-solc-0.7",
    "@openzeppelin/contracts-upgradeable": "^3.3.0",
    "@openzeppelin/test-environment": "^0.1.9",
    "@openzeppelin/truffle-upgrades": "^1.3.1",
    "@truffle/hdwallet-provider": "^1.2.0",
    "@types/chai": "^4.2.14",
    "@types/mocha": "^8.2.0",
    "chai": "^4.2.0",
    "dotenv": "^8.2.0",
    "mocha": "^8.2.1",
    "solc": "^0.7.5",
    "truffle": "^5.1.58",
    "ts-mocha": "^8.0.0",
    "ts-node": "^9.1.1",
    "typescript": "^4.1.3"
  }
}

Whatever I do, I also get this

Error: Global Truffle config not found: Truffle >=5.1.35 is required. Truffle exec not yet supported

I don't have truffle installed globally (only got npm and npx) and I have no idea what to do to make it work. Please help :slight_smile:

2 Likes

Hi @pibu,

Welcome to the community :wave:

I was able to reproduce the issue by using the tests from OpenZeppelin Upgrades: Step by Step Tutorial for Truffle and converting to OpenZeppelin Test Environment: https://docs.openzeppelin.com/test-environment/0.1/migrating-from-truffle

I will need to come back to you whether testing with OpenZeppelin Test Environment is supported or if we need to use Truffle Test when using Upgrades Plugins.

Hi @pibu, Unfortunately the plugin only works with a Truffle project that uses Truffle to compile and run tests.

1 Like

Hey @frangio, will it ever work with OpenZeppelin Test Environment ?

1 Like

Not for the time being. As we’re currently working on improvements to OpenZeppelin Contracts we won’t be able to develop this for a while.

1 Like

A post was split to a new topic: Getting admin instance in Truffle Upgrades

Hi, I also get this error when using "await erc1967.getBeaconAddress(proxyAddress)" inside a truffle script when calling e.g. "truffle exec scripts/someJavascript.js". Is this issue, because in the Javascript I do not use "deployer.then...." ? I use "truffle": "^5.5.22" and "ganache": "^7.3.2" in my package.json.
any feedback would be highly appreciated. Thanks!

Hi @Sven_Seydler, the Truffle Upgrades plugin is only supported with Truffle migrations or tests. It is not currently supported with truffle exec (there is an issue open).

See https://docs.openzeppelin.com/upgrades-plugins/1.x/truffle-upgrades for some examples of its usage.

1 Like