From 27f8bf13c02b8c9f2ee4e4e47b6d4c5489e0ac54 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 19:17:59 +0530 Subject: [PATCH 1/8] Create test.yml --- .github/workflows/test.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ff9dfd8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +# adding tests +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: CI - Test + +on: + push: + branches: [main, develop, init, "feat/*"] + pull_request: + branches: [main, develop, init, "feat/*"] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + node-version: [14.x, 16.x, 18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + +steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} + uses: actions/setup-node@v3 + # uses: borales/actions-yarn@v3.0.0 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + - name: "Install packages" + run: yarn + - name: "Start hardhat node" + run: yarn hardhat node & sleep 3 + - name: "Compile Contracts" + run: yarn compile + - name: "Run tests" + run: yarn test + - name: "Deploy contracts" + run: yarn deploy From 069539c197084d31385399ece8c8fe7ed8578cfd Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 19:24:35 +0530 Subject: [PATCH 2/8] Update test.yml --- .github/workflows/test.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff9dfd8..c8f8e0d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,21 +19,21 @@ jobs: node-version: [14.x, 16.x, 18.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ -steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} - uses: actions/setup-node@v3 - # uses: borales/actions-yarn@v3.0.0 - with: - node-version: ${{ matrix.node-version }} - cache: yarn - - name: "Install packages" - run: yarn - - name: "Start hardhat node" - run: yarn hardhat node & sleep 3 - - name: "Compile Contracts" - run: yarn compile - - name: "Run tests" - run: yarn test - - name: "Deploy contracts" - run: yarn deploy + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} + uses: actions/setup-node@v3 + # uses: borales/actions-yarn@v3.0.0 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + - name: "Install packages" + run: yarn + - name: "Start hardhat node" + run: yarn hardhat node & sleep 3 + - name: "Compile Contracts" + run: yarn compile + - name: "Run tests" + run: yarn test + - name: "Deploy contracts" + run: yarn deploy From b11eafb6c9fee7af76027827d14104afd2616734 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 19:30:29 +0530 Subject: [PATCH 3/8] Update CI --- .github/workflows/{test.yml => ci.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{test.yml => ci.yml} (95%) diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 95% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index c8f8e0d..fe7e270 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions -name: CI - Test +name: Node.js CI on: push: @@ -31,7 +31,7 @@ jobs: run: yarn - name: "Start hardhat node" run: yarn hardhat node & sleep 3 - - name: "Compile Contracts" + - name: "Compile contracts" run: yarn compile - name: "Run tests" run: yarn test From e3f3c296c42879e5c879d018fa4ccb2566d36f2b Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 19:33:41 +0530 Subject: [PATCH 4/8] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe7e270..345ed3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: branches: [main, develop, init, "feat/*"] jobs: - build: + e2e-test: runs-on: ubuntu-latest strategy: matrix: From f79eb8a070207bd6627e2ec7c3ab06462335a087 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 19:56:58 +0530 Subject: [PATCH 5/8] updated: using env vars, update compiler and other cleanups --- .env.example | 6 ++++++ contracts/greeter.sol | 4 ++-- hardhat.config.js | 24 ++++++++++++++++-------- package.json | 3 ++- scripts/deploy.js | 2 +- test/sample-test.js | 2 +- yarn.lock | 5 +++++ 7 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..47459fc --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Be aware. dont commit this file or any of theses keys to your repo. +PRIV_KEY= +ETHEREUM_MAINNET_RPC_URL= +GOERLI_RPC_URL= +POLYGON_MUMBAI_RPC_URL= +POLYGON_MAINNET_RPC_URL= \ No newline at end of file diff --git a/contracts/greeter.sol b/contracts/greeter.sol index 1246c47..2c3871e 100644 --- a/contracts/greeter.sol +++ b/contracts/greeter.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT -pragma solidity 0.8.7; +pragma solidity 0.8.16; -contract greeter { +contract Greeter { string private greeting; constructor(string memory _greeting) { diff --git a/hardhat.config.js b/hardhat.config.js index a9948b4..31bb650 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -1,4 +1,8 @@ require("@nomiclabs/hardhat-ethers"); +require('dotenv').config(); + +// defining accounts to reuse. +const accounts = process.env.PRIV_KEY ? [process.env.PRIV_KEY] : []; // This is a sample Hardhat task. To learn how to create your own go to // https://hardhat.org/guides/create-task.html @@ -15,7 +19,7 @@ task("accounts", "Prints the list of accounts with balances", async () => { }); task("deploy", "Deploys Contract", async () => { - const contractFactory = await ethers.getContractFactory("greeter"); + const contractFactory = await ethers.getContractFactory("Greeter"); const contract = await contractFactory.deploy("Hello, Hardhat!"); await contract.deployed(); console.log("contract deployed at:", contract.address); @@ -39,21 +43,25 @@ module.exports = { local: { url: "http://127.0.0.1:8545", }, + main: { + url: process.env.ETHEREUM_MAINNET_RPC_URL, + accounts: accounts + }, goerli: { - url: "", // rpc providers: infura, alchemy - accounts: [] // private keys + url: process.env.GOERLI_RPC_URL, + accounts // private keys }, polygonTest: { - url: "", // rpc providers: polygon, infura, alchemy - accounts: [] + url: process.env.POLYGON_MUMBAI_RPC_URL, + accounts }, polygonMain: { - url: "", // rpc providers: infura,polygon, alchemy - accounts: [] + url: process.env.POLYGON_MAINNET_RPC_URL, + accounts } }, solidity: { - version: "0.8.7", + version: "0.8.16", settings: { optimizer: { enabled: true, diff --git a/package.json b/package.json index 7b0525c..aa4700b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "devDependencies": { "@nomiclabs/hardhat-ethers": "^2.1.1", "chai": "^4.3.6", + "dotenv": "^16.0.3", "ethers": "^5.7.0", "hardhat": "^2.10.2" } -} \ No newline at end of file +} diff --git a/scripts/deploy.js b/scripts/deploy.js index 716e235..842e92b 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -1,6 +1,6 @@ async function main() { - const contractFactory = await ethers.getContractFactory("greeter"); + const contractFactory = await ethers.getContractFactory("Greeter"); const contract = await contractFactory.deploy("Hello, Hardhat!"); await contract.deployed(); return contract; diff --git a/test/sample-test.js b/test/sample-test.js index 9ed03b1..cfcec39 100644 --- a/test/sample-test.js +++ b/test/sample-test.js @@ -3,7 +3,7 @@ const { ethers } = require("hardhat"); describe("Contract Tests", function () { it("Should return the new greeting once it's changed", async function () { - const contractFactory = await ethers.getContractFactory("greeter"); + const contractFactory = await ethers.getContractFactory("Greeter"); const contract = await contractFactory.deploy("Hello, world!"); await contract.deployed(); diff --git a/yarn.lock b/yarn.lock index f832be3..91c7bb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1061,6 +1061,11 @@ diff@5.0.0: resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== +dotenv@^16.0.3: + version "16.0.3" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" + integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== + elliptic@6.5.4, elliptic@^6.5.2, elliptic@^6.5.4: version "6.5.4" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" From e07433696132576327f4894e22afc68f1c58b53c Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 20:13:36 +0530 Subject: [PATCH 6/8] updated: using env example in actions --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 345ed3e..68fe057 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,8 @@ jobs: cache: yarn - name: "Install packages" run: yarn + - name: "Rename .env.example to .env" + run: mv .env.example .env - name: "Start hardhat node" run: yarn hardhat node & sleep 3 - name: "Compile contracts" From 4589f6d77d355e99c41430a1154ba49cff135bc7 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 20:15:09 +0530 Subject: [PATCH 7/8] Rename greeter.sol to Greeter.sol --- contracts/{greeter.sol => Greeter.sol} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contracts/{greeter.sol => Greeter.sol} (100%) diff --git a/contracts/greeter.sol b/contracts/Greeter.sol similarity index 100% rename from contracts/greeter.sol rename to contracts/Greeter.sol From f098981903a34a5d82d76be4e28067c1d1e5111b Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 22 Oct 2022 20:18:18 +0530 Subject: [PATCH 8/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 52d3073..682ac8f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts with balances. +> Rename `env.example` to `.env` and add your env specific keys. + Try running some of the following tasks: ```shell