-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20e90ff
commit da017e6
Showing
4 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { task } from 'hardhat/config'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
interface NetworkDeployment { | ||
chainId: number; | ||
contracts: { | ||
[key: string]: { | ||
bytecode: string; | ||
address: string; | ||
}; | ||
}; | ||
} | ||
|
||
task('compare', 'Compare bytecodes between two deployments') | ||
.addParam('source', 'Source network (main, test, local, pretestnet, tenderly)') | ||
.addParam('target', 'Target network to compare against') | ||
.setAction(async (taskArgs: { source: string; target: string }) => { | ||
const sourceType = taskArgs.source.toLowerCase(); | ||
const targetType = taskArgs.target.toLowerCase(); | ||
|
||
const validNetworks = ['main', 'test', 'local', 'pretestnet', 'tenderly']; | ||
if (!validNetworks.includes(sourceType) || !validNetworks.includes(targetType)) { | ||
throw new Error('Network parameters must be one of: ' + validNetworks.join(', ')); | ||
} | ||
|
||
const fileNames = { | ||
main: 'mainnet_deployed.json', | ||
test: 'testnet_deployed.json', | ||
local: 'localhost_deployed.json', | ||
pretestnet: 'pretestnet_deployed.json', | ||
tenderly: 'tenderly_deployed.json', | ||
}; | ||
|
||
const sourceFile = fileNames[sourceType as keyof typeof fileNames]; | ||
const targetFile = fileNames[targetType as keyof typeof fileNames]; | ||
|
||
try { | ||
// Read deployment files | ||
const sourceData: NetworkDeployment = JSON.parse(fs.readFileSync(path.join(__dirname, '..', sourceFile), 'utf8')); | ||
const targetData: NetworkDeployment = JSON.parse(fs.readFileSync(path.join(__dirname, '..', targetFile), 'utf8')); | ||
|
||
console.log(`\nComparing bytecodes between ${sourceType} and ${targetType}`); | ||
console.log('============================================='); | ||
|
||
// Compare bytecodes for each contract | ||
Object.keys(sourceData.contracts).forEach((contractName) => { | ||
if (targetData.contracts[contractName]) { | ||
const sourceBytecode = sourceData.contracts[contractName].bytecode; | ||
const targetBytecode = targetData.contracts[contractName].bytecode; | ||
|
||
console.log(`\nContract: ${contractName}`); | ||
|
||
if (sourceBytecode === targetBytecode) { | ||
console.log('Bytecodes are identical'); | ||
} else { | ||
// Find the first differing character position | ||
let firstDiff = -1; | ||
for (let i = 0; i < Math.max(sourceBytecode.length, targetBytecode.length); i++) { | ||
if (sourceBytecode[i] !== targetBytecode[i]) { | ||
firstDiff = i; | ||
break; | ||
} | ||
} | ||
|
||
console.log(`Bytecodes differ at position: ${firstDiff}`); | ||
if (firstDiff !== -1) { | ||
// Show a snippet around the difference | ||
const start = Math.max(0, firstDiff - 10); | ||
const end = firstDiff + 10; | ||
|
||
console.log('\nSource bytecode snippet:'); | ||
console.log(sourceBytecode.slice(start, end)); | ||
console.log(' ^'); | ||
console.log('Target bytecode snippet:'); | ||
console.log(targetBytecode.slice(start, end)); | ||
console.log(' ^'); | ||
} | ||
|
||
console.log(`\nSource length: ${sourceBytecode.length}`); | ||
console.log(`Target length: ${targetBytecode.length}`); | ||
} | ||
} else { | ||
console.log(`\nContract ${contractName} not found in ${targetType} deployment`); | ||
} | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error('Error comparing bytecodes:'); | ||
console.error(error.message); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './signatures'; | ||
export * from './copybatch'; | ||
export * from './contracts'; | ||
export * from './compare'; |