Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No revert trace when using factory from typechain #3216

Closed
amanusk opened this issue Sep 27, 2022 · 5 comments
Closed

No revert trace when using factory from typechain #3216

amanusk opened this issue Sep 27, 2022 · 5 comments
Assignees

Comments

@amanusk
Copy link

amanusk commented Sep 27, 2022

This might be related to #2848 and #2248 (what is this, EIPs?! ;) )

Running failed tests when importing a contract via getContractFactory works as intended.
However, when importing via Contract__factory from typechain, and using attach, there is no trace if there is a failed transaction.

Importing from typechain is useful since it enables autocomplete for functions (using coc-typescript), this feature does not work when importing with getContractFactory

MVP for the bug can be found here:
https://github.com/amanusk/hardhat-template/tree/typechain-bug

Running the test (which should fail), returns different results based on how the instance was intiated:

  1) Token
       Mint
         Should mint some tokens:
     Error: Transaction reverted without a reason string
      at TestToken.mint (contracts/TestToken.sol:19)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1802:23)
      at async HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:491:16)
      at async EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1522:18)
      at async HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)
      at async EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

  2) Token
       Mint
         Should mint some tokens, but fail to print trace:
     Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Transaction reverted without a reason string", method="estimateGas", transaction={"from":"0x16CdAd2084BD13Ffe19FC74E5Af4d2ab651e9DF1","to":"0xBc0C757A20aB825930fa42C4Fc067eA12D80c245","data":"0x40c10f19000000000000000000000000303a7b81a1da3d8e52809c32f08058d1a9b193b70000000000000000000000000000000000000000000000000de0b6b3a7640000","accessList":null}, error={"stackTrace":[{"type":4,"sourceReference":{"function":"mint","contract":"TestToken","sourceName":"contracts/TestToken.sol","sourceContent":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\n\n/**\n * @notice A mintable ERC20\n */\ncontract TestToken is ERC20, AccessControl {\n    bytes32 public constant MINTER_ROLE = keccak256(\"MINTER_ROLE\");\n\n    constructor() ERC20(\"Test Token\", \"TST\") {\n        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n        _setupRole(MINTER_ROLE, msg.sender);\n    }\n\n    function mint(address to, uint256 amount) external {\n        require(1 == 0);\n        require(hasRole(MINTER_ROLE, msg.sender), \"Only minter can mint\");\n        _mint(to, amount);\n    }\n}\n","line":19,"range":[539,554]},"message":{"value":{"type":"Buffer","data":[]}},"isInvalidOpcodeError":false}],"data":"0x"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.1)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
      at checkError (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:78:20)
      at EthersProviderWrapper.<anonymous> (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:642:20)
      at step (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
      at Object.throw (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
      at rejected (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:528:9)

@github-actions
Copy link
Contributor

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: d035b504-2b40-4e00-802a-242b90b5599d

@fvictorio
Copy link
Member

Importing from typechain is useful since it enables autocomplete for functions (using coc-typescript), this feature does not work when importing with getContractFactory

Wait, this confuses me. Typechain does return a properly typed contract when you do getContractFactory("Foo"). I just tested that, and I use coc-typescript too. The only reason that I can think of for it not working is that the types haven't been generated yet, but they should be available after compiling your contracts.

@fvictorio
Copy link
Member

Oh, I know why it's not working for you. Can you remove the include and files entries of your tsconfig.json and try again?

@fvictorio
Copy link
Member

Closing for lack of further details. We monitor closed issues though, so I'll re-open it if you can add more information.

@amanusk
Copy link
Author

amanusk commented Oct 19, 2022

grr.. missed your first notification. apologies.
Yes, removing this from tsconfig fixed the issue, completion working fine now!
Thank you. This can indeed me closed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants