Open mdnorman opened 4 years ago
Hi @mdnorman! Apologies for the delay, I am still catching up after vacation over Easter.
I’m sorry that you had this issue.
When I attempted to reproduce, I received a different error (my JavaScript syntax may be incorrect):
// contracts/Box.sol
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
contract Box {
struct Info {
string message;
}
Info private value;
function store(Info memory newValue) public {
value = newValue;
}
function retrieve() public view returns (string memory) {
return value.message;
}
}
const { ZWeb3, Contracts, SimpleProject } = require('@openzeppelin/upgrades');
async function main() {
// Initialize a web3 provider
ZWeb3.initialize("http://localhost:8545");
// Load the contract
const Box = Contracts.getFromLocal('Box');
// Instantiate a project
const myProject = new SimpleProject('MyProject', {
from: await ZWeb3.defaultAccount()
});
const info = {value: 'hello'};
// Create a proxy for the contract
const proxy = await myProject.createProxy(Box, { initMethod: 'store', initArgs: [info] });
}
main();
$ node deploy.js
(node:13059) UnhandledPromiseRejectionWarning: Error: Error: Returned error: VM Exception while processing transaction: revert
at Object.<anonymous> (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/utils/Transactions.js:129:27)
at Generator.throw (<anonymous>)
at rejected (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/utils/Transactions.js:11:65)
(node:13059) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13059) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I also get an issue when using the CLI to deploy:
$ npx oz deploy --verbose
[2020-04-15T06:16:42.582Z@SolidityProjectCompiler.js#call] <started> Nothing to compile, all contracts are up to date.
[2020-04-15T06:16:42.585Z@ProjectFile.js#write] <started> Updated /home/abcoathup/projects/forum/issue1523/.openzeppelin/project.json
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy Box
[2020-04-15T06:16:45.731Z@NetworkController.js#uploadContract] <started> Validating and deploying contract Box
[2020-04-15T06:16:45.731Z@BaseSimpleProject.js#setImplementation] <started> Deploying logic contract for Box
[2020-04-15T06:16:45.828Z@NetworkController.js#uploadContract] <succeeded> Contract Box deployed
[2020-04-15T06:16:45.830Z@NetworkController.js#push] <started> All implementations have been deployed
[2020-04-15T06:16:45.831Z@NetworkFile.js#write] <started> Created .openzeppelin/dev-1586931398623.json
? Call a function to initialize the instance after creating it? Yes
? Select which function store(newValue: (string))
? newValue: (string): hello
[2020-04-15T06:16:51.834Z@ProxyAdmin.js#deploy] <started> Setting everything up to create contract instances
[2020-04-15T06:16:51.911Z@ProxyAdmin.js#deploy] <succeeded> Setting everything up to create contract instances
[2020-04-15T06:16:51.914Z@NetworkFile.js#write] <started> Updated /home/abcoathup/projects/forum/issue1523/.openzeppelin/dev-1586931398623.json
[2020-04-15T06:16:51.915Z@errors.js#call] <started> Error: types/value length mismatch (coderType="tuple", value=["hello"], version=4.0.46)
at Object.throwError (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/errors.js:76:17)
at pack (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:638:16)
at CoderTuple.encode (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:804:16)
at /home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:645:59
at Array.forEach (<anonymous>)
at pack (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:644:12)
at CoderTuple.encode (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:804:16)
at AbiCoder.encode (/home/abcoathup/projects/forum/issue1523/node_modules/ethers/utils/abi-coder.js:941:77)
at encodeParams (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/helpers/encodeCall.js:7:40)
at Object.encodeCall [as default] (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/helpers/encodeCall.js:11:31)
at Object.buildCallData (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/utils/ABIs.js:23:42)
at ProxyAdminProject._getAndLogInitCallData (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/project/BaseSimpleProject.js:200:61)
at ProxyAdminProject.<anonymous> (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/project/BaseSimpleProject.js:87:39)
at Generator.next (<anonymous>)
at fulfilled (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/project/BaseSimpleProject.js:5:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
Thanks so much for reporting it! The project owner will review and triage this issue during the next week.
From your example, one issue is that the hash you're passing in is using the key value
instead of the struct key of message
.
ie
const info = {value: 'hello'};
should be
const info = {message: 'hello'};
Regardless, it looks like you're getting the same error in your deploy.js
example that I did.
I'd given up on oz deploy
for structs because I assumed the command line wouldn't parse the structure properly.
Hi @mdnorman,
Good spot. Updating my deploy.js
example gives the following:
$ node deploy.js
(node:25160) UnhandledPromiseRejectionWarning: Error: Error: Returned error: VM Exception while processing transaction: revert
at Object.<anonymous> (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/utils/Transactions.js:129:27)
at Generator.throw (<anonymous>)
at rejected (/home/abcoathup/projects/forum/issue1523/node_modules/@openzeppelin/upgrades/lib/utils/Transactions.js:11:65)
(node:25160) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25160) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Hi @abcoathup ,
Will struct
be supported in the next release? Another question, when the next version will be released? We'd like to use 0.6.0
. Thanks.
Hi @KimiWu123,
Please see the roadmap for what is coming up next: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1528
Included in this is a plan to move Proxies to OpenZeppelin Contracts (which the latest release uses Solidity 0.6). If you are developing upgradeable contracts OpenZeppelin Contracts Ethereum Package v3.0 has been released (which uses Solidity 0.6)
Supporting structs is unfortunately not a priority for us at the moment.
SimpleProject.createProxy
fails wheninitArgs
contains a hash in order to initialize a struct.For example, my Box contract expects a
BoxInfo
struct ininitializeBox
.However, if I attempt to execute the
initializeBox
as aninitMethod
duringcreateProxy
, it fails duringeth_estimateGas
:deploy.ts
output:ganache-cli
output:If I set gas to 5000000, it fails with a revert:
deploy.ts
output:I am able to create the proxy, and then call
initializeBox
later via web3 with my deploy script, so web3 can handle the conversion of hashes to structs properly. This appears to be specifically an issue with thecreateProxy
call, or one of its underlying eth libraries.This is tangentially related to https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1373. However,
@ts-ignore
doesn't solve the problem because it's not only a typing issue.