test hardhat

This commit is contained in:
Dimitar Manov 2025-06-11 09:22:26 +03:00
parent 546e10a151
commit 2508ce9b56
6 changed files with 82 additions and 72 deletions

View file

@ -4,47 +4,50 @@ name: CI-Build
on: on:
pull_request: pull_request:
types: [ closed ] types: [ closed ]
branches: [ master ]
permissions: permissions:
contents: write contents: write
jobs: jobs:
devnet: build-push:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy') if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ')
name: Build
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
environment: dev
services: env:
geth: ENVIRONMENT: dev
image: dmanov/go-ethereum:dev-latest REPO_NAME: ${{ github.event.repository.name }}
ports:
- 8545:8545
- 30303:30303
options: >-
--health-cmd="curl --fail http://localhost:8545 || exit 1"
--health-interval=10s
--health-timeout=5s
--health-retries=10
command: >
--dev
--http --http.addr 0.0.0.0
--http.api eth,net,web3
--http.corsdomain="*"
--http.vhosts="*"
steps: steps:
- name: Checkout code - name: Checkout the repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: master ref: master
- name: Set up Node.js - name: Autotag
uses: actions/setup-node@v4 id: autotag
uses: anothrNick/github-tag-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
- name: Login to Docker Hub
uses: docker/login-action@v3
with: with:
node-version: '18' username: ${{ secrets.DOCKERHUB_USERNAME }}
cache: 'npm' password: ${{ secrets.DOCKERHUB_TOKEN }}
cache-dependency-path: hardhat/package-lock.json
- name: Install Hardhat dependencies - name: Docker metadata
working-directory: ./hardhat id: metadata
run: npm ci uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}
- name: Build and push to Docker Hub
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-${{ steps.autotag.outputs.tag }}
labels: ${{ steps.metadata.outputs.labels }}

View file

@ -1,53 +1,35 @@
name: CI-Deploy name: CI-Deploy
on: on:
pull_request: pull_request:
types: [ closed ] types: [closed]
branches: [ master ] branches: [master]
permissions:
contents: write
jobs: jobs:
build-push: deploy-contracts:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ') if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy')
name: Build runs-on: ubuntu-latest
runs-on: ubuntu-24.04
environment: dev
env:
ENVIRONMENT: dev
REPO_NAME: ${{ github.event.repository.name }}
steps: steps:
- name: Checkout the repo - name: Checkout Repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: master ref: master
- name: Autotag - name: Start Geth Devnet
id: autotag run: |
uses: anothrNick/github-tag-action@v1 docker compose up -d
env: echo "Waiting for Geth JSON-RPC..."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} until curl -s http://localhost:8545; do sleep 1; done
WITH_V: false
- name: Login to Docker Hub - name: Install Node Modules
uses: docker/login-action@v3 working-directory: ./hardhat
with: run: npm ci
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker metadata - name: Compile Contracts
id: metadata working-directory: ./hardhat
uses: docker/metadata-action@v5 run: npx hardhat compile
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}
- name: Build and push to Docker Hub - name: Deploy Contracts
uses: docker/build-push-action@v6 working-directory: ./hardhat
with: run: npx hardhat run scripts/deploy.ts --network localhost
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-${{ steps.autotag.outputs.tag }}
labels: ${{ steps.metadata.outputs.labels }}

View file

@ -1,4 +1,5 @@
version: "3.8" version: "3.8"
services: services:
geth: geth:
container_name: geth container_name: geth
@ -6,8 +7,12 @@ services:
volumes: volumes:
- ./devnet:/root/.ethereum - ./devnet:/root/.ethereum
ports: ports:
- "8545:8545" # HTTP based JSON RPC API - "8545:8545"
- "30303:30303" # P2P - "30303:30303"
command: > command: >
--http --http.addr 0.0.0.0 --http.api eth,net,web3
--dev --dev
--http
--http.addr 0.0.0.0
--http.corsdomain="*"
--allow-insecure-unlock
--verbosity 3

View file

@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Counter {
uint256 public count;
function incBy(uint256 value) public {
count += value;
}
}

View file

@ -5,7 +5,8 @@ const config: HardhatUserConfig = {
solidity: "0.8.28", solidity: "0.8.28",
networks: { networks: {
localhost: { localhost: {
url: "http://127.0.0.1:8545" url: "http://127.0.0.1:8545",
chainId: 1337
} }
} }
}; };

View file

@ -0,0 +1,9 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("CounterModule", (m) => {
const counter = m.contract("Counter");
m.call(counter, "incBy", [5n]);
return { counter };
});