Repository: iExecBlockchainComputing/dataprotector-sdk
Pull request #408: ci(ssc): add workflow for sharing smart contract tests
Author: login: TartanLeGrand
Created: 2025-03-11T11:31:15Z | Merged: 2025-04-09T14:09:08Z

This pull request introduces a new continuous integration (CI) workflow for the sharing smart contract. The workflow is defined in the `.github/workflows/sharing-smart-contract-test.yml` file and includes several steps to ensure the smart contract is properly built, tested, and analyzed.

Key changes:

* `.github/workflows/sharing-smart-contract-test.yml`: 
  - Added a new CI workflow named "CI Sharing Smart Contract" that triggers on pull requests affecting the `packages/sharing-smart-contract` directory.
  - Configured the workflow to run on the latest Ubuntu environment and set up concurrency control to cancel in-progress runs for the same branch.
  - Included steps to check out the repository, set up Node.js, install dependencies, compile the smart contract, check formatting, lint the code, generate UML diagrams, and run a static analyzer.
  - Added steps to start and wait for the Anvil Ethereum local testnet, run Hardhat tests, perform an upgrade test, run Forge tests, and upload the SARIF file generated by the static analyzer.


Diff:
diff --git a/.github/workflows/sharing-smart-contract-test.yml b/.github/workflows/sharing-smart-contract-test.yml
new file mode 100644
index 000000000..ea7cf3922
--- /dev/null
+++ b/.github/workflows/sharing-smart-contract-test.yml
@@ -0,0 +1,105 @@
+name: CI Sharing Smart Contract
+
+on:
+  pull_request:
+    branches:
+      - '*'
+    paths:
+      - 'packages/sharing-smart-contract/**'
+
+concurrency:
+  group: ${{ github.ref }}-sharing-smart-contract-tests
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+
+      - name: Install Dependencies
+        working-directory: packages/sharing-smart-contract
+        run: |
+          node -v
+          npm -v
+          npm ci
+
+      - name: Install Foundry
+        uses: foundry-rs/foundry-toolchain@v1
+        with:
+          version: stable
+          cache: true
+
+      - name: Compile
+        working-directory: packages/sharing-smart-contract
+        run: npm run compile
+
+      - name: Check Format
+        working-directory: packages/sharing-smart-contract
+        run: npm run check-format
+
+      - name: Lint
+        working-directory: packages/sharing-smart-contract
+        run: npm run lint
+
+      - name: UML Diagrams
+        working-directory: packages/sharing-smart-contract
+        run: npm run uml
+
+      - name: Static Analyzer
+        uses: crytic/slither-action@v0.4.0
+        id: slither
+        with:
+          sarif: result.sarif
+          fail-on: none
+          target: 'packages/sharing-smart-contract/'
+
+      - name: Start Anvil
+        run: |
+          anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0 &
+
+      - name: Wait for Anvil to start
+        run: |
+          timeout=30
+          interval=1
+          echo "Waiting for Anvil to start..."
+          for ((i=0; i<timeout; i++)); do
+            if nc -z localhost 8545; then
+               echo "Anvil is operational."
+               exit 0
+            fi
+            echo "Attempt $((i+1)) of $timeout: Anvil is not ready, waiting ${interval}s..."
+            sleep $interval
+          done
+          echo "Error: Anvil did not start within the timeout period."
+          exit 1
+
+      - name: Hardhat Tests
+        working-directory: packages/sharing-smart-contract
+        run: npm run test -- --network ci-bellecour-fork
+
+      - name: Upgrade Test
+        working-directory: packages/sharing-smart-contract
+        run: npm run upgrade-local-fork -- --network local-bellecour-fork
+
+      - name: Set Directory Permissions
+        working-directory: packages/sharing-smart-contract
+        run: sudo chmod -R 777 .
+
+      - name: Forge Tests
+        working-directory: packages/sharing-smart-contract
+        run: forge test --no-match-test "invariant" -vvvv
+
+      - name: Upload SARIF file
+        uses: github/codeql-action/upload-sarif@v3
+        with:
+          sarif_file: ${{ steps.slither.outputs.sarif }}
diff --git a/packages/sharing-smart-contract/.drone.yml b/packages/sharing-smart-contract/.drone.yml
deleted file mode 100644
index d5d31a8c1..000000000
--- a/packages/sharing-smart-contract/.drone.yml
+++ /dev/null
@@ -1,126 +0,0 @@
-###################### SHARING SMART CONTRACT DRONE CI ######################
-kind: pipeline
-type: docker
-name: sharing-smart-contract-default
-
-trigger:
-  event: push
-
-steps:
-  - name: install-deps
-    image: node:18.19
-    pull: always
-    commands:
-      - cd packages/sharing-smart-contract
-      - node -v
-      - npm -v
-      - npm ci
-
-  - name: install-forge
-    image: node:18.19
-    pull: always
-    commands:
-      - export XDG_CONFIG_HOME=/drone/src
-      - curl -L https://foundry.paradigm.xyz | bash
-      - export PATH="$PATH:/drone/src/.foundry/bin"
-      - foundryup
-      - cd packages/sharing-smart-contract
-      - forge install foundry-rs/forge-std --no-git
-
-  - name: bellecour-fork
-    detach: true
-    image: ghcr.io/foundry-rs/foundry:latest
-    pull: always
-    expose:
-      - 8545
-    commands:
-      - anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0
-
-  - name: bellecour-fork-healthy
-    image: bash
-    commands:
-      - while ! nc -z bellecour-fork 8545 ; do sleep 1 ; done && echo "bellecour-fork ready"
-    depends_on:
-      - bellecour-fork
-
-  - name: compile
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - export PATH="$PATH:/drone/src/.foundry/bin"
-      - npm run compile
-    depends_on:
-      - install-forge
-      - install-deps
-
-  - name: check format
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - npm run check-format
-    depends_on:
-      - install-deps
-
-  - name: lint
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - npm run lint
-    depends_on:
-      - install-deps
-
-  - name: uml-diagrams
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - npm run uml
-    depends_on:
-      - install-deps
-
-  - name: static-analyzer
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - git clone https://github.com/Picodes/4naly3er.git
-      - cd 4naly3er
-      - git reset --hard HEAD~1 # FIX issue https://github.com/Picodes/4naly3er/issues/48
-      - yarn install
-      - yarn analyze ../contracts
-    depends_on:
-      - lint
-
-  - name: hardhat-tests
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - export PATH="$PATH:/drone/src/.foundry/bin"
-      - npm run test -- --network ci-bellecour-fork
-    depends_on:
-      - install-deps
-      - install-forge
-      - compile
-      - bellecour-fork-healthy
-
-  - name: upgrade-test
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - export PATH="$PATH:/drone/src/.foundry/bin"
-      - npm run upgrade-local-fork -- --network ci-bellecour-fork
-    depends_on:
-      - install-deps
-      - install-forge
-      - compile
-      - bellecour-fork-healthy
-
-  - name: forge-tests
-    image: node:18.19
-    commands:
-      - cd packages/sharing-smart-contract
-      - export PATH="$PATH:/drone/src/.foundry/bin"
-      - forge test --no-match-test "invariant" -vvvv
-    depends_on:
-      - install-deps
-      - install-forge
-      - compile
-      - bellecour-fork-healthy
diff --git a/packages/sharing-smart-contract/test/SupportsInterface.t.sol b/packages/sharing-smart-contract/test/SupportsInterface.t.sol
index eb05b464b..9f7250e45 100644
--- a/packages/sharing-smart-contract/test/SupportsInterface.t.sol
+++ b/packages/sharing-smart-contract/test/SupportsInterface.t.sol
@@ -20,11 +20,11 @@ contract SupportsInterface is Test {
         );
     }
 
