Socket
Socket
Sign inDemoInstall

hardhat-tracer

Package Overview
Dependencies
1
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hardhat-tracer

Hardhat Tracer plugin


Version published
Weekly downloads
5.6K
decreased by-23.99%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

hardhat-tracer 🕵️

This is a beta release. Some things might not work.

Allows you to see events, calls and storage operations when running your tests.

  • hardhat-tracer 🕵️

Installation

Step 1: Install the package

npm i hardhat-tracer@beta

Step 2: Add to your hardhat.config.js file

require("hardhat-tracer");

Usage

Test

npx hardhat test --trace # same as --vvv
npx hardhat test --fulltrace # same as --vvvv

npx hardhat test --v    # shows logs + calls for only failed txs
npx hardhat test --vv   # shows logs + calls + storage for only failed txs
npx hardhat test --vvv  # shows logs + calls for all txs
npx hardhat test --vvvv # shows logs + calls + storage for all txs

# specify opcode
npx hardhat test --v --opcodes ADD,SUB   # shows any opcode specified for only failed txs
npx hardhat test --vvv --opcodes ADD,SUB # shows any opcode specified for all txs
Console testing

You can just enable trace some code snippet in your tests:

hre.tracer.enable = true;
await myContract.doStuff(val2);
hre.tracer.enable = false;

Trace

You can trace a mainnet transaction and ABIs/artifacts in your project will be used to decode the internal message calls.

npx hardhat trace --hash 0xTransactionHash # works if mainnet fork is on
npx hardhat trace --hash 0xTransactionHash --rpc https://url # must be archive node

Calldata decoder

If you are just looking for a quick decode of calldata, return data or Solidity"s Custom Error:

$ npx hardhat decode --data 0x095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ERC20.approve(spender=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, amount=115792089237316195423570985008687907853269984665640564039457584007913129639935)


$ npx hardhat decode --data 0x3850c7bd --returndata 0x000000000000000000000000000000000000000000024d0fa9cd4ba6ff769172fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcdea1000000000000000000000000000000000000000000000000000000000000a244000000000000000000000000000000000000000000000000000000000000ff78000000000000000000000000000000000000000000000000000000000000ffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001

IUniswapV3Pool(0x0000000000000000000000000000000000000000).slot0() => (sqrtPriceX96: 2781762795090269932261746, tick: -205151, observationIndex: 41540, observationCardinality: 65400, observationCardinalityNext: 65535, feeProtocol: 0, unlocked: true)

Address name tags

You can set display names / name tags for unknown addresses by adding new entry to hre.tracer.nameTags object in your test cases, see following example:

hre.tracer.nameTags[this.arbitrager.address] = "Arbitrager";

or can be set in hardhat config

tracer: {
  nameTags: {
    "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266": "Hunter",
    [someVariable]: "MyContract",
  },
},

State overrides

These state overrides are applied when the EthereumJS/VM is created inside hardhat.

tracer: {
  stateOverrides: {
    "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
      storage: {
        "0": 100,
        "0x1abf42a573070203916aa7bf9118741d8da5f9522f66b5368aa0a2644f487b38": 0,
      },
      bytecode: "0x30FF",
      balance: parseEther("2"),
      nonce: 2
    },
  },
},

Chai util

Allows to add a test case to check whether last tx did an internal message call.

expect(hre.tracer.lastTrace()).to.have.messageCall(
  await contract.populateTransaction.getData(),
  {
    returnData: defaultAbiCoder.encode(["uint"], ["1234"]),
    from: otherContract.address,
    isDelegateCall: true,
    isStaticCall: true,
    isSuccess: true,
  }
);

Keywords

FAQs

Last updated on 18 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc