Skip to content

Commit

Permalink
Setup of hardhat for precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Jan 30, 2024
1 parent 2650356 commit 7ee71d6
Show file tree
Hide file tree
Showing 19 changed files with 13,698 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
build/_workspace
build/_bin
tests/testdata

vendor
contracts/node_modules
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,22 @@ jobs:
# - name: run simulation result parser
# working-directory: ./hive
# run: result_parser -path_to_results ./workspace/logs

precompile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.4'
- name: build geth docker image
run: make docker-build-dev
- name: run geth docker container
run: docker-compose up -d
- name: install hardhat
working-directory: ./contracts
run: npm install --save-dev hardhat
- name: run precompile tests
working-directory: ./contracts
run: npx hardhat test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ profile.cov
/dashboard/assets/package-lock.json

**/yarn-error.log
logs/

tests/spec-tests/

contracts/artifacts
contracts/cache
contracts/node_modules
12 changes: 12 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.20-alpine

RUN apk add bash make curl

RUN mkdir -p $GOPATH/src/github.com/Kava-Labs/go-ethereum
WORKDIR $GOPATH/src/github.com/Kava-Labs/go-ethereum

COPY . .
RUN make geth
RUN cp ./build/bin/geth $GOPATH/bin/

CMD ["geth", "--dev", "--http", "--http.addr=0.0.0.0"]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ devtools:
env GOBIN= go install ./cmd/abigen
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'

docker-build-dev:
docker build -t go-ethereum-dev -f Dockerfile.dev .
14 changes: 14 additions & 0 deletions contracts/contracts/ExampleStatelessSum3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.8.0;

import "hardhat/console.sol";

address constant PRECOMPILED_STATELESS_SUM3_CONTRACT_ADDRESS = address(0x0b);

contract ExampleStatelessSum3 {
function sum3(uint256 a, uint256 b, uint256 c) public view returns (bytes memory) {
(bool ok, bytes memory data) = address(PRECOMPILED_STATELESS_SUM3_CONTRACT_ADDRESS).staticcall(abi.encode(a,b,c));
require(ok, "call to precompiled contract failed");

return data;
}
}
15 changes: 15 additions & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
defaultNetwork: "geth",
networks: {
hardhat: {},
geth: {
url: "http://localhost:8545",
}
},
solidity: "0.8.19",
};

export default config;
Loading

0 comments on commit 7ee71d6

Please sign in to comment.