I understand what you're saying (Deploying to Quorum with OpenZeppelin CLI - #4 by abcoathup), I decided to go ahead to try deploying and upgrading a contract on a private ethereum blockchain using the plugin you suggested. I decided to follow this tutorial: OpenZeppelin Upgrades: Step by Step Tutorial for Truffle but as I deploy the upgraded contract via the 4_prepare_upgrade_boxv2.js migration (I skipped the ownership transfer as I just wanted to get the upgrade to work), I get an error saying: "Error: Artifacts are from different compiler runs". Artifcats being from a different compiler runs shouldn't cause an issue? Or, how else am I supposed to deploy a new version of a contract.
Here is a more detailed description of what I did so you can try to reproduce the error:
mkdir mycontract && cd mycontract
npm init -y
npm i --save-dev truffle
npx truffle init
npm i --save-dev @openzeppelin/truffle-upgrades
Create a Box.sol inside the contracts folder, code:
pragma solidity ^0.5.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
contract Box is Initializable{
uint256 private value;
function initialize(uint256 _value) initializer public {
value = _value;
}
function retrieve() public view returns (uint256) {
return value;
}}
Edit truffle-config.js to use solc version: "^0.5.0"
Deploy via truffle to local network -> Everything deploys successfully!
Create new version of contract, BoxV2.sol:
pragma solidity ^0.5.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
contract BoxV2 is Initializable{
uint256 private value;
function initialize(uint256 _value) initializer public {
value = _value;
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
function increment() public {
value = value + 1;
}
}
I am sorry that you are having this issue. Thank you so much for creating reproduceable steps.
I ran through what you described and after running into Error: Artifacts are from different compiler runs I was able to resolve by running npx truffle compile --all.
Would you mind trying that and let me know if you still run into issues.
As an aside, if you want to jump straight to the upgrade you can use upgradeProxy
For completeness, below is the steps I took:
...
3_prepare.js
============
Error: Artifacts are from different compiler runs
Run a full recompilation using `truffle compile --all`
https://zpl.in/upgrades/truffle-recompile-all
...
$ npx truffle compile --all
Compiling your contracts...
===========================
âś” Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/Box.sol
> Compiling ./contracts/BoxV2.sol
> Compiling ./contracts/Migrations.sol
> Compiling @openzeppelin/upgrades/contracts/Initializable.sol
âś” Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /home/abcoathup/projects/forum/alex-dev/build/contracts
> Compiled successfully using:
- solc: 0.5.17+commit.d19bba13.Emscripten.clang
$ npx truffle migrate
Compiling your contracts...
===========================
âś” Fetching solc version list from solc-bin. Attempt #1
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'development'
> Network id: 1600375667969
> Block gas limit: 6721975 (0x6691b7)
3_prepare.js
============
Deploying 'BoxV2'
-----------------
> transaction hash: 0x4c16a1a5e6607fbeeed00c46380c017c47014d8b6d93bfa39fc80bf465e75221
> Blocks: 0 Seconds: 0
> contract address: 0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7
...
I deleted the build/contracts directory as you suggested and ran truffle migrate again but this caused all the migration files to run again (1. migration, 2. first deploy, 3. second deploy). My understanding is that only the latest migration should be re-run. Otherwise, doesn’t this mean that the old contract is deployed again to a new address which the new contract is “linked” to?
EDIT:
Using npx truffle compile -all doesn’t seem to re-compile the contracts as expected. I am getting the message: Everything is up to date…
However, adding the compile all flag to the migrate command seems to do the job. Like so: npx truffle migrate --compile-all.
So, I’m not sure if I did something incorrectly. But what I draw from this is that you should always use the “–compile-all” command when migrating.
Another hint if you're having this error: in my case I realized that running Solidity tests together with the test which calls deployProxy was causing this error.
A simple workaround that worked for me is to run both tests separately.
A convenient way to do this is to specify the following snippet in your package.json.:
"scripts": {
...
"test-sol": "truffle test test/*.sol",
"test-js": "truffle test test/*.js",
"test": "npm run test-sol; npm run test-js"
},