wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.2k stars 296 forks source link

`execute` fails while `ethers.getContract(...).fun` does work #252

Open ClementWalter opened 2 years ago

ClementWalter commented 2 years ago

Describe the bug

In a deploy script, after deployment, I am trying to execute a given function of the contract. One of these functions does not work when called with execute while using ethers it does work.

To Reproduce Steps to reproduce the behavior:

  1. Get ChainRunnersBaseRenderer contract from https://etherscan.io/address/0xfdac77881ff861ff76a83cc43a1be3c317c6a1cc#code
  2. Execute this deployment script
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const { deployments, getNamedAccounts, ethers } = hre;
  const { deploy, execute } = deployments;

  const { deployer } = await getNamedAccounts();

  await deploy("ChainRunnersBaseRenderer", {
    from: deployer,
    log: true,
  });
  const layers = [
    {
      name: "trait0",
      hexString: "0x23455763454530",
      layerIndex: 0,
      itemIndex: 0,
    },
    {
      name: "trait1",
      hexString: "0x23455763454530",
      layerIndex: 1,
      itemIndex: 1,
    },
    {
      name: "trait2",
      hexString: "0x23455763454530",
      layerIndex: 2,
      itemIndex: 2,
    },
  ];

  // This call works
  await execute(
    "ChainRunnersBaseRenderer",
    { from: deployer, log: true },
    "setLayers",
    layers
  );

  // This call to getLayer works with ethers.js
  const renderer = await ethers.getContract("ChainRunnersBaseRenderer");
  const layer00 = await renderer.getLayer(0, 0);
  console.log(layer00);

  // Same call to getLayer fails with hardhat-deploy
  await execute(
    "ChainRunnersBaseRenderer",
    { from: deployer },
    "getLayer",
    0,
    0
  );
};
export default func;
func.tags = ["ChainRunners"];
  1. See error
> yarn hardhat deploy --tags ChainRunners
yarn run v1.22.15
$ /Users/clementwalter/Documents/perso/light-runners/node_modules/.bin/hardhat deploy --tags ChainRunners
Nothing to compile
No need to generate any newer typings.
deploying "ChainRunnersBaseRenderer" (tx: 0xb9d43dc4087f6211c58c47c39091824bc8ecb2503e784d70bddf89b8c5b89f96)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 7486234 gas
executing ChainRunnersBaseRenderer.setLayers (tx: 0xea31ac951adafa13e6f0a41ab3633173616560001bc1bc0f1d4480daf28697a7) ...: performed with 169506 gas
[
  'trait0',
  '0x23455763454530',
  name: 'trait0',
  hexString: '0x23455763454530'
]
An unexpected error occurred:

Error: ERROR processing /Users/clementwalter/Documents/perso/light-runners/deploy/runners.ts:
TypeError: Cannot read property 'bind' of undefined
    at DeploymentsManager.onPendingTx (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/DeploymentsManager.ts:572:28)
    at execute (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/helpers.ts:2282:16)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at runNextTicks (internal/process/task_queues.js:64:3)
    at listOnTimeout (internal/timers.js:524:9)
    at processTimers (internal/timers.js:498:7)
    at async Object.func (/Users/clementwalter/Documents/perso/light-runners/deploy/runners.ts:51:3)
    at async DeploymentsManager.executeDeployScripts (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1217:22)
    at async DeploymentsManager.runDeploy (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1050:5)
    at async SimpleTaskDefinition.action (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/index.ts:405:5)
    at DeploymentsManager.executeDeployScripts (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1220:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at runNextTicks (internal/process/task_queues.js:64:3)
    at listOnTimeout (internal/timers.js:524:9)
    at processTimers (internal/timers.js:498:7)
    at async DeploymentsManager.runDeploy (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1050:5)
    at async SimpleTaskDefinition.action (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/index.ts:405:5)
    at async Environment._runTaskDefinition (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at async Environment.run (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at async SimpleTaskDefinition.action (/Users/clementwalter/Documents/perso/light-runners/node_modules/hardhat-deploy/src/index.ts:551:32)
error Command failed with exit code 1.

Expected behavior The execute should work for getLayer as it does for setLayers.

versions

Additional context

I am not affiliated with the Chain Runners projet, I am just trying to play around with their rendering contract. I have extracted this MWE from my personal repo: https://github.com/ClementWalter/light-runners

wighawag commented 2 years ago

execute is for write operation and will always make a tx on the network

to read, you use read

ClementWalter commented 2 years ago

sorry for this; I could not find this sort of info in the doc, do you think that it would be better to add something in it?

wighawag commented 2 years ago

agree, documentation need to improve. there should also be a better error message, I ll re-open so I get to at least improve the current state