diff --git a/.github/workflows/ci-deploy.yml b/.github/workflows/ci-deploy.yml index 73fa382834..88b320ce42 100644 --- a/.github/workflows/ci-deploy.yml +++ b/.github/workflows/ci-deploy.yml @@ -38,6 +38,12 @@ jobs: working-directory: hardhat run: npx hardhat ignition deploy ./ignition/modules/Lock.js --network localhost + - name: Upload contract address artifact + uses: actions/upload-artifact@v3 + with: + name: deployment-artifact + path: hardhat/deployment-output.json + - name: Commit container as new image with contracts run: | docker commit geth-devnet ghcr.io/${{ github.repository_owner }}/go-ethereum:devnet-with-contracts diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 06d825e9f4..c7d51ada0f 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -22,15 +22,21 @@ jobs: - name: Wait for Geth RPC to be ready run: | - for i in {1..10}; do + for i in {1..15}; do curl -s http://localhost:8545 && break echo "Waiting for Geth RPC..." && sleep 3 done - - name: Install Hardhat dependencies - working-directory: hardhat - run: npm install - - name: Run Hardhat tests against devnet-with-contracts - working-directory: hardhat - run: npx hardhat test \ No newline at end of file + + - name: Download contract address artifact + uses: actions/download-artifact@v3 + with: + name: deployment-artifact + path: hardhat/ + + - name: Install dependencies and run test + run: | + cd hardhat + npm install + npx hardhat test test/Lock.external.js --network hell \ No newline at end of file diff --git a/hardhat/hardhat.config.js b/hardhat/hardhat.config.js index cdc70c5bc8..a51cba71dc 100644 --- a/hardhat/hardhat.config.js +++ b/hardhat/hardhat.config.js @@ -1,7 +1,11 @@ require("@nomicfoundation/hardhat-toolbox"); -/** @type import('hardhat/config').HardhatUserConfig */ module.exports = { - solidity: "0.8.28", -}; \ No newline at end of file + networks: { + hell: { + url: "http://127.0.0.1:8545", + accounts: [process.env.PRIVATE_KEY] // Set in GitHub Secrets + } + } +}; diff --git a/hardhat/tasks/index.js b/hardhat/tasks/index.js new file mode 100644 index 0000000000..4d85ddccfb --- /dev/null +++ b/hardhat/tasks/index.js @@ -0,0 +1,15 @@ +const fs = require("fs"); + +task("deploy", "Deploys the contract") + .addParam("unlockTime", "Timestamp after which the contract can be unlocked") + .setAction(async (taskArgs, hre) => { + const Contract = await hre.ethers.getContractFactory("Lock"); + const contract = await Contract.deploy(taskArgs.unlockTime); + await contract.waitForDeployment(); + + const address = contract.target; + + fs.writeFileSync("deployment-output.json", JSON.stringify({ address })); + + console.log("Deployed to:", address); + }); diff --git a/hardhat/test/Lock.external.js b/hardhat/test/Lock.external.js new file mode 100644 index 0000000000..5e72be92f9 --- /dev/null +++ b/hardhat/test/Lock.external.js @@ -0,0 +1,17 @@ +const { expect } = require("chai"); +const fs = require("fs"); + +describe("Lock (deployed contract)", function () { + let lock; + + before(async () => { + const { address } = JSON.parse(fs.readFileSync("deployment-output.json", "utf-8")); + const Lock = await ethers.getContractFactory("Lock"); + lock = Lock.attach(address); + }); + + it("Should read unlock time", async () => { + const unlockTime = await lock.unlockTime(); + expect(unlockTime).to.be.a("bigint"); + }); +});