Issue: When testing contract with oz-upgrades :
- Trying test for unsafe pattern (as intializing variable directly (not in constructor) as uint256 rad=90))
When upgading ,then It will throw error ,but i'm not able to catch it .
Code to reproduce
Contract V0{
string public hello;
mapping(address=>string) mapString;
function setString(string memory _str)public {
mapString[msg.sender]=_str;
hello=_str;
}
}
Contract V1{
string public hello="roman";
mapping(address=>string) mapString;
function setString(string memory _str)public {
mapString[msg.sender]=_str;
hello=_str;
}
}
in test/test_upgrades.js
const { ethers ,upgrades} = require("hardhat");
describe("Upgrading Contract", async function () {
let proxy;
beforeEach(async () => {
const V0 = await ethers.getContractFactory("V0");
proxy = await upgrades.deployProxy(V0);
});
it("Shound not upgrade if initalizing hello in upgrading implementation contract", async () => {
const V2 = await ethers.getContractFactory("V2");
await expect(upgrades.upgradeProxy(proxy.address ,V2)).to.throw()
});
Environment
Hardhat