OpenZeppelin / openzeppelin-sdk

OpenZeppelin SDK repository for CLI and upgrades.js. No longer actively developed.
MIT License
432 stars 200 forks source link

Unable to deploy upgradeable contract non-interactively #1526

Closed osnwt closed 4 years ago

osnwt commented 4 years ago

This works:

oz deploy --no-interactive --network development --kind regular MyContract

This doesn't:

oz deploy --no-interactive --network development --kind upgradeable MyContract

The question about init has no command-line option: ? Call a function to initialize the instance after creating it? (Y/n)

In addition, -k option has broken help (see below).

Usage: deploy [options] [contract] [arguments...]

deploy a contract instance

Options:
  --skip-compile           use existing compilation artifacts
  -k, --kind <kind>        the kind of deployment ([object Object], [object Object], [object Object])
  -n, --network <network>  network to use
  --timeout <timeout>      timeout in seconds for each transaction (default: 750)
  -f, --from <address>     sender for the contract creation transaction
  --migrate-manifest       enable automatic migration of manifest format
  --no-interactive         disable interactive prompts
  -h, --help               output usage information

How to deploy upgradeable contract from script?

nventuro commented 4 years ago

This is an issue about the OpenZeppelin CLI, I'm transferring it to the SDK repo.

frangio commented 4 years ago

Hi @osnwt. Can you share some more details about the contract you're trying to deploy? Does it have an initializer function with arguments?

osnwt commented 4 years ago

It doesn't matter. I tried simplest test contract which does not have/use the initialize function. I can deploy it interactively as both regular and upgradeable. From script using '--no-interactive' I have an error (see logs below). The only difference with interactive deployment is that it asks about Init function (do I want to run it and which one if yes). There is no command line equivalent to this question in deploy command. So if I want to run initializer (and which one), or don't want, I have no way to specify this in the script.

Interactive deployment:

+ yarn -s run oz:deploy --network development --kind regular DocumentManager
Nothing to compile, all contracts are up to date.
✓ Deployed instance of DocumentManager
0xa8CCc62837Fc861c4c0a10264f7191871F8dad07

+ yarn -s run oz:deploy --network development --kind upgradeable DocumentManager
Nothing to compile, all contracts are up to date.
✓ Contract DocumentManager deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? No
✓ Setting everything up to create contract instances
✓ Instance created at 0x2D2EcEEB9cb1dE1A7E5a853159f0F48fF0D3ca86
To upgrade this instance run 'oz upgrade'
0x2D2EcEEB9cb1dE1A7E5a853159f0F48fF0D3ca86

Non-interactive deployment:

+ yarn -s run oz:deploy --no-interactive --network development --kind regular DocumentManager
Nothing to compile, all contracts are up to date.
✓ Deployed instance of DocumentManager
0x587c8347892386e8cbF58F16e7559aBB021429F0

+ yarn -s run oz:deploy --no-interactive --network development --kind upgradeable DocumentManager
Nothing to compile, all contracts are up to date.
Contract DocumentManager is not deployed to dev-1337.
osnwt commented 4 years ago

I think you should provide some options to deploy command like:

--init-function fn
--init-args ...

If no --init-function specified, it does not run. If it's given, then it uses optional --init-args as arguments.

frangio commented 4 years ago

Unforunately this is a different issue that has nothing to do with --init. Please see https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1518#issuecomment-608036695 for the explanation and workaround.

deploy is able to call initialize on an upgradeable contract. The syntax is the same as that for constructor arguments on regular deploys. You should include the initializer arguments as extra arguments to oz deploy, after the contract name. There is no need for an --args flag. As for --init-function, deploy currently will assume that the function is called initialize as this is the case in general, and it's not possible to customize it at the moment. If you have an initializer function with a different name please open an issue requesting the feature!

frangio commented 4 years ago

Closing this issue in favor of #1518.