Add tests

This commit is contained in:
Dimitar Manov 2025-06-11 13:25:50 +03:00
parent f5bfdc4d96
commit a68460f65d
4 changed files with 30 additions and 2 deletions

View file

@ -39,7 +39,11 @@ jobs:
- name: Deploy Contracts - name: Deploy Contracts
working-directory: ./hardhat working-directory: ./hardhat
run: npx hardhat run scripts/deploy.ts --network localhost run: npx hardhat ignition deploy ./ignition/modules/Lock.ts --network localhost
- name: Test Contracts
working-directory: ./hardhat
run: npx hardhat test --network localhost
- name: Autotag - name: Autotag
id: autotag id: autotag

View file

@ -14,5 +14,5 @@ services:
--datadir /root/.ethereum --datadir /root/.ethereum
--http --http
--http.addr 0.0.0.0 --http.addr 0.0.0.0
--http.api eth,net,web3,personal --http.api eth,net,web3
--allow-insecure-unlock --allow-insecure-unlock

View file

@ -7,6 +7,10 @@ const config: HardhatUserConfig = {
localhost: { localhost: {
url: "http://127.0.0.1:8545", url: "http://127.0.0.1:8545",
chainId: 1337 chainId: 1337
},
node: {
url: "http:127.0.0.1:8545",
chainId: 31337
} }
} }
}; };

20
hardhat/test/Contracts.ts Normal file
View file

@ -0,0 +1,20 @@
import { expect } from "chai";
import hre from "hardhat";
import { time } from "@nomicfoundation/hardhat-toolbox/network-helpers";
describe("Lock", function () {
it("Should set the right unlockTime", async function () {
const lockedAmount = 1_000_000_000;
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
// deploy a lock contract where funds can be withdrawn
// one year in the future
const lock = await hre.ethers.deployContract("Lock", [unlockTime], {
value: lockedAmount,
});
// assert that the value is correct
expect(await lock.unlockTime()).to.equal(unlockTime);
});
});