UNPKG

hardhat-tracer

Version:

Hardhat Tracer plugin

27 lines (23 loc) 679 B
export function compareBytecode( artifactBytecode: string, contractBytecode: string ): number { if (artifactBytecode.length <= 2 || contractBytecode.length <= 2) { return 0; } if (typeof artifactBytecode === "string") { artifactBytecode = artifactBytecode .replace(/\_\_\$/g, "000") .replace(/\$\_\_/g, "000"); } let matchedBytes = 0; for (let i = 0; i < artifactBytecode.length; i++) { if (artifactBytecode[i] === contractBytecode[i]) { matchedBytes++; } } if (isNaN(matchedBytes / artifactBytecode.length)) { console.log(matchedBytes, artifactBytecode.length); } return matchedBytes / artifactBytecode.length; }