# Upgrading Contracts

**URL:** <https://forum.openzeppelin.com/t/upgrading-contracts/17975>\
**Category:** Upgrades\
**Created:** [November 1, 2021, 12:43pm UTC](https://forum.openzeppelin.com/t/upgrading-contracts/17975 "2021-11-01T12:43:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajaroy43](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/rajaroy43/32/6973_2.png) [@rajaroy43](https://forum.openzeppelin.com/u/rajaroy43)\
**Post date:** [November 1, 2021, 12:43pm UTC](https://forum.openzeppelin.com/t/upgrading-contracts/17975/1 "2021-11-01T12:43:13Z")

</div>

Issue: When testing contract with oz-upgrades :

1. 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

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [November 5, 2021, 1:27pm UTC](https://forum.openzeppelin.com/t/upgrading-contracts/17975/2 "2021-11-05T13:27:20Z")

</div>

Please use triple backticks to surround your code in order to get proper formatting.

```
```
code here
```
```

* * *

Your test is using contract `V2` but you haven't included a `V2` contract in the post.
