Skip to content

Commit 5ca5d6c

Browse files
Le-CaignecgfournieriExecCopilotzguesmi
authored
fix: dataProtector core fix ci (#468)
* feat: add core smart contract CI and deploy workflows with environment configuration * ci: set fetch-depth to 0 for checkout actions in CI workflows * fix: add missing cache-dependency-path for npm in CI workflow * fix: add push trigger to smart contract deploy workflow * fix: remove push trigger from smart contract deploy workflow * fix: add missing cache-dependency-path for npm in smart contract deploy workflow * feat: add support for Arbitrum mainnet and API V2 verification format * fix: rename deploy job to build-and-test in CI workflow * fix: format code * fix: add issue reference for Arbitrum mainnet CI support in changelog * chore: update core-smart-contract-deploy.yml Co-authored-by: Copilot <[email protected]> * fix: add environment variables and permissions for deploy job in CI workflow * fix: add step to save deployment artifacts in CI workflow * fix: add IS_VERIFICATION_API_V2 variable to .env.template * fix: remove unused Arbitrum network configurations from Hardhat config * fix: add environment validation for mainnet deployments in CI workflow * fix: streamline deployment folder naming and improve deployment ID handling * fix: ensure newline at end of .env.template for consistency * fix: make node-version input optional in CI workflow * fix: improve mainnet deployment validation in CI workflow * fix: Apply suggestions from code review Co-authored-by: Zied Guesmi <[email protected]> * fix: Update .github/workflows/core-smart-contract-ci.yml Co-authored-by: Zied Guesmi <[email protected]> --------- Co-authored-by: gfournieriExec <[email protected]> Co-authored-by: gfournieriExec <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Zied Guesmi <[email protected]>
1 parent 1f64d5e commit 5ca5d6c

File tree

9 files changed

+217
-122
lines changed

9 files changed

+217
-122
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Core Smart Contract - Default
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths:
8+
- 'packages/smart-contract/**'
9+
workflow_call:
10+
inputs:
11+
node-version:
12+
description: Node.js version to use
13+
required: false
14+
type: number
15+
default: 20
16+
17+
concurrency:
18+
group: ${{ github.ref }}-core-smart-contract-ci
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build-and-test:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ inputs.node-version }}
32+
cache: 'npm'
33+
cache-dependency-path: 'packages/smart-contract'
34+
35+
- name: Install dependencies
36+
working-directory: packages/smart-contract
37+
run: npm ci
38+
39+
- name: Check Format
40+
working-directory: packages/smart-contract
41+
run: npm run check-format
42+
43+
- name: Check Lint
44+
working-directory: packages/smart-contract
45+
run: npm run lint
46+
47+
- name: Compile smart contracts
48+
working-directory: packages/smart-contract
49+
run: npm run compile
50+
51+
- name: Run Coverage
52+
working-directory: packages/smart-contract
53+
run: npm run coverage
54+
55+
- name: Upload coverage reports to Codecov
56+
uses: codecov/codecov-action@v5
57+
with:
58+
token: ${{ secrets.CODECOV_TOKEN }}
59+
slug: iExecBlockchainComputing/dataprotector-sdk
60+
61+
- name: Run static analysis with slither
62+
uses: crytic/[email protected]
63+
with:
64+
target: "packages/smart-contract/"
65+
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
66+
fail-on: none # TODO set this to high or other
67+
sarif: results.sarif
68+
69+
- name: Upload SARIF file
70+
uses: github/codeql-action/upload-sarif@v3
71+
with:
72+
sarif_file: results.sarif
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Smart Contract Deploy
2+
3+
on:
4+
workflow_dispatch: # Manual trigger
5+
inputs:
6+
network:
7+
description: 'Network'
8+
required: true
9+
type: choice
10+
options:
11+
- hardhat
12+
- avalancheFujiTestnet
13+
- arbitrumSepolia
14+
- arbitrum
15+
- bellecour
16+
default: 'hardhat'
17+
environment:
18+
description: 'Environment'
19+
required: true
20+
type: choice
21+
options:
22+
- dev
23+
- prod
24+
default: 'dev'
25+
26+
27+
jobs:
28+
build-and-test:
29+
uses: ./.github/workflows/core-smart-contract-ci.yml
30+
with:
31+
node-version: 20
32+
33+
deploy:
34+
needs: build-and-test
35+
runs-on: ubuntu-latest
36+
env:
37+
CI: true
38+
permissions:
39+
contents: write # Required to commit deployment files.
40+
environment: ${{ inputs.network }}
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: 20
49+
cache: 'npm'
50+
cache-dependency-path: 'packages/smart-contract'
51+
52+
- name: Install dependencies
53+
working-directory: packages/smart-contract
54+
run: npm ci
55+
56+
- name: Validate deployment environment and prepare variables
57+
if: inputs.network != 'hardhat'
58+
run: |
59+
NETWORK="${{ inputs.network }}"
60+
ENVIRONMENT="${{ inputs.environment }}"
61+
62+
case "$NETWORK" in
63+
arbitrum|bellecour)
64+
if [ "$ENVIRONMENT" = "dev" ]; then
65+
echo "Error: Cannot deploy to mainnet ($NETWORK) with dev environment"
66+
exit 1
67+
fi
68+
echo "IS_MAINNET=true" >> $GITHUB_ENV
69+
;;
70+
*)
71+
echo "IS_MAINNET=false" >> $GITHUB_ENV
72+
;;
73+
esac
74+
75+
- name: Deploy contract
76+
working-directory: packages/smart-contract
77+
env:
78+
# For Deployment
79+
RPC_URL: ${{ secrets.RPC_URL }}
80+
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
81+
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
82+
# For Verification
83+
EXPLORER_API_KEY: ${{ secrets.EXPLORER_API_KEY }}
84+
IS_VERIFICATION_API_V2: ${{ vars.IS_VERIFICATION_API_V2 }}
85+
run: |
86+
if [ "${{ inputs.network }}" = "hardhat" ]; then
87+
npm run deploy -- --network ${{ inputs.network }}
88+
else
89+
# For testnets, use network-environment; for mainnets, use network only
90+
if [ "$IS_MAINNET" = false ]; then
91+
DEPLOYMENT_ID="${{ inputs.network }}-${{ inputs.environment }}"
92+
else
93+
DEPLOYMENT_ID="${{ inputs.network }}"
94+
fi
95+
npm run deploy -- --network ${{ inputs.network }} --deployment-id "$DEPLOYMENT_ID" --verify
96+
fi
97+
98+
- name: Save deployment artifacts
99+
if: inputs.network != 'hardhat'
100+
uses: stefanzweifel/git-auto-commit-action@v5
101+
with:
102+
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} ${{ inputs.environment }} (${{ github.run_id }})'
103+
file_pattern: 'packages/smart-contract/ignition/deployments/*'
104+
commit_user_name: 'GitHub Actions Bot'
105+
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
106+
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'

