-
Notifications
You must be signed in to change notification settings - Fork 14
Migrate script/
JS files to TS
#184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6b51fcf
deploy timelock in TS modern hardhat
gfournieriExec 553f5d5
set timelock in script folder
gfournieriExec b9810ae
migrate test storage to TS
gfournieriExec 6a1997a
update year
gfournieriExec a91d693
update test-storage script to TypeScript
gfournieriExec 46ef4a1
migrate common-test-snapshot to TS
gfournieriExec fd1f44b
update getFunctionSignatures to TS
gfournieriExec 134871e
use hre from hardhat
gfournieriExec c4de97c
update changelog
gfournieriExec 56fe7de
Merge branch 'develop' into feature/update-script-js-files
gfournieriExec a59cd29
update timilock constructor arg
gfournieriExec 8a19032
refactor: update storage layout compatibility check with validation o…
gfournieriExec 3f13b73
removed tools banner
gfournieriExec fc6875c
apply suggestion hasIncompatibleLayouts => hasCompatibleLayouts
gfournieriExec ad6be35
apply suggestion and rename file
gfournieriExec e54402d
back to keeping tracks of incompatibilities
gfournieriExec a2003d1
make this file executable and use export
gfournieriExec f1ee3ea
update github CI to test timelock deployment script
gfournieriExec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,28 @@ | ||
// SPDX-FileCopyrightText: 2023-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
interface AbiParameter { | ||
type: string; | ||
components?: AbiParameter[]; | ||
} | ||
|
||
function getSerializedObject(entry: AbiParameter): string { | ||
return entry.type === 'tuple' | ||
? `(${entry.components?.map(getSerializedObject).join(',') ?? ''})` | ||
: entry.type; | ||
} | ||
|
||
export function getFunctionSignatures(abi: any[]): string { | ||
return [ | ||
...abi.filter((entry) => entry.type === 'receive').map(() => 'receive;'), | ||
...abi.filter((entry) => entry.type === 'fallback').map(() => 'fallback;'), | ||
...abi | ||
.filter((entry) => entry.type === 'function') | ||
.map( | ||
(entry) => | ||
`${entry.name}(${entry.inputs?.map(getSerializedObject).join(',') ?? ''});`, | ||
), | ||
] | ||
.filter(Boolean) | ||
.join(''); | ||
} |
This file contains hidden or 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
10 changes: 4 additions & 6 deletions
10
scripts/common-test-snapshot.js → scripts/common-test-snapshot.ts
This file contains hidden or 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,13 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
async function resetNetworkToInitialState() { | ||
import hre from 'hardhat'; | ||
|
||
export async function resetNetworkToInitialState(): Promise<void> { | ||
console.log( | ||
'Reset network to a fresh state to ensure same initial snapshot state between tests', | ||
); | ||
await hre.network.provider.send('hardhat_reset'); | ||
} | ||
|
||
module.exports = { | ||
resetNetworkToInitialState, | ||
}; |
This file contains hidden or 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,50 @@ | ||
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { duration } from '@nomicfoundation/hardhat-network-helpers/dist/src/helpers/time'; | ||
import hre, { ethers } from 'hardhat'; | ||
import { TimelockController__factory } from '../typechain'; | ||
import { FactoryDeployerHelper } from '../utils/FactoryDeployerHelper'; | ||
const CONFIG = require('../config/config.json'); | ||
|
||
/** | ||
* Deploy TimelockController contract using the generic factory. | ||
*/ | ||
|
||
export const deploy = async () => { | ||
console.log('Deploying TimelockController..'); | ||
const chainId = (await ethers.provider.getNetwork()).chainId; | ||
const [owner] = await hre.ethers.getSigners(); | ||
const deploymentOptions = CONFIG.chains[chainId] || CONFIG.chains.default; | ||
const salt = process.env.SALT || deploymentOptions.v5.salt || ethers.constants.HashZero; | ||
|
||
// Initialize factory deployer | ||
const factoryDeployer = new FactoryDeployerHelper(owner, salt); | ||
|
||
// Deploy TimelockController | ||
const ONE_WEEK_IN_SECONDS = duration.days(7); | ||
const ADMINISTRATORS = [ | ||
'0x9ED07B5DB7dAD3C9a0baA3E320E68Ce779063249', | ||
'0x36e19bc6374c9cea5eb86622cf04c6b144b5b59c', | ||
'0x56fa2d29a54b5349cd5d88ffa584bffb2986a656', | ||
'0x9a78ecd77595ea305c6e5a0daed3669b17801d09', | ||
'0xb5ad0c32fc5fcb5e4cba4c81f523e6d47a82ecd7', | ||
'0xb906dc99340d0f3162dbc5b2539b0ad075649bcf', | ||
]; | ||
const PROPOSERS = [ | ||
'0x0B3a38b0A47aB0c5E8b208A703de366751Df5916', // v5 deployer | ||
]; | ||
const EXECUTORS = [ | ||
'0x0B3a38b0A47aB0c5E8b208A703de366751Df5916', // v5 deployer | ||
]; | ||
const constructorArgs = [ONE_WEEK_IN_SECONDS, ADMINISTRATORS, PROPOSERS, EXECUTORS]; | ||
const timelockFactory = new TimelockController__factory(owner); | ||
await factoryDeployer.deployWithFactory(timelockFactory, constructorArgs); | ||
}; | ||
|
||
if (require.main === module) { | ||
deploy().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
} |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 @@ | ||
// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ValidationOptions } from '@openzeppelin/upgrades-core'; | ||
import { solcInputOutputDecoder } from '@openzeppelin/upgrades-core/dist/src-decoder'; | ||
import { getStorageUpgradeReport } from '@openzeppelin/upgrades-core/dist/storage'; | ||
import { extractStorageLayout } from '@openzeppelin/upgrades-core/dist/storage/extract'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import semver from 'semver'; | ||
import { astDereferencer, findAll } from 'solidity-ast/utils'; | ||
|
||
interface ContractLayouts { | ||
[contractName: string]: { | ||
[version: string]: any; | ||
}; | ||
} | ||
|
||
/** | ||
* Checks storage layout compatibility between different versions of contracts | ||
* @returns true if all storage layouts are compatible, false otherwise | ||
*/ | ||
export function checkStorageLayoutCompatibility(): boolean { | ||
const layouts: ContractLayouts = {}; | ||
const buildDir = 'artifacts/build-info'; | ||
|
||
// Read and process all build artifacts | ||
for (const artifact of fs.readdirSync(buildDir)) { | ||
const buildInfo = JSON.parse(fs.readFileSync(path.join(buildDir, artifact), 'utf8')); | ||
const { solcVersion, input, output } = buildInfo; | ||
const decoder = solcInputOutputDecoder(input, output); | ||
const deref = astDereferencer(output); | ||
|
||
// Process each contract in the build output | ||
for (const src in output.contracts) { | ||
// Skip if no AST | ||
if (!output.sources[src].ast) continue; | ||
|
||
// Process each contract definition | ||
for (const contractDef of findAll('ContractDefinition', output.sources[src].ast)) { | ||
// Skip libraries and interfaces that don't have storage | ||
if (['library', 'interface'].includes(contractDef.contractKind)) continue; | ||
|
||
// Initialize storage layout for this contract if not exists | ||
layouts[contractDef.name] = layouts[contractDef.name] || {}; | ||
|
||
// Store storage layout for this version | ||
layouts[contractDef.name][solcVersion] = extractStorageLayout( | ||
contractDef, | ||
decoder, | ||
deref, | ||
output.contracts[src][contractDef.name].storageLayout, | ||
); | ||
} | ||
} | ||
} | ||
|
||
let hasIncompatibleLayouts = false; | ||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Check compatibility between versions | ||
for (const [name, versions] of Object.entries(layouts)) { | ||
const keys = Object.keys(versions).sort(semver.compare); | ||
switch (keys.length) { | ||
case 0: // should never happen | ||
case 1: // contract only available in one version | ||
continue; | ||
default: | ||
console.log(`[${name}]`); | ||
keys.slice(0, -1).forEach((v, i) => { | ||
const report = getStorageUpgradeReport( | ||
versions[v], | ||
versions[keys[i + 1]], | ||
{} as Required<ValidationOptions>, | ||
); | ||
if (report.ok) { | ||
console.log(`- ${v} → ${keys[i + 1]}: storage layout is compatible`); | ||
} else { | ||
console.log(report.explain()); | ||
hasIncompatibleLayouts = true; | ||
gfournieriExec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
break; | ||
} | ||
} | ||
|
||
return !hasIncompatibleLayouts; | ||
gfournieriExec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Run the check if this file is being run directly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking for that thanks |
||
if (require.main === module) { | ||
const success = checkStorageLayoutCompatibility(); | ||
process.exit(success ? 0 : 1); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.