mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add hardhat
This commit is contained in:
parent
10f6db5fd8
commit
7bede70560
10 changed files with 7655 additions and 3 deletions
41
.github/workflows/build-hardhat-project.yaml
vendored
Normal file
41
.github/workflows/build-hardhat-project.yaml
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
name: Hardhat Deploy and Test
|
||||
|
||||
on: [workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
deploy_and_test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20.9.0
|
||||
- name: Set up Docker Compose
|
||||
uses: docker/compose-cli@v1
|
||||
with:
|
||||
version: '3.0'
|
||||
|
||||
- name: Run geth devnet
|
||||
run: docker compose up -d
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd hardhat
|
||||
npm install -y
|
||||
npm install --save-dev hardhat -y
|
||||
npx hardhat init -y
|
||||
npm install --save-dev @nomicfoundation/hardhat-toolbox -y
|
||||
|
||||
|
||||
- name: Deploy Hardhat project
|
||||
run: |
|
||||
cd hardhat
|
||||
npx hardhat run scripts/deploy.js --network localhost
|
||||
|
||||
- name: Run tests
|
||||
run: npx hardhat test --network localhost
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -50,3 +50,11 @@ profile.cov
|
|||
logs/
|
||||
|
||||
tests/spec-tests/
|
||||
|
||||
# Hardhat
|
||||
node_modules
|
||||
.env
|
||||
coverage
|
||||
typechain
|
||||
cache
|
||||
artifacts
|
||||
22
create_image.sh
Executable file
22
create_image.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set the name of the container you want to create an image from
|
||||
container_name="limechain-task-geth-1"
|
||||
|
||||
# Get the container ID by filtering the output of `docker ps`
|
||||
container_id=$(docker ps -qf "name=$container_name")
|
||||
|
||||
# Check if the container ID is not empty
|
||||
if [ -n "$container_id" ]; then
|
||||
echo "Found container ID: $container_id"
|
||||
|
||||
# Generate a unique tag for the new image
|
||||
image_tag="anglyuboslav/geth-smart-con"
|
||||
|
||||
# Create an image from the container
|
||||
docker commit "$container_id" "$image_tag"
|
||||
|
||||
echo "Image created with tag: $image_tag"
|
||||
else
|
||||
echo "No running container found with name: $container_name"
|
||||
fi
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
version: "3.9"
|
||||
services:
|
||||
geth:
|
||||
image: anglyuboslav/go-eth-lab
|
||||
command:
|
||||
- --dev
|
||||
image: anglyuboslav/geth
|
||||
command: --dev --http --http.addr 0.0.0.0
|
||||
ports:
|
||||
- 8545:8545
|
||||
- 30303:30303
|
||||
|
|
|
|||
66
hardhat/contracts/Token.sol
Normal file
66
hardhat/contracts/Token.sol
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//SPDX-License-Identifier: UNLICENSED
|
||||
|
||||
// Solidity files have to start with this pragma.
|
||||
// It will be used by the Solidity compiler to validate its version.
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
|
||||
// This is the main building block for smart contracts.
|
||||
contract Token {
|
||||
// Some string type variables to identify the token.
|
||||
string public name = "My Hardhat Token";
|
||||
string public symbol = "MHT";
|
||||
|
||||
// The fixed amount of tokens, stored in an unsigned integer type variable.
|
||||
uint256 public totalSupply = 1000000;
|
||||
|
||||
// An address type variable is used to store ethereum accounts.
|
||||
address public owner;
|
||||
|
||||
// A mapping is a key/value map. Here we store each account's balance.
|
||||
mapping(address => uint256) balances;
|
||||
|
||||
// The Transfer event helps off-chain applications understand
|
||||
// what happens within your contract.
|
||||
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
||||
|
||||
/**
|
||||
* Contract initialization.
|
||||
*/
|
||||
constructor() {
|
||||
// The totalSupply is assigned to the transaction sender, which is the
|
||||
// account that is deploying the contract.
|
||||
balances[msg.sender] = totalSupply;
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to transfer tokens.
|
||||
*
|
||||
* The `external` modifier makes a function *only* callable from *outside*
|
||||
* the contract.
|
||||
*/
|
||||
function transfer(address to, uint256 amount) external {
|
||||
// Check if the transaction sender has enough tokens.
|
||||
// If `require`'s first argument evaluates to `false` then the
|
||||
// transaction will revert.
|
||||
require(balances[msg.sender] >= amount, "Not enough tokens");
|
||||
|
||||
// Transfer the amount.
|
||||
balances[msg.sender] -= amount;
|
||||
balances[to] += amount;
|
||||
|
||||
// Notify off-chain applications of the transfer.
|
||||
emit Transfer(msg.sender, to, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read only function to retrieve the token balance of a given account.
|
||||
*
|
||||
* The `view` modifier indicates that it doesn't modify the contract's
|
||||
* state, which allows us to call it without executing a transaction.
|
||||
*/
|
||||
function balanceOf(address account) external view returns (uint256) {
|
||||
return balances[account];
|
||||
}
|
||||
}
|
||||
5
hardhat/hardhat.config.js
Normal file
5
hardhat/hardhat.config.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require("@nomicfoundation/hardhat-toolbox");
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.19",
|
||||
};
|
||||
7464
hardhat/package-lock.json
generated
Normal file
7464
hardhat/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
16
hardhat/package.json
Normal file
16
hardhat/package.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "hardhat",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
||||
"hardhat": "^2.19.1"
|
||||
}
|
||||
}
|
||||
16
hardhat/scripts/deploy.js
Normal file
16
hardhat/scripts/deploy.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
async function main() {
|
||||
const [deployer] = await ethers.getSigners();
|
||||
|
||||
console.log("Deploying contracts with the account:", deployer.address);
|
||||
|
||||
const token = await ethers.deployContract("Token");
|
||||
|
||||
console.log("Token address:", await token.getAddress());
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
12
hardhat/test/Token.js
Normal file
12
hardhat/test/Token.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const { expect } = require("chai");
|
||||
|
||||
describe("Token contract", function () {
|
||||
it("Deployment should assign the total supply of tokens to the owner", async function () {
|
||||
const [owner] = await ethers.getSigners();
|
||||
|
||||
const hardhatToken = await ethers.deployContract("Token");
|
||||
|
||||
const ownerBalance = await hardhatToken.balanceOf(owner.address);
|
||||
expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue