hardhat-tracer
Advanced tools
Comparing version 1.1.0-rc.3 to 1.1.0-rc.4
@@ -0,3 +1,4 @@ | ||
import "./decode"; | ||
import "./test"; | ||
import "./trace"; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./decode"); | ||
require("./test"); | ||
require("./trace"); | ||
//# sourceMappingURL=index.js.map |
@@ -21,3 +21,4 @@ "use strict"; | ||
// try to find the contract name | ||
if ((0, utils_2.compareBytecode)(_artifact.deployedBytecode, toBytecode) > 0.5) { | ||
if ((0, utils_2.compareBytecode)(_artifact.deployedBytecode, toBytecode) > 0.5 || | ||
(to === ethers_1.ethers.constants.AddressZero && toBytecode.length <= 2)) { | ||
// if bytecode of "to" is the same as the deployed bytecode | ||
@@ -64,3 +65,3 @@ // we can use the artifact name | ||
// TODO add flag to hide unrecognized stuff | ||
if (contractName) { | ||
if (toBytecode.length > 2 && contractName) { | ||
return `${(0, colors_1.colorContract)(contractName)}.<${(0, colors_1.colorFunction)("UnknownFunction")}>(${(0, colors_1.colorKey)("input=")}${input}, ${(0, colors_1.colorKey)("ret=")}${ret})`; | ||
@@ -67,0 +68,0 @@ } |
@@ -13,2 +13,3 @@ import { Artifacts } from "hardhat/types"; | ||
opcodes?: string[]; | ||
nameTags?: NameTags; | ||
} | ||
@@ -15,0 +16,0 @@ export interface TracerEnv { |
@@ -17,2 +17,3 @@ import { BigNumber } from "ethers"; | ||
export declare function compareBytecode(artifactBytecode: string, contractBytecode: string): number; | ||
export declare function removeColor(str: string): string; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.applyCommonFlagsToTracerEnv = exports.addCommonTracerFlagsTo = exports.getTracerEnvFromUserInput = void 0; | ||
const ethers_1 = require("ethers"); | ||
const utils_1 = require("ethers/lib/utils"); | ||
function getTracerEnvFromUserInput(userInput) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
return { | ||
@@ -16,3 +16,3 @@ enabled: (_a = userInput === null || userInput === void 0 ? void 0 : userInput.enabled) !== null && _a !== void 0 ? _a : false, | ||
opcodes: (_g = userInput === null || userInput === void 0 ? void 0 : userInput.opcodes) !== null && _g !== void 0 ? _g : [], | ||
nameTags: {}, | ||
nameTags: (_h = userInput === null || userInput === void 0 ? void 0 : userInput.nameTags) !== null && _h !== void 0 ? _h : {}, | ||
_internal: { | ||
@@ -86,3 +86,4 @@ printNameTagTip: undefined, | ||
dependencies.nameTags[address.toUpperCase()] || | ||
dependencies.nameTags[ethers_1.ethers.utils.getAddress(address)]); | ||
dependencies.nameTags[ethers_1.ethers.utils.getAddress(address)] || | ||
address); | ||
} | ||
@@ -150,2 +151,6 @@ exports.getFromNameTags = getFromNameTags; | ||
exports.compareBytecode = compareBytecode; | ||
function removeColor(str) { | ||
return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ""); | ||
} | ||
exports.removeColor = removeColor; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "hardhat-tracer", | ||
"version": "1.1.0-rc.3", | ||
"version": "1.1.0-rc.4", | ||
"description": "Hardhat Tracer plugin", | ||
@@ -5,0 +5,0 @@ "repository": "github:zemse/hardhat-tracer", |
@@ -27,3 +27,3 @@ # hardhat-tracer 🕵️ | ||
npx hardhat test --trace # shows logs + calls | ||
npx hardhat test --traceFull # shows logs + calls + sloads + sstores | ||
npx hardhat test --fulltrace # shows logs + calls + sloads + sstores | ||
``` | ||
@@ -33,2 +33,10 @@ | ||
You can just enable trace some code snippet in your tests: | ||
```ts | ||
hre.tracer.enable = true; | ||
await myContract.doStuff(val2); | ||
hre.tracer.enable = false; | ||
``` | ||
### Trace | ||
@@ -43,2 +51,11 @@ | ||
### Calldata decoder | ||
If you are just looking for a quick decode of calldata or [Solidity's Custom Error](https://blog.soliditylang.org/2021/04/21/custom-errors/): | ||
``` | ||
$ npx hardhat decode --data 0x095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | ||
ERC20.approve(spender=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, amount=115792089237316195423570985008687907853269984665640564039457584007913129639935) | ||
``` | ||
### Address name tags | ||
@@ -51,1 +68,12 @@ | ||
``` | ||
or can be set in hardhat config | ||
```ts | ||
tracer: { | ||
nameTags: { | ||
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266': 'Hunter', | ||
[someVariable]: 'MyContract', | ||
}, | ||
}, | ||
``` |
@@ -0,2 +1,3 @@ | ||
import "./decode"; | ||
import "./test"; | ||
import "./trace"; |
@@ -1,2 +0,2 @@ | ||
import { BigNumber, BigNumberish } from "ethers"; | ||
import { BigNumber, BigNumberish, ethers } from "ethers"; | ||
import { FunctionFragment, Interface, Result } from "ethers/lib/utils"; | ||
@@ -32,3 +32,6 @@ import { Artifact } from "hardhat/types"; | ||
// try to find the contract name | ||
if (compareBytecode(_artifact.deployedBytecode, toBytecode) > 0.5) { | ||
if ( | ||
compareBytecode(_artifact.deployedBytecode, toBytecode) > 0.5 || | ||
(to === ethers.constants.AddressZero && toBytecode.length <= 2) | ||
) { | ||
// if bytecode of "to" is the same as the deployed bytecode | ||
@@ -96,3 +99,3 @@ // we can use the artifact name | ||
// TODO add flag to hide unrecognized stuff | ||
if (contractName) { | ||
if (toBytecode.length > 2 && contractName) { | ||
return `${colorContract(contractName)}.<${colorFunction( | ||
@@ -99,0 +102,0 @@ "UnknownFunction" |
@@ -15,2 +15,3 @@ import { Artifacts, EthereumProvider } from "hardhat/types"; | ||
opcodes?: string[]; | ||
nameTags?: NameTags; | ||
} | ||
@@ -17,0 +18,0 @@ |
@@ -26,3 +26,3 @@ import { BigNumber, ethers } from "ethers"; | ||
opcodes: userInput?.opcodes ?? [], | ||
nameTags: {}, | ||
nameTags: userInput?.nameTags ?? {}, | ||
_internal: { | ||
@@ -115,3 +115,4 @@ printNameTagTip: undefined, | ||
dependencies.nameTags[address.toUpperCase()] || | ||
dependencies.nameTags[ethers.utils.getAddress(address)] | ||
dependencies.nameTags[ethers.utils.getAddress(address)] || | ||
address | ||
); | ||
@@ -193,1 +194,8 @@ } | ||
} | ||
export function removeColor(str: string) { | ||
return str.replace( | ||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, | ||
"" | ||
); | ||
} |
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
188243
179
3205
76