.github/workflows/deploy-smart-contract.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# wallet used for transactions
2-
WALLET_PRIVATE_KEY=
2+
DEPLOYER_PRIVATE_KEY=
33

44
# DatasetRegistry contract address override (deploy script only)
55
DATASET_REGISTRY_ADDRESS=
@@ -10,5 +10,8 @@ RPC_URL=
1010
## Mnemonic for the network
1111
MNEMONIC=
1212

13-
## Arbiscan API key to verify contracts
14-
ARBISCAN_API_KEY=
13+
## API key to verify contracts
14+
EXPLORER_API_KEY=
15+
16+
## Whether to use API V2 verification format
17+
IS_VERIFICATION_API_V2=

packages/smart-contract/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

packages/smart-contract/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9+
- Fix CIs and Support for Arbitrum mainnet (#468)
910
- Support for Arbitrum and Avalanche Fuji testnets (#429).
1011

1112
### Changed

packages/smart-contract/config/env.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
66

77
const envSchema = z.object({
88
// Private key of the wallet used for transactions
9-
WALLET_PRIVATE_KEY: z
9+
DEPLOYER_PRIVATE_KEY: z
1010
.string()
1111
.regex(privateKeyRegex, 'Invalid private key format')
1212
.optional()
@@ -26,7 +26,17 @@ const envSchema = z.object({
2626
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
2727

2828
// Arbiscan API key
29-
ARBISCAN_API_KEY: z.string().optional().or(z.literal('')),
29+
EXPLORER_API_KEY: z.string().optional().or(z.literal('')),
30+
31+
// Whether to use API V2 verification format
32+
IS_VERIFICATION_API_V2: z
33+
.string()
34+
.optional()
35+
.default('true')
36+
.refine((val) => val === 'true' || val === 'false', {
37+
message: 'IS_VERIFICATION_API_V2 must be "true" or "false"',
38+
})
39+
.transform((val) => val === 'true'),
3040
});
3141

3242
export const env = envSchema.parse(process.env);

packages/smart-contract/hardhat.config.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,7 @@ import '@nomicfoundation/hardhat-toolbox';
22
import { HardhatUserConfig } from 'hardhat/config';
33
import { env } from './config/env';
44

5-
const privateKey = env.WALLET_PRIVATE_KEY;
6-
7-
// Avalanche Fuji specific configuration
8-
const fujiBaseConfig = {
9-
blockGasLimit: 8_000_000,
10-
chainId: 43113,
11-
};
12-
13-
// Arbitrum Sepolia specific configuration
14-
const arbitrumSepoliaBaseConfig = {
15-
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
16-
chainId: 421614,
17-
};
5+
const privateKey = env.DEPLOYER_PRIVATE_KEY;
186

197
const config: HardhatUserConfig = {
208
networks: {
@@ -34,13 +22,21 @@ const config: HardhatUserConfig = {
3422
avalancheFuji: {
3523
url: env.RPC_URL || 'https://api.avax-test.network/ext/bc/C/rpc',
3624
accounts: privateKey ? [privateKey] : [],
37-
...fujiBaseConfig,
25+
blockGasLimit: 8_000_000,
26+
chainId: 43113,
3827
},
3928
// Add Arbitrum Sepolia as a network
4029
arbitrumSepolia: {
4130
url: env.RPC_URL || 'https://sepolia-rollup.arbitrum.io/rpc',
4231
accounts: privateKey ? [privateKey] : [],
43-
...arbitrumSepoliaBaseConfig,
32+
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
33+
chainId: 421614,
34+
},
35+
arbitrum: {
36+
url: env.RPC_URL || 'https://arb1.arbitrum.io/rpc',
37+
accounts: privateKey ? [privateKey] : [],
38+
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
39+
chainId: 42161,
4440
},
4541
// poco-chain native config
4642
'dev-native': {
@@ -54,11 +50,12 @@ const config: HardhatUserConfig = {
5450
},
5551
//to verify contract on Blockscout
5652
etherscan: {
57-
apiKey: {
58-
bellecour: 'nothing', // a non-empty string is needed by the plugin.
59-
avalancheFuji: 'nothing', // a non-empty string is needed by the plugin.
60-
arbitrumSepolia: env.ARBISCAN_API_KEY || '',
61-
},
53+
apiKey: env.IS_VERIFICATION_API_V2
54+
? env.EXPLORER_API_KEY
55+
: {
56+
bellecour: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
57+
avalancheFuji: env.EXPLORER_API_KEY || 'nothing', // a non-empty string is needed by the plugin.
58+
},
6259
customChains: [
6360
{
6461
network: 'bellecour',

0 commit comments

Comments
 (0)