Socket
Socket
Sign inDemoInstall

hardhat-tracer

Package Overview
Dependencies
277
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0-rc.6 to 1.1.0-rc.7

dist/src/format/call.d.ts

6

dist/src/tasks/decode.js

@@ -5,6 +5,6 @@ "use strict";

const config_1 = require("hardhat/config");
const call_1 = require("../trace/format/call");
const error_1 = require("../trace/format/error");
const call_1 = require("../format/call");
const error_1 = require("../format/error");
const utils_1 = require("../utils");
(0, utils_1.addCommonTracerFlagsTo)((0, config_1.task)("decode", "Decodes calldata or error data"))
(0, utils_1.addCliParams)((0, config_1.task)("decode", "Decodes calldata or error data"))
.addParam("data", "Calldata or error data to decode")

@@ -11,0 +11,0 @@ .setAction(async (args, hre) => {

@@ -7,4 +7,4 @@ "use strict";

const wrapper_1 = require("../wrapper");
(0, utils_1.addCommonTracerFlagsTo)((0, config_1.task)(task_names_1.TASK_TEST, "Runs mocha tests")).setAction(async (args, hre, runSuper) => {
(0, utils_1.applyCommonFlagsToTracerEnv)(args, hre);
(0, utils_1.addCliParams)((0, config_1.task)(task_names_1.TASK_TEST, "Runs mocha tests")).setAction(async (args, hre, runSuper) => {
(0, utils_1.applyCliArgsToTracer)(args, hre);
(0, wrapper_1.wrapHardhatProvider)(hre);

@@ -11,0 +11,0 @@ return runSuper(args);

@@ -5,5 +5,5 @@ "use strict";

const config_1 = require("hardhat/config");
const print_1 = require("../print");
const utils_1 = require("../utils");
const wrapper_1 = require("../wrapper");
(0, utils_1.addCommonTracerFlagsTo)((0, config_1.task)("trace", "Traces a transaction hash"))
(0, utils_1.addCliParams)((0, config_1.task)("trace", "Traces a transaction hash"))
.addParam("hash", "transaction hash to view trace of")

@@ -13,6 +13,7 @@ .addOptionalParam("rpc", "archive node")

var _a;
(0, utils_1.applyCommonFlagsToTracerEnv)(args, hre);
(0, utils_1.applyCliArgsToTracer)(args, hre);
const tx = await hre.network.provider.send("eth_getTransactionByHash", [
args.hash,
]);
// if tx is not on hardhat local, then use rpc
if (tx == null) {

@@ -31,6 +32,16 @@ if (!args.rpc) {

}
else if (!txFromRpc.blockNumber) {
if (!txFromRpc.blockNumber) {
throw new Error("Transaction is not mined yet, please wait for it to be mined");
}
else {
try {
console.warn("Trying with rpc");
await (0, print_1.printDebugTrace)(args.hash, {
provider,
tracerEnv: hre.tracer,
artifacts: hre.artifacts,
nameTags: hre.tracer.nameTags,
});
}
catch (error) {
console.warn("Using debug_tt on rpc failed, activating mainnet fork at block", txFromRpc.blockNumber);
await hre.network.provider.send("hardhat_reset", [

@@ -44,11 +55,16 @@ {

]);
console.log("Switched mainnet fork to block", txFromRpc.blockNumber);
}
}
(0, wrapper_1.wrapHardhatProvider)(hre);
hre.tracer.enabled = true;
// using hardhat for getting the trace. if tx was previously not found on hardhat local,
// but now it will be available, due to mainnet fork activation
console.warn("Trying with hardhat mainnet fork");
const tracePromise = (0, print_1.printDebugTraceOrLogs)(args.hash, {
provider: hre.network.provider,
tracerEnv: hre.tracer,
artifacts: hre.artifacts,
nameTags: hre.tracer.nameTags,
});
const delayPromise = new Promise((resolve) => {
setTimeout(() => resolve("delay"), 20000);
});
const tracePromise = hre.network.provider.send("eth_getTransactionReceipt", [args.hash]);
const resolved = await Promise.race([delayPromise, tracePromise]);

@@ -59,3 +75,3 @@ if (resolved === "delay") {

const traceResult = await tracePromise;
if (traceResult == null) {
if (!traceResult) {
throw new Error("Transaction could not be traced");

@@ -62,0 +78,0 @@ }

@@ -5,4 +5,4 @@ import { BigNumber } from "ethers";

export declare function getTracerEnvFromUserInput(userInput?: TracerEnvUser): TracerEnv;
export declare function addCommonTracerFlagsTo(task: ConfigurableTaskDefinition): ConfigurableTaskDefinition;
export declare function applyCommonFlagsToTracerEnv(args: any, hre: HardhatRuntimeEnvironment): void;
export declare function addCliParams(task: ConfigurableTaskDefinition): ConfigurableTaskDefinition;
export declare function applyCliArgsToTracer(args: any, hre: HardhatRuntimeEnvironment): void;
export declare function isOnlyLogs(env: TracerEnv): boolean;

@@ -9,0 +9,0 @@ export declare function getFromNameTags(address: string, dependencies: TracerDependenciesExtended): string | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeColor = exports.compareBytecode = exports.shallowCopyStack = exports.parseMemory = exports.parseAddress = exports.parseUint = exports.parseNumber = exports.parseHex = exports.findNextStructLogInDepth = exports.getFromNameTags = exports.isOnlyLogs = exports.applyCommonFlagsToTracerEnv = exports.addCommonTracerFlagsTo = exports.getTracerEnvFromUserInput = void 0;
exports.removeColor = exports.compareBytecode = exports.shallowCopyStack = exports.parseMemory = exports.parseAddress = exports.parseUint = exports.parseNumber = exports.parseHex = exports.findNextStructLogInDepth = exports.getFromNameTags = exports.isOnlyLogs = exports.applyCliArgsToTracer = exports.addCliParams = exports.getTracerEnvFromUserInput = void 0;
const ethers_1 = require("ethers");

@@ -23,5 +23,7 @@ const utils_1 = require("ethers/lib/utils");

exports.getTracerEnvFromUserInput = getTracerEnvFromUserInput;
function addCommonTracerFlagsTo(task) {
function addCliParams(task) {
return (task
// features
// params
.addOptionalParam("opcodes", "specify more opcodes to print")
// feature flags
.addFlag("logs", "print logs emitted during transactions")

@@ -33,3 +35,3 @@ .addFlag("calls", "print calls during transactions")

.addFlag("disabletracer", "do not enable tracer at the start (for inline enabling tracer)")
// feature group
// feature group flags
.addFlag("trace", "trace logs and calls in transactions")

@@ -41,4 +43,4 @@ .addFlag("fulltrace", "trace logs, calls and storage writes in transactions")

}
exports.addCommonTracerFlagsTo = addCommonTracerFlagsTo;
function applyCommonFlagsToTracerEnv(args, hre) {
exports.addCliParams = addCliParams;
function applyCliArgsToTracer(args, hre) {
// populating aliases

@@ -64,2 +66,5 @@ const fulltrace = args.fulltrace || args.tracefull;

}
if (args.opcodes) {
hre.tracer.opcodes = [...args.opcodes.split(",")];
}
// enabling config by mode of operation

@@ -80,3 +85,3 @@ if (args.trace) {

}
exports.applyCommonFlagsToTracerEnv = applyCommonFlagsToTracerEnv;
exports.applyCliArgsToTracer = applyCliArgsToTracer;
function isOnlyLogs(env) {

@@ -83,0 +88,0 @@ return env.logs && !env.calls && !env.sstores && !env.sloads && !env.gasCost;

@@ -7,3 +7,3 @@ "use strict";

const wrapper_1 = require("hardhat/internal/core/providers/wrapper");
const print_trace_1 = require("./trace/print-trace");
const print_1 = require("./print");
const utils_1 = require("./utils");

@@ -46,3 +46,8 @@ /**

const dependenciesExtended = Object.assign(Object.assign({}, this.dependencies), { nameTags: Object.assign({}, this.dependencies.tracerEnv.nameTags) });
await (0, print_trace_1.printTrace)(hash, dependenciesExtended);
try {
await (0, print_1.printDebugTraceOrLogs)(hash, dependenciesExtended);
}
catch (error) {
console.log("error in request wrapper:", error);
}
}

@@ -49,0 +54,0 @@ }

{
"name": "hardhat-tracer",
"version": "1.1.0-rc.6",
"version": "1.1.0-rc.7",
"description": "Hardhat Tracer plugin",

@@ -5,0 +5,0 @@ "repository": "github:zemse/hardhat-tracer",

@@ -35,2 +35,3 @@ # hardhat-tracer 🕵️

npx hardhat test --fulltrace # shows logs + calls + sloads + sstores
npx hardhat test --trace --opcodes ADD,SUB # shows any opcode specified
```

@@ -37,0 +38,0 @@

import { ethers } from "ethers";
import { task } from "hardhat/config";
import { formatCall } from "../trace/format/call";
import { formatError } from "../trace/format/error";
import {
addCommonTracerFlagsTo,
applyCommonFlagsToTracerEnv,
removeColor,
} from "../utils";
import { formatCall } from "../format/call";
import { formatError } from "../format/error";
import { addCliParams, removeColor } from "../utils";
addCommonTracerFlagsTo(task("decode", "Decodes calldata or error data"))
addCliParams(task("decode", "Decodes calldata or error data"))
.addParam("data", "Calldata or error data to decode")

@@ -13,0 +9,0 @@ .setAction(async (args, hre) => {

import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
import { task } from "hardhat/config";
import { addCommonTracerFlagsTo, applyCommonFlagsToTracerEnv } from "../utils";
import { addCliParams, applyCliArgsToTracer } from "../utils";
import { wrapHardhatProvider } from "../wrapper";
addCommonTracerFlagsTo(task(TASK_TEST, "Runs mocha tests")).setAction(
addCliParams(task(TASK_TEST, "Runs mocha tests")).setAction(
async (args, hre, runSuper) => {
applyCommonFlagsToTracerEnv(args, hre);
applyCliArgsToTracer(args, hre);

@@ -11,0 +11,0 @@ wrapHardhatProvider(hre);

import { ethers } from "ethers";
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
import { task } from "hardhat/config";
import { printDebugTrace, printDebugTraceOrLogs } from "../print";
import { addCommonTracerFlagsTo, applyCommonFlagsToTracerEnv } from "../utils";
import { wrapHardhatProvider } from "../wrapper";
import { addCliParams, applyCliArgsToTracer } from "../utils";
addCommonTracerFlagsTo(task("trace", "Traces a transaction hash"))
addCliParams(task("trace", "Traces a transaction hash"))
.addParam("hash", "transaction hash to view trace of")
.addOptionalParam("rpc", "archive node")
.setAction(async (args, hre, runSuper) => {
applyCommonFlagsToTracerEnv(args, hre);
applyCliArgsToTracer(args, hre);

@@ -18,2 +18,3 @@ const tx = await hre.network.provider.send("eth_getTransactionByHash", [

// if tx is not on hardhat local, then use rpc
if (tx == null) {

@@ -36,7 +37,23 @@ if (!args.rpc) {

);
} else if (!txFromRpc.blockNumber) {
}
if (!txFromRpc.blockNumber) {
throw new Error(
"Transaction is not mined yet, please wait for it to be mined"
);
} else {
}
try {
console.warn("Trying with rpc");
await printDebugTrace(args.hash, {
provider,
tracerEnv: hre.tracer,
artifacts: hre.artifacts,
nameTags: hre.tracer.nameTags,
});
} catch (error) {
console.warn(
"Using debug_tt on rpc failed, activating mainnet fork at block",
txFromRpc.blockNumber
);
await hre.network.provider.send("hardhat_reset", [

@@ -50,8 +67,14 @@ {

]);
console.log("Switched mainnet fork to block", txFromRpc.blockNumber);
}
}
wrapHardhatProvider(hre);
hre.tracer.enabled = true;
// using hardhat for getting the trace. if tx was previously not found on hardhat local,
// but now it will be available, due to mainnet fork activation
console.warn("Trying with hardhat mainnet fork");
const tracePromise = printDebugTraceOrLogs(args.hash, {
provider: hre.network.provider,
tracerEnv: hre.tracer,
artifacts: hre.artifacts,
nameTags: hre.tracer.nameTags,
});

@@ -61,6 +84,2 @@ const delayPromise = new Promise((resolve) => {

});
const tracePromise = hre.network.provider.send(
"eth_getTransactionReceipt",
[args.hash]
);

@@ -75,6 +94,5 @@ const resolved = await Promise.race([delayPromise, tracePromise]);

const traceResult = await tracePromise;
if (traceResult == null) {
if (!traceResult) {
throw new Error("Transaction could not be traced");
}
});

@@ -25,3 +25,3 @@ import { Artifacts, EthereumProvider } from "hardhat/types";

gasCost: boolean;
opcodes: string[];
opcodes: string[]; // TODO have a map of opcode to boolean
nameTags: NameTags;

@@ -28,0 +28,0 @@ _internal: {

@@ -33,6 +33,9 @@ import { BigNumber, ethers } from "ethers";

export function addCommonTracerFlagsTo(task: ConfigurableTaskDefinition) {
export function addCliParams(task: ConfigurableTaskDefinition) {
return (
task
// features
// params
.addOptionalParam("opcodes", "specify more opcodes to print")
// feature flags
.addFlag("logs", "print logs emitted during transactions")

@@ -47,3 +50,4 @@ .addFlag("calls", "print calls during transactions")

)
// feature group
// feature group flags
.addFlag("trace", "trace logs and calls in transactions")

@@ -60,3 +64,3 @@ .addFlag(

export function applyCommonFlagsToTracerEnv(
export function applyCliArgsToTracer(
args: any,

@@ -87,2 +91,5 @@ hre: HardhatRuntimeEnvironment

}
if (args.opcodes) {
hre.tracer.opcodes = [...args.opcodes.split(",")];
}

@@ -89,0 +96,0 @@ // enabling config by mode of operation

@@ -11,3 +11,3 @@ import { ethers } from "ethers";

import { printTrace } from "./trace/print-trace";
import { printDebugTraceOrLogs } from "./print";
import {

@@ -19,3 +19,3 @@ ProviderLike,

} from "./types";
import { getTracerEnvFromUserInput } from "./utils";
import { getTracerEnvFromUserInput, isOnlyLogs } from "./utils";

@@ -70,3 +70,7 @@ /**

};
await printTrace(hash, dependenciesExtended);
try {
await printDebugTraceOrLogs(hash, dependenciesExtended);
} catch (error) {
console.log("error in request wrapper:", error);
}
}

@@ -73,0 +77,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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