OpenZeppelin / openzeppelin-sdk

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

Openzeppelin CLI removes solidity library when deploying non-upgradeable version of a contract #1569

Open JUDOKICK opened 4 years ago

JUDOKICK commented 4 years ago

I have a contract that I intend to deploy as upgradeable using the OZ CLI as well as with oz capable factories I've written.

When I deploy the using oz deploy -n development and I choose regular. It correctly deploys the contract and links the library associated.

However, when I run the same deployment using upgradeable OZ decides to remove the library contract but it correctly deploys the contract.

If however, I try to deploy the contract before running a "regular" deployment. It fails with "ContractFactroy deployment failed with error: The data field must be HEX encoded data."

No idea why or how this is the case. But it seems to me that OZ does not know how to deploy Solidity Library contracts if they have never been deployed before on a "regular" contract

I am not sure if this is a known bug or not, but I will try to create a minimalist repo to demonstrate the issue.

abcoathup commented 4 years ago

Hi @X! Unfortunately, I wasn’t able to reproduce this issue with a simple example. I tried the following:

I used a simple library and contract:

A.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

library A {
    function doStuff() public returns (uint256) {
        return 42;
    }
}

B.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "./A.sol";

contract B {

    event Stuff(uint256 value);

    function doStuff() public {
        uint256 value = A.doStuff();
        emit Stuff(value);
    }
}

Deploying B as a regular contract also gets the library deployed and linked

$ npx oz deploy
✓ Compiled contracts with solc 0.6.12 (commit.27d51765)
Compilation warnings:
contracts/A.sol:5:5: Warning: Function state mutability can be restricted to pure
    function doStuff() public returns (uint256) {
    ^ (Relevant source part starts here and spans across multiple lines).

? Choose the kind of deployment regular
? Pick a network development
? Pick a contract to deploy B
✓ A library uploaded
✓ Deployed instance of B
0x5b1869D9A4C187F2EAa108f3062412ecf0526b24

Then deploying the contract as upgradeable the library has already been deployed

$ npx oz deploy
Nothing to compile, all contracts are up to date.
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy B
✓ Contract B 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 0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb
To upgrade this instance run 'oz upgrade'
0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb

If I restart ganache-cli and remove the build directory and deploy the contract as upgradeable the library gets uploaded

$ npx oz deploy
✓ Compiled contracts with solc 0.6.12 (commit.27d51765)
Compilation warnings:
contracts/A.sol:5:5: Warning: Function state mutability can be restricted to pure
    function doStuff() public returns (uint256) {
    ^ (Relevant source part starts here and spans across multiple lines).

? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy B
✓ A library uploaded
✓ Contract B 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 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
To upgrade this instance run 'oz upgrade'
0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B

The doStuff function works as expected:

$ npx oz send-tx
? Pick a network development
? Pick an instance B at 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
? Select which function doStuff()
✓ Transaction successful. Transaction hash: 0xae938fc3a92d96d02292f33f9ebd10452c538203aea153ee83ffc857ad40a176
Events emitted:
 - Stuff(42)

I am running this on the following environment: oz: 2.8.2 node: v10.21.0 npm: 6.14.7 WSL2 on Windows 10