Skip to content

Commit 37261db

Browse files
committed
feat: add core smart contract CI and deploy workflows with environment configuration
1 parent 1f64d5e commit 37261db

File tree

7 files changed

+108
-65
lines changed

7 files changed

+108
-65
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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: true
14+
type: number
15+
default: 20
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ inputs.node-version }}
26+
cache: 'npm'
27+
28+
- name: Install dependencies
29+
working-directory: packages/smart-contract
30+
run: npm ci
31+
32+
- name: Check Format
33+
working-directory: packages/smart-contract
34+
run: npm run check-format
35+
36+
- name: Check Lint
37+
working-directory: packages/smart-contract
38+
run: npm run lint
39+
40+
- name: Compile smart contracts
41+
working-directory: packages/smart-contract
42+
run: npm run compile
43+
44+
- name: Run Coverage
45+
working-directory: packages/smart-contract
46+
run: npm run coverage
47+
48+
- name: Upload coverage reports to Codecov
49+
uses: codecov/codecov-action@v5
50+
with:
51+
token: ${{ secrets.CODECOV_TOKEN }}
52+
slug: iExecBlockchainComputing/dataprotector-sdk
53+
54+
- name: Run static analysis with slither
55+
uses: crytic/[email protected]
56+
with:
57+
target: "packages/smart-contract/"
58+
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
59+
fail-on: none # TODO set this to high or other
60+
sarif: results.sarif
61+
62+
- name: Upload SARIF file
63+
uses: github/codeql-action/upload-sarif@v3
64+
with:
65+
sarif_file: results.sarif
Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,54 @@
11
name: Smart Contract Deploy
22

33
on:
4-
workflow_dispatch: # Manually trigger the workflow OR trigger with tags or releases ?
4+
workflow_dispatch: # Manual trigger
55
inputs:
6-
target:
7-
description: 'Deployment target (smart-contract-deploy-dev, smart-contract-deploy-staging, smart-contract-deploy-prod)'
6+
network:
7+
description: 'Network'
88
required: true
99
type: choice
1010
options:
11-
- smart-contract-deploy-dev
12-
- smart-contract-deploy-staging
13-
- smart-contract-deploy-prod
14-
default: smart-contract-deploy-dev
11+
- hardhat
12+
- avalancheFujiTestnet
13+
- arbitrumSepolia
14+
- arbitrum
15+
- bellecour
16+
default: 'hardhat'
17+
18+
concurrency:
19+
group: ${{ github.ref }}-core-smart-contract-ci
20+
cancel-in-progress: true
1521

1622
jobs:
23+
build-and-test:
24+
uses: ./.github/workflows/core-smart-contract-ci.yml
25+
with:
26+
node-version: 20
27+
1728
deploy:
1829
runs-on: ubuntu-latest
1930
steps:
2031
- uses: actions/checkout@v4
2132

2233
- uses: actions/setup-node@v4
2334
with:
24-
node-version: '18'
35+
node-version: 20
36+
cache: 'npm'
2537

2638
- name: Install dependencies
2739
working-directory: packages/smart-contract
28-
run: |
29-
node -v
30-
npm -v
31-
npm ci
32-
33-
- name: Check code format
34-
working-directory: packages/smart-contract
35-
run: npm run check-format
36-
37-
- name: Run lint
38-
working-directory: packages/smart-contract
39-
run: npm run lint
40-
41-
- name: Compile smart contracts
42-
working-directory: packages/smart-contract
43-
run: npm run compile
44-
45-
- name: Run tests
46-
working-directory: packages/smart-contract
47-
run: npm run test
48-
49-
- name: Deploy to dev/staging
50-
if: ${{ (github.event.inputs.target == 'smart-contract-deploy-dev' || github.event.inputs.target == 'smart-contract-deploy-staging') && startsWith(github.ref, 'refs/heads/main') }}
51-
working-directory: packages/smart-contract
52-
env:
53-
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_DEV_PRIVATEKEY }}
54-
run: npm run deploy -- --network bellecour
40+
run: npm ci
5541

56-
- name: Deploy to prod
57-
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' && github.ref == 'refs/heads/main' }}
42+
- name: Deploy contract
5843
working-directory: packages/smart-contract
5944
env:
60-
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_PROD_PRIVATEKEY }}
61-
run: npm run deploy -- --network bellecour
45+
# For Deployment
46+
RPC_URL: ${{ secrets.RPC_URL }}
47+
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
48+
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
49+
# For Verification
50+
EXPLORER_API_KEY: ${{ secrets.EXPLORER_API_KEY }}
51+
run: npm run deploy -- --network ${{ inputs.network }} --deployment-id ${{ inputs.network }} --verify
6252

6353
- name: Update production environment
6454
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' }}
@@ -90,7 +80,3 @@ jobs:
9080
# Configure the SSH key to secrets GitHub
9181
SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }}
9282
shell: bash
93-
94-
- name: Verify contract
95-
working-directory: packages/smart-contract
96-
run: npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)
Lines changed: 3 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,5 @@ 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=

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/config/env.ts

Lines changed: 2 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,7 @@ 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('')),
3030
});
3131

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

packages/smart-contract/hardhat.config.ts

Lines changed: 6 additions & 16 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,15 @@ 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,
4434
},
4535
// poco-chain native config
4636
'dev-native': {
@@ -57,7 +47,7 @@ const config: HardhatUserConfig = {
5747
apiKey: {
5848
bellecour: 'nothing', // a non-empty string is needed by the plugin.
5949
avalancheFuji: 'nothing', // a non-empty string is needed by the plugin.
60-
arbitrumSepolia: env.ARBISCAN_API_KEY || '',
50+
arbitrumSepolia: env.EXPLORER_API_KEY || '',
6151
},
6252
customChains: [
6353
{

packages/smart-contract/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "0.1.0",
44
"scripts": {
55
"compile": "hardhat compile && npm run artifact-to-abis",
6-
"deploy": "hardhat ignition deploy ignition/modules/DataProtector.ts --strategy create2",
76
"test": "hardhat test",
7+
"coverage": "hardhat coverage",
8+
"deploy": "hardhat ignition deploy ignition/modules/DataProtector.ts --strategy create2",
89
"artifact-to-abis": "node tools/artifacts-to-abis.mjs",
910
"check-format": "prettier --loglevel warn 'contracts/**/*.sol' '**/*.ts' --check",
1011
"format": "prettier --loglevel warn 'contracts/**/*.sol' '**/*.ts' --write",

0 commit comments

Comments
 (0)