-
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.
feat: make additional checker tools (#279)
- Loading branch information
1 parent
f11e048
commit 8d91927
Showing
4 changed files
with
151 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { task } from 'hardhat/config'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
task('contracts', 'Display contract deployment information') | ||
.addParam('target', 'Network type (main, test, local, pretestnet, tenderly)') | ||
.setAction(async (taskArgs: { target: string }) => { | ||
const networkType = taskArgs.target.toLowerCase(); | ||
|
||
const validNetworks = ['main', 'test', 'local', 'pretestnet', 'tenderly']; | ||
if (!validNetworks.includes(networkType)) { | ||
throw new Error('Network parameter 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 fileName = fileNames[networkType as keyof typeof fileNames]; | ||
|
||
// Read JSON file | ||
const filePath = path.join(__dirname, '..', fileName); | ||
|
||
try { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
const deploymentData = JSON.parse(fileContent); | ||
|
||
// Extract and display contract information | ||
console.log(`\nDeployed Contracts (${networkType})`); | ||
console.log('========================'); | ||
|
||
Object.entries(deploymentData.contracts).forEach(([name, data]: [string, any]) => { | ||
console.log(`\n${name}:`); | ||
console.log(`Address: ${data.address}`); | ||
console.log(`Explorer: ${data.url}`); | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error(`Error: Could not read or parse ${fileName}`); | ||
console.error(`Details: ${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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './signatures'; | ||
export * from './copybatch'; | ||
export * from './contracts'; | ||
export * from './compare'; |