dmdv
December 29, 2020, 8:48pm
1
I’ve been using @openzeppelin/test-environment
to test upgradeable contracts.
Basic examples just show how to initialize a contract without constructor parameter or with
function initialize()
without parameters.
How to test a contract where initialize function has arguments?
describe('MyContract', function () {
it('deployer is owner', async function () {
const myContract = await MyContract.new(*other arguments*{ from: owner });
expect(await myContract.owner()).to.equal(owner);
});
});
1 Like
How is MyContract
upgradeable? Are you using the truffle-upgrades
package ?
You don’t initialize an upgradeable contract with new
but with deployProxy
(or by calling initialize
explicitly)
// migrations/NN_deploy_upgradeable_box.js
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const Box = artifacts.require('Box');
module.exports = async function (deployer) {
const instance = await deployProxy(Box, [42], { deployer });
console.log('Deployed', instance.address);
};
1 Like
HI @dmdv ,
To test upgradeable contracts we can use Upgrades Plugins for Truffle or Hardhat. The Upgrades Plugin for Truffle only works with a Truffle project that uses Truffle to compile and run tests.