OpenZeppelin / openzeppelin-sdk

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

Upgradeable contract - providing parameters to a method in the upgraded contract #1588

Closed stefek99 closed 3 years ago

stefek99 commented 3 years ago

INITIAL

// contracts/Counter.sol
pragma solidity ^0.5.0;

contract Counter {
    uint256 public value;

    function increase() public {
      value++;
    }
}

npx oz deploy --network development --kind upgradeable Counter

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increase

npx oz upgrade --network development

- Compiling contracts with solc 0.5.17 (commit.d19bba13)
- Compiled contracts with solc 0.5.17 (commit.d19bba13)
- Compiled contracts with solc 0.5.17 (commit.d19bba13)
- Validating and deploying contract Counter
- Compiled contracts with solc 0.5.17 (commit.d19bba13)
- Contract Counter deployed
- Compiled contracts with solc 0.5.17 (commit.d19bba13)
- Contract Counter deployed
- All implementations have been deployed
- The package name, contract name, or address to upgrade must be provided, or set the `all` flag to upgrade all contracts in the application.

UPGRADED

// contracts/Counter.sol
pragma solidity ^0.5.0;

contract Counter {
    uint256 public value;

    function increase() public {
      value++;
    }

    function increaseBy(uint256 amount) public {
        value += amount;
    }
}

Using 17 the number

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increaseBy --args 17

- Calling: 'increaseBy' with:
- amount (uint256): "17"
- Error while trying to send transaction to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Error: Returned error: VM Exception while processing transaction: revert

Noticed "17" in the ouput, trying with string

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increaseBy --args "17"

- Calling: 'increaseBy' with:
- amount (uint256): "17"
- Error while trying to send transaction to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Error: Returned error: VM Exception while processing transaction: revert

Checking with a different method name, checking if the error is generic

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increaseByNONEXISTENT --args 17

- Could not find method increaseByNONEXISTENT with 1 arguments in contract Counter

That was the confusing part. I thought that due to a different error, the contract was properly deployed.

Trying ABI-encoded version

https://abi.hashex.org/

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increaseBy --args 0000000000000000000000000000000000000000000000000000000000000011

- Calling: 'increaseBy' with:
- amount (uint256): "0000000000000000000000000000000000000000000000000000000000000011"
- Error while trying to send transaction to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Error: Returned error: VM Exception while processing transaction: revert

How do I call the upgraded method?

The package name, contract name, or address to upgrade must be provided, or set the all flag to upgrade all contracts in the application.

Norticed that thing above...

npx oz upgrade --network development --all

- Nothing to compile, all contracts are up to date.
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Instance upgraded at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Transaction receipt: 0xdbdd6d34236c5c811fb784f903a2297e223b37589def7f6fd01ad2db0a642cd9
- Upgrading instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
- Nothing to compile, all contracts are up to date.
- All implementations are up to date
- Instance upgraded at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601. Transaction receipt: 0xdbdd6d34236c5c811fb784f903a2297e223b37589def7f6fd01ad2db0a642cd9
- Instance at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 upgraded

Hurray

npx oz send-tx --network development --to 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 --method increaseBy --args 17

- Calling: 'increaseBy' with:
- amount (uint256): "17"
- Transaction successful. Transaction hash: 0xfd66349a8239825566eff11ff6fde7fa06b3d3948d21dea77b6db83815b813e4