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:
pull_request:
types: [ closed ]
branches: [ master ]
permissions:
contents: write
jobs:
devnet:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy')
build-push:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ')
name: Build
runs-on: ubuntu-24.04
services:
geth:
image: dmanov/go-ethereum:dev-latest
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="*"
environment: dev
env:
ENVIRONMENT: dev
REPO_NAME: ${{ github.event.repository.name }}
steps:
- name: Checkout code
- name: Checkout the repo
uses: actions/checkout@v4
with:
ref: master
- name: Set up Node.js
uses: actions/setup-node@v4
- name: Autotag
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:
node-version: '18'
cache: 'npm'
cache-dependency-path: hardhat/package-lock.json
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Install Hardhat dependencies
working-directory: ./hardhat
run: npm ci
- name: Docker metadata
id: metadata
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
on:
pull_request:
types: [closed]
branches: [master]
permissions:
contents: write
jobs:
build-push:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ')
name: Build
runs-on: ubuntu-24.04
environment: dev
env:
ENVIRONMENT: dev
REPO_NAME: ${{ github.event.repository.name }}
deploy-contracts:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy')
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: master
- name: Autotag
id: autotag
uses: anothrNick/github-tag-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
- name: Start Geth Devnet
run: |
docker compose up -d
echo "Waiting for Geth JSON-RPC..."
until curl -s http://localhost:8545; do sleep 1; done
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Install Node Modules
working-directory: ./hardhat
run: npm ci
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}
- name: Compile Contracts
working-directory: ./hardhat
run: npx hardhat compile
- 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 }}
- name: Deploy Contracts
working-directory: ./hardhat
run: npx hardhat run scripts/deploy.ts --network localhost

View file

@ -1,4 +1,5 @@
version: "3.8"
services:
geth:
container_name: geth
@ -6,8 +7,12 @@ services:
volumes:
- ./devnet:/root/.ethereum
ports:
- "8545:8545" # HTTP based JSON RPC API
- "30303:30303" # P2P
- "8545:8545"
- "30303:30303"
command: >
--http --http.addr 0.0.0.0 --http.api eth,net,web3
--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",
networks: {
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 };
});