OpenZeppelin / openzeppelin-upgrades

Plugins for Hardhat and Foundry to deploy and manage upgradeable contracts on Ethereum.
MIT License
627 stars 268 forks source link

Cannot apply migration because smart-contract uses enums and a struct #368

Closed brg-andrew closed 3 years ago

brg-andrew commented 3 years ago

Hello. I encountered the issue below when wrote migration to upgrade my smart-contract to a new version. My smart-contract includes 2 enums and a struct.

Here is the error I am seeing:

Error: An unexpected condition occurred. Please report this at https://zpl.in/upgrades/report at Object.assert (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/utils/assert.ts:7:11) at StorageLayoutComparator.uncachedGetTypeChange (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:189:9) at StorageLayoutComparator.getTypeChange (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:110:27) at StorageLayoutComparator.getFieldChange (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:82:29) at /home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:71:63 at change (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/levenshtein.ts:77:20) at buildMatrix (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/levenshtein.ts:46:29) at Object.levenshtein (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/levenshtein.ts:16:18) at StorageLayoutComparator.layoutLevenshtein (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:71:17) at StorageLayoutComparator.compareLayouts (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/compare.ts:63:47) at Object.assertStorageUpgradeSafe (/home/user/Projects/node_modules/@openzeppelin/upgrades-core/src/storage/index.ts:20:29) at Object.deployImpl (/home/user/Projects/node_modules/@openzeppelin/truffle-upgrades/src/utils/deploy-impl.ts:39:5) at upgradeProxy (/home/user/Projects/node_modules/@openzeppelin/truffle-upgrades/src/upgrade-proxy.ts:30:20) at module.exports (/home/user/Projects/migrations/2_new_version.js:7:3)

Here are the versions I am using: openzeppelin/truffle-upgrades: 1.7.0 openzeppelin/contracts-upgradeable: 3.4.1

I know, that there was a flag unsafeAllowCustomTypes in earlier versions, but adding it to my migration did not help. How can I resolve this issue?

brg-andrew commented 3 years ago

Looks like the problem is not about enum, but because my contract uses mapping form contract to int256. As far as I understand, such mapping is allowed at least by solidity 0.7.6. So the question is which version of @openzeppelin/truffle-upgrades should be used?

frangio commented 3 years ago

Thank you for reporting @brg-andrew. This is a bug, let me take a look and fix it now.

frangio commented 3 years ago

Fixed in https://github.com/OpenZeppelin/openzeppelin-upgrades/commit/c8ae9d026fc52128e4938a6040f94688794e47fa and released in @openzeppelin/upgrades-core@1.7.6.

brg-andrew commented 3 years ago

Many thanks, @frangio !