-    function testSupports721Interface() external view {
+    function testSupports721Interface() external {
         assertTrue(_dataProtectorSharing.supportsInterface(type(IAccessControl).interfaceId));
     }
 
-    function testSupportsAccessControlInterface() external view {
+    function testSupportsAccessControlInterface() external {
         assertTrue(_dataProtectorSharing.supportsInterface(type(IERC721).interfaceId));
         assertTrue(_dataProtectorSharing.supportsInterface(type(IERC721Metadata).interfaceId));
     }


Reviews:
user: login: gfournierPro
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-01T09:17:47Z
user: login: gfournierPro
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-01T09:32:33Z
user: login: gfournierPro
body: Some comments, but looks good to me 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-01T12:27:24Z
user: login: gfournierPro
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-01T15:14:27Z
user: login: TartanLeGrand
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-03T21:16:56Z
user: login: TartanLeGrand
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-03T21:17:27Z
user: login: gfournierPro
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T06:51:01Z
user: login: TartanLeGrand
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T07:53:16Z
user: login: Le-Caignec
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T10:04:02Z

Review comments:
diff_hunk: @@ -0,0 +1,107 @@
+name: CI Sharing Smart Contract
+
+on:
+  pull_request:
+    branches:
+      - '*'
+    paths:
+      - 'packages/sharing-smart-contract/**'
+
+concurrency:
+  group: ${{ github.ref }}-sharing-smart-contract-tests
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+
+      - name: Install Dependencies
+        working-directory: packages/sharing-smart-contract
+        run: |
+          node -v
+          npm -v
+          npm ci
+
+      - name: Install Foundry
+        uses: foundry-rs/foundry-toolchain@v1
+        with:
+          version: stable
+          cache: true
+
+      - name: Compile
+        working-directory: packages/sharing-smart-contract
+        run: npm run compile
+
+      - name: Check Format
+        working-directory: packages/sharing-smart-contract
+        run: npm run check-format
+
+      - name: Lint
+        working-directory: packages/sharing-smart-contract
+        run: npm run lint
+
+      - name: UML Diagrams
+        working-directory: packages/sharing-smart-contract
+        run: npm run uml
+
+      - name: Static Analyzer
+        uses: crytic/slither-action@v0.4.0
+        id: slither
+        with:
+          sarif: result.sarif
+          fail-on: none
+          target: 'packages/sharing-smart-contract/'
+
+      - name: Start Anvil
+        run: |
+          anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0 &
+
+      - name: Wait for Anvil to start
+        run: |
+          timeout=30
+          interval=1
+          echo "Waiting for Anvil to start..."
+          for ((i=0; i<timeout; i++)); do
+            if nc -z localhost 8545; then
+               echo "Anvil is operational."
+               exit 0
+            fi
+            echo "Attempt $((i+1)) of $timeout: Anvil is not ready, waiting ${interval}s..."
+            sleep $interval
+          done
+          echo "Error: Anvil did not start within the timeout period."
+          exit 1
+
+      - name: Hardhat Tests
+        uses: ambersun1234/hardhat-test-action@v1
+        with:
+          network: 'local-bellecour-fork'
+          rpc_url: 'http://127.0.0.1:8545'
+
+      - name: Upgrade Test
+        working-directory: packages/sharing-smart-contract
+        run: npm run upgrade-local-fork -- --network local-bellecour-fork
+
+      - name: Set Directory Permissions
+        working-directory: packages/sharing-smart-contract
+        run: sudo chmod -R 777 .
path: .github/workflows/sharing-smart-contract-test.yml
user: login: gfournierPro
body: what it is used for
created_at: 2025-04-01T09:17:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,11 +20,11 @@ contract SupportsInterface is Test {
         );
     }
 
-    function testSupports721Interface() external view {
+    function testSupports721Interface() external {
path: packages/sharing-smart-contract/test/SupportsInterface.t.sol
user: login: gfournierPro
body: why modify this in this PR ?
created_at: 2025-04-01T09:32:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,107 @@
+name: CI Sharing Smart Contract
+
+on:
+  pull_request:
+    branches:
+      - '*'
+    paths:
+      - 'packages/sharing-smart-contract/**'
+
+concurrency:
+  group: ${{ github.ref }}-sharing-smart-contract-tests
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+
+      - name: Install Dependencies
+        working-directory: packages/sharing-smart-contract
+        run: |
+          node -v
+          npm -v
+          npm ci
+
+      - name: Install Foundry
+        uses: foundry-rs/foundry-toolchain@v1
+        with:
+          version: stable
+          cache: true
+
+      - name: Compile
+        working-directory: packages/sharing-smart-contract
+        run: npm run compile
+
+      - name: Check Format
+        working-directory: packages/sharing-smart-contract
+        run: npm run check-format
+
+      - name: Lint
+        working-directory: packages/sharing-smart-contract
+        run: npm run lint
+
+      - name: UML Diagrams
+        working-directory: packages/sharing-smart-contract
+        run: npm run uml
+
+      - name: Static Analyzer
+        uses: crytic/slither-action@v0.4.0
+        id: slither
+        with:
+          sarif: result.sarif
+          fail-on: none
+          target: 'packages/sharing-smart-contract/'
+
+      - name: Start Anvil
+        run: |
+          anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0 &
+
+      - name: Wait for Anvil to start
+        run: |
+          timeout=30
+          interval=1
+          echo "Waiting for Anvil to start..."
+          for ((i=0; i<timeout; i++)); do
+            if nc -z localhost 8545; then
+               echo "Anvil is operational."
+               exit 0
+            fi
+            echo "Attempt $((i+1)) of $timeout: Anvil is not ready, waiting ${interval}s..."
+            sleep $interval
+          done
+          echo "Error: Anvil did not start within the timeout period."
+          exit 1
+
+      - name: Hardhat Tests
+        uses: ambersun1234/hardhat-test-action@v1
+        with:
+          network: 'local-bellecour-fork'
+          rpc_url: 'http://127.0.0.1:8545'
path: .github/workflows/sharing-smart-contract-test.yml
user: login: gfournierPro
body: Can we use our package.json test script (?) I don't find any outputed logs of this action ?
created_at: 2025-04-01T14:13:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,107 @@
+name: CI Sharing Smart Contract
+
+on:
+  pull_request:
+    branches:
+      - '*'
+    paths:
+      - 'packages/sharing-smart-contract/**'
+
+concurrency:
+  group: ${{ github.ref }}-sharing-smart-contract-tests
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+
+      - name: Install Dependencies
+        working-directory: packages/sharing-smart-contract
+        run: |
+          node -v
+          npm -v
+          npm ci
+
+      - name: Install Foundry
+        uses: foundry-rs/foundry-toolchain@v1
+        with:
+          version: stable
+          cache: true
+
+      - name: Compile
+        working-directory: packages/sharing-smart-contract
+        run: npm run compile
+
+      - name: Check Format
+        working-directory: packages/sharing-smart-contract
+        run: npm run check-format
+
+      - name: Lint
+        working-directory: packages/sharing-smart-contract
+        run: npm run lint
+
+      - name: UML Diagrams
+        working-directory: packages/sharing-smart-contract
+        run: npm run uml
+
+      - name: Static Analyzer
+        uses: crytic/slither-action@v0.4.0
+        id: slither
+        with:
+          sarif: result.sarif
+          fail-on: none
+          target: 'packages/sharing-smart-contract/'
+
+      - name: Start Anvil
+        run: |
+          anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0 &
+
+      - name: Wait for Anvil to start
+        run: |
+          timeout=30
+          interval=1
+          echo "Waiting for Anvil to start..."
+          for ((i=0; i<timeout; i++)); do
+            if nc -z localhost 8545; then
+               echo "Anvil is operational."
+               exit 0
+            fi
+            echo "Attempt $((i+1)) of $timeout: Anvil is not ready, waiting ${interval}s..."
+            sleep $interval
+          done
+          echo "Error: Anvil did not start within the timeout period."
+          exit 1
+
+      - name: Hardhat Tests
+        uses: ambersun1234/hardhat-test-action@v1
+        with:
+          network: 'local-bellecour-fork'
+          rpc_url: 'http://127.0.0.1:8545'
+
+      - name: Upgrade Test
+        working-directory: packages/sharing-smart-contract
+        run: npm run upgrade-local-fork -- --network local-bellecour-fork
+
+      - name: Set Directory Permissions
+        working-directory: packages/sharing-smart-contract
+        run: sudo chmod -R 777 .
path: .github/workflows/sharing-smart-contract-test.yml
user: login: TartanLeGrand
body: Fix for permission files
created_at: 2025-04-03T21:16:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,11 +20,11 @@ contract SupportsInterface is Test {
         );
     }
 
-    function testSupports721Interface() external view {
+    function testSupports721Interface() external {
path: packages/sharing-smart-contract/test/SupportsInterface.t.sol
user: login: TartanLeGrand
body: Code error, the fix came from @Le-Caignec :smile: 
created_at: 2025-04-03T21:17:27Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,11 +20,11 @@ contract SupportsInterface is Test {
         );
     }
 
-    function testSupports721Interface() external view {
+    function testSupports721Interface() external {
path: packages/sharing-smart-contract/test/SupportsInterface.t.sol
user: login: gfournierPro
body: thanks
created_at: 2025-04-04T06:51:01Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,107 @@
+name: CI Sharing Smart Contract
+
+on:
+  pull_request:
+    branches:
+      - '*'
+    paths:
+      - 'packages/sharing-smart-contract/**'
+
+concurrency:
+  group: ${{ github.ref }}-sharing-smart-contract-tests
+  cancel-in-progress: true
+
+jobs:
+  build-and-test:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - uses: actions/setup-node@v4
+        with:
+          node-version: '18'
+
+      - name: Install Dependencies
+        working-directory: packages/sharing-smart-contract
+        run: |
+          node -v
+          npm -v
+          npm ci
+
+      - name: Install Foundry
+        uses: foundry-rs/foundry-toolchain@v1
+        with:
+          version: stable
+          cache: true
+
+      - name: Compile
+        working-directory: packages/sharing-smart-contract
+        run: npm run compile
+
+      - name: Check Format
+        working-directory: packages/sharing-smart-contract
+        run: npm run check-format
+
+      - name: Lint
+        working-directory: packages/sharing-smart-contract
+        run: npm run lint
+
+      - name: UML Diagrams
+        working-directory: packages/sharing-smart-contract
+        run: npm run uml
+
+      - name: Static Analyzer
+        uses: crytic/slither-action@v0.4.0
+        id: slither
+        with:
+          sarif: result.sarif
+          fail-on: none
+          target: 'packages/sharing-smart-contract/'
+
+      - name: Start Anvil
+        run: |
+          anvil --host 0.0.0.0 --port 8545 --hardfork berlin --fork-url https://bellecour.iex.ec --chain-id 134 --gas-limit 6700000 --gas-price 0 &
+
+      - name: Wait for Anvil to start
+        run: |
+          timeout=30
+          interval=1
+          echo "Waiting for Anvil to start..."
+          for ((i=0; i<timeout; i++)); do
+            if nc -z localhost 8545; then
+               echo "Anvil is operational."
+               exit 0
+            fi
+            echo "Attempt $((i+1)) of $timeout: Anvil is not ready, waiting ${interval}s..."
+            sleep $interval
+          done
+          echo "Error: Anvil did not start within the timeout period."
+          exit 1
+
+      - name: Hardhat Tests
+        uses: ambersun1234/hardhat-test-action@v1
+        with:
+          network: 'local-bellecour-fork'
+          rpc_url: 'http://127.0.0.1:8545'
path: .github/workflows/sharing-smart-contract-test.yml
user: login: TartanLeGrand
body: Changed 😄 
created_at: 2025-04-09T07:53:16Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-advanced-security[bot]
created_at: 2025-03-11T15:14:16Z
body: This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on [this overview](/iExecBlockchainComputing/dataprotector-sdk/security/code-scanning?query=pr%3A408+is%3Aopen). Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out [the documentation](https://docs.github.com/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning). 
author_association: NONE
user: login: Le-Caignec
created_at: 2025-04-09T06:54:33Z
body: we need logs for hardhat tests step. Can you display them ?

author_association: CONTRIBUTOR
user: login: TartanLeGrand
created_at: 2025-04-09T07:54:00Z
body: > we need logs for hardhat tests step. Can you display them ?

Have rollback to npm test, good for you ?
author_association: CONTRIBUTOR