Skip to content

Commit b22de91

Browse files
Migrate script/ JS files to TS (#184)
2 parents 0b0ac0a + f1ee3ea commit b22de91

12 files changed

+182
-202
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
# Basic deployment to make sure everything is ok.
3737
# Could be removed in the future if not relevant.
3838
run: npm run deploy
39+
- name: Test Timelock Deployment
40+
run: npm run deploy:timelock
3941
- name: Run coverage
4042
run: npm run coverage
4143
- name: Upload coverage reports to Codecov

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- [x] `IexecPoco2Delegate.sol`
77

88
### Features
9+
- Migrate scripts to TypeScript: (#184)
10+
- `getFunctionSignatures.js`, `common-test-snapshot.js`, `test-storage.js`, `timelock.js`
911
- Migrated utility files to TypeScript : (#183)
1012
- `FactoryDeployer.js`, `constants.js`, `odb-tools.js`
1113
- Removed deprecated `scripts/ens/sidechain.js`

migrations/utils/getFunctionSignatures.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

migrations/utils/getFunctionSignatures.js

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-FileCopyrightText: 2023-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
interface AbiParameter {
5+
type: string;
6+
components?: AbiParameter[];
7+
}
8+
9+
function getSerializedObject(entry: AbiParameter): string {
10+
return entry.type === 'tuple'
11+
? `(${entry.components?.map(getSerializedObject).join(',') ?? ''})`
12+
: entry.type;
13+
}
14+
15+
export function getFunctionSignatures(abi: any[]): string {
16+
return [
17+
...abi.filter((entry) => entry.type === 'receive').map(() => 'receive;'),
18+
...abi.filter((entry) => entry.type === 'fallback').map(() => 'fallback;'),
19+
...abi
20+
.filter((entry) => entry.type === 'function')
21+
.map(
22+
(entry) =>
23+
`${entry.name}(${entry.inputs?.map(getSerializedObject).join(',') ?? ''});`,
24+
),
25+
]
26+
.filter(Boolean)
27+
.join('');
28+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"prepare": "husky",
1111
"build": "npx hardhat compile",
1212
"deploy": "npx hardhat deploy",
13-
"test-storage-layout": "npx hardhat run scripts/test-storage.js",
13+
"deploy:timelock": "hardhat run scripts/deploy-timelock.ts",
14+
"test-storage-layout": "npx hardhat run scripts/test-storage.ts",
1415
"test": "REPORT_GAS=true npx hardhat test",
1516
"autotest": "./test.sh",
1617
"coverage": "npx hardhat coverage",
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
1+
// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
async function resetNetworkToInitialState() {
4+
import hre from 'hardhat';
5+
6+
export async function resetNetworkToInitialState(): Promise<void> {
57
console.log(
68
'Reset network to a fresh state to ensure same initial snapshot state between tests',
79
);
810
await hre.network.provider.send('hardhat_reset');
911
}
10-
11-
module.exports = {
12-
resetNetworkToInitialState,
13-
};

scripts/deploy-timelock.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { duration } from '@nomicfoundation/hardhat-network-helpers/dist/src/helpers/time';
5+
import hre, { ethers } from 'hardhat';
6+
import { TimelockController__factory } from '../typechain';
7+
import { FactoryDeployerHelper } from '../utils/FactoryDeployerHelper';
8+
const CONFIG = require('../config/config.json');
9+
10+
/**
11+
* Deploy TimelockController contract using the generic factory.
12+
*/
13+
14+
export const deploy = async () => {
15+
console.log('Deploying TimelockController..');
16+
const chainId = (await ethers.provider.getNetwork()).chainId;
17+
const [owner] = await hre.ethers.getSigners();
18+
const deploymentOptions = CONFIG.chains[chainId] || CONFIG.chains.default;
19+
const salt = process.env.SALT || deploymentOptions.v5.salt || ethers.constants.HashZero;
20+
21+
// Initialize factory deployer
22+
const factoryDeployer = new FactoryDeployerHelper(owner, salt);
23+
24+
// Deploy TimelockController
25+
const ONE_WEEK_IN_SECONDS = duration.days(7);
26+
const ADMINISTRATORS = [
27+
'0x9ED07B5DB7dAD3C9a0baA3E320E68Ce779063249',
28+
'0x36e19bc6374c9cea5eb86622cf04c6b144b5b59c',
29+
'0x56fa2d29a54b5349cd5d88ffa584bffb2986a656',
30+
'0x9a78ecd77595ea305c6e5a0daed3669b17801d09',
31+
'0xb5ad0c32fc5fcb5e4cba4c81f523e6d47a82ecd7',
32+
'0xb906dc99340d0f3162dbc5b2539b0ad075649bcf',
33+
];
34+
const PROPOSERS = [
35+
'0x0B3a38b0A47aB0c5E8b208A703de366751Df5916', // v5 deployer
36+
];
37+
const EXECUTORS = [
38+
'0x0B3a38b0A47aB0c5E8b208A703de366751Df5916', // v5 deployer
39+
];
40+
const constructorArgs = [ONE_WEEK_IN_SECONDS, ADMINISTRATORS, PROPOSERS, EXECUTORS];
41+
const timelockFactory = new TimelockController__factory(owner);
42+
await factoryDeployer.deployWithFactory(timelockFactory, constructorArgs);
43+
};
44+
45+
if (require.main === module) {
46+
deploy().catch((error) => {
47+
console.error(error);
48+
process.exit(1);
49+
});
50+
}

scripts/hardhat-fixture-deployer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
66
import { deployments, ethers } from 'hardhat';
77
import { IexecInterfaceNative__factory } from '../typechain';
88
import { getIexecAccounts } from '../utils/poco-tools';
9-
const { resetNetworkToInitialState } = require('./common-test-snapshot');
9+
import { resetNetworkToInitialState } from './common-test-snapshot';
1010
const deploy = require('../deploy/0_deploy');
1111
const deployEns = require('../deploy/1_deploy-ens');
1212

scripts/test-storage.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)