refactor: move brother_node development artifact to dev/test-nodes subdirectory
Development Artifact Cleanup: ✅ BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location - dev/test-nodes/brother_node/: Moved from root directory for better organization - Contains development configuration, test logs, and test chain data - No impact on production systems - purely development/testing artifact ✅ DEVELOPMENT ARTIFACTS IDENTIFIED: - Chain ID: aitbc-brother-chain (test/development chain) - Ports: 8010 (P2P) and 8011 (RPC) - different from production - Environment: .env file with test configuration - Logs: rpc.log and node.log from development testing session (March 15, 2026) ✅ ROOT DIRECTORY CLEANUP: Removed development clutter from production directory - brother_node/ moved to dev/test-nodes/brother_node/ - Root directory now contains only production-ready components - Development artifacts properly organized in dev/ subdirectory DIRECTORY STRUCTURE IMPROVEMENT: 📁 dev/test-nodes/: Development and testing node configurations 🏗️ Root Directory: Clean production structure with only essential components 🧪 Development Isolation: Test environments separated from production BENEFITS: ✅ Clean Production Directory: No development artifacts in root ✅ Better Organization: Development nodes grouped in dev/ subdirectory ✅ Clear Separation: Production vs development environments clearly distinguished ✅ Maintainability: Easier to identify and manage development components RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
13
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/README.md
generated
vendored
Executable file
13
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/README.md
generated
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
# Sample Hardhat Project
|
||||
|
||||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
||||
|
||||
Try running some of the following tasks:
|
||||
|
||||
```shell
|
||||
npx hardhat help
|
||||
npx hardhat test
|
||||
REPORT_GAS=true npx hardhat test
|
||||
npx hardhat node
|
||||
npx hardhat ignition deploy ./ignition/modules/Lock.js
|
||||
```
|
||||
34
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/contracts/Lock.sol
generated
vendored
Executable file
34
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/contracts/Lock.sol
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
// Uncomment this line to use console.log
|
||||
// import "hardhat/console.sol";
|
||||
|
||||
contract Lock {
|
||||
uint public unlockTime;
|
||||
address payable public owner;
|
||||
|
||||
event Withdrawal(uint amount, uint when);
|
||||
|
||||
constructor(uint _unlockTime) payable {
|
||||
require(
|
||||
block.timestamp < _unlockTime,
|
||||
"Unlock time should be in the future"
|
||||
);
|
||||
|
||||
unlockTime = _unlockTime;
|
||||
owner = payable(msg.sender);
|
||||
}
|
||||
|
||||
function withdraw() public {
|
||||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
||||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
||||
|
||||
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
||||
require(msg.sender == owner, "You aren't the owner");
|
||||
|
||||
emit Withdrawal(address(this).balance, block.timestamp);
|
||||
|
||||
owner.transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
17
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/gitignore
generated
vendored
Executable file
17
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/gitignore
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
# Hardhat files
|
||||
/cache
|
||||
/artifacts
|
||||
|
||||
# TypeChain files
|
||||
/typechain
|
||||
/typechain-types
|
||||
|
||||
# solidity-coverage files
|
||||
/coverage
|
||||
/coverage.json
|
||||
|
||||
# Hardhat Ignition default folder for deployments against a local node
|
||||
ignition/deployments/chain-31337
|
||||
6
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/hardhat.config.js
generated
vendored
Executable file
6
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/hardhat.config.js
generated
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
require("@nomicfoundation/hardhat-toolbox");
|
||||
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.28",
|
||||
};
|
||||
18
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/ignition/modules/Lock.js
generated
vendored
Executable file
18
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/ignition/modules/Lock.js
generated
vendored
Executable file
@@ -0,0 +1,18 @@
|
||||
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
||||
// Learn more about it at https://hardhat.org/ignition
|
||||
|
||||
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
|
||||
|
||||
const JAN_1ST_2030 = 1893456000;
|
||||
const ONE_GWEI = 1_000_000_000n;
|
||||
|
||||
module.exports = buildModule("LockModule", (m) => {
|
||||
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
||||
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
||||
|
||||
const lock = m.contract("Lock", [unlockTime], {
|
||||
value: lockedAmount,
|
||||
});
|
||||
|
||||
return { lock };
|
||||
});
|
||||
23
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/package.json
generated
vendored
Executable file
23
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/package.json
generated
vendored
Executable file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "template-v2-mocha-ethers-js",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "A Javascript project using Mocha and Ethers.js",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
|
||||
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
||||
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^6.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"ethers": "^6.4.0",
|
||||
"hardhat": "^2.14.0",
|
||||
"hardhat-gas-reporter": "^2.3.0",
|
||||
"solidity-coverage": "^0.8.0",
|
||||
"typechain": "^8.3.0"
|
||||
}
|
||||
}
|
||||
126
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/test/Lock.js
generated
vendored
Executable file
126
dev/env/node_modules/hardhat/templates/hardhat-2/01-mocha-ethers-js/test/Lock.js
generated
vendored
Executable file
@@ -0,0 +1,126 @@
|
||||
const {
|
||||
time,
|
||||
loadFixture,
|
||||
} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
|
||||
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
|
||||
const { expect } = require("chai");
|
||||
|
||||
describe("Lock", function () {
|
||||
// We define a fixture to reuse the same setup in every test.
|
||||
// We use loadFixture to run this setup once, snapshot that state,
|
||||
// and reset Hardhat Network to that snapshot in every test.
|
||||
async function deployOneYearLockFixture() {
|
||||
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
||||
const ONE_GWEI = 1_000_000_000;
|
||||
|
||||
const lockedAmount = ONE_GWEI;
|
||||
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
||||
|
||||
// Contracts are deployed using the first signer/account by default
|
||||
const [owner, otherAccount] = await ethers.getSigners();
|
||||
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
||||
|
||||
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
||||
}
|
||||
|
||||
describe("Deployment", function () {
|
||||
it("Should set the right unlockTime", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.unlockTime()).to.equal(unlockTime);
|
||||
});
|
||||
|
||||
it("Should set the right owner", async function () {
|
||||
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.owner()).to.equal(owner.address);
|
||||
});
|
||||
|
||||
it("Should receive and store the funds to lock", async function () {
|
||||
const { lock, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
expect(await ethers.provider.getBalance(lock.target)).to.equal(
|
||||
lockedAmount,
|
||||
);
|
||||
});
|
||||
|
||||
it("Should fail if the unlockTime is not in the future", async function () {
|
||||
// We don't use the fixture here because we want a different deployment
|
||||
const latestTime = await time.latest();
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
||||
"Unlock time should be in the future",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Withdrawals", function () {
|
||||
describe("Validations", function () {
|
||||
it("Should revert with the right error if called too soon", async function () {
|
||||
const { lock } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await expect(lock.withdraw()).to.be.revertedWith(
|
||||
"You can't withdraw yet",
|
||||
);
|
||||
});
|
||||
|
||||
it("Should revert with the right error if called from another account", async function () {
|
||||
const { lock, unlockTime, otherAccount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// We can increase the time in Hardhat Network
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
// We use lock.connect() to send a transaction from another account
|
||||
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
||||
"You aren't the owner",
|
||||
);
|
||||
});
|
||||
|
||||
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// Transactions are sent using the first signer by default
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).not.to.be.reverted;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("Should emit an event on withdrawals", async function () {
|
||||
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw())
|
||||
.to.emit(lock, "Withdrawal")
|
||||
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
||||
});
|
||||
});
|
||||
|
||||
describe("Transfers", function () {
|
||||
it("Should transfer the funds to the owner", async function () {
|
||||
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).to.changeEtherBalances(
|
||||
[owner, lock],
|
||||
[lockedAmount, -lockedAmount],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
13
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/README.md
generated
vendored
Executable file
13
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/README.md
generated
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
# Sample Hardhat Project
|
||||
|
||||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
||||
|
||||
Try running some of the following tasks:
|
||||
|
||||
```shell
|
||||
npx hardhat help
|
||||
npx hardhat test
|
||||
REPORT_GAS=true npx hardhat test
|
||||
npx hardhat node
|
||||
npx hardhat ignition deploy ./ignition/modules/Lock.js
|
||||
```
|
||||
34
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/contracts/Lock.sol
generated
vendored
Executable file
34
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/contracts/Lock.sol
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
// Uncomment this line to use console.log
|
||||
// import "hardhat/console.sol";
|
||||
|
||||
contract Lock {
|
||||
uint public unlockTime;
|
||||
address payable public owner;
|
||||
|
||||
event Withdrawal(uint amount, uint when);
|
||||
|
||||
constructor(uint _unlockTime) payable {
|
||||
require(
|
||||
block.timestamp < _unlockTime,
|
||||
"Unlock time should be in the future"
|
||||
);
|
||||
|
||||
unlockTime = _unlockTime;
|
||||
owner = payable(msg.sender);
|
||||
}
|
||||
|
||||
function withdraw() public {
|
||||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
||||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
||||
|
||||
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
||||
require(msg.sender == owner, "You aren't the owner");
|
||||
|
||||
emit Withdrawal(address(this).balance, block.timestamp);
|
||||
|
||||
owner.transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
17
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/gitignore
generated
vendored
Executable file
17
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/gitignore
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
# Hardhat files
|
||||
/cache
|
||||
/artifacts
|
||||
|
||||
# TypeChain files
|
||||
/typechain
|
||||
/typechain-types
|
||||
|
||||
# solidity-coverage files
|
||||
/coverage
|
||||
/coverage.json
|
||||
|
||||
# Hardhat Ignition default folder for deployments against a local node
|
||||
ignition/deployments/chain-31337
|
||||
6
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/hardhat.config.cjs
generated
vendored
Executable file
6
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/hardhat.config.cjs
generated
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
require("@nomicfoundation/hardhat-toolbox");
|
||||
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.28",
|
||||
};
|
||||
18
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/ignition/modules/Lock.js
generated
vendored
Executable file
18
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/ignition/modules/Lock.js
generated
vendored
Executable file
@@ -0,0 +1,18 @@
|
||||
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
||||
// Learn more about it at https://hardhat.org/ignition
|
||||
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
|
||||
const JAN_1ST_2030 = 1893456000;
|
||||
const ONE_GWEI = 1_000_000_000n;
|
||||
|
||||
export default buildModule("LockModule", (m) => {
|
||||
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
||||
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
||||
|
||||
const lock = m.contract("Lock", [unlockTime], {
|
||||
value: lockedAmount,
|
||||
});
|
||||
|
||||
return { lock };
|
||||
});
|
||||
24
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/package.json
generated
vendored
Executable file
24
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/package.json
generated
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "template-v2-mocha-ethers-js-esm",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "A Javascript project using Mocha and Ethers.js (ESM)",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
|
||||
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
||||
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^6.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"ethers": "^6.4.0",
|
||||
"hardhat": "^2.14.0",
|
||||
"hardhat-gas-reporter": "^2.3.0",
|
||||
"solidity-coverage": "^0.8.0",
|
||||
"typechain": "^8.3.0"
|
||||
}
|
||||
}
|
||||
128
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/test/Lock.js
generated
vendored
Executable file
128
dev/env/node_modules/hardhat/templates/hardhat-2/02-mocha-ethers-js-esm/test/Lock.js
generated
vendored
Executable file
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
time,
|
||||
loadFixture,
|
||||
} from "@nomicfoundation/hardhat-toolbox/network-helpers.js";
|
||||
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs.js";
|
||||
import chai from "chai";
|
||||
|
||||
const { expect } = chai;
|
||||
|
||||
describe("Lock", function () {
|
||||
// We define a fixture to reuse the same setup in every test.
|
||||
// We use loadFixture to run this setup once, snapshot that state,
|
||||
// and reset Hardhat Network to that snapshot in every test.
|
||||
async function deployOneYearLockFixture() {
|
||||
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
||||
const ONE_GWEI = 1_000_000_000;
|
||||
|
||||
const lockedAmount = ONE_GWEI;
|
||||
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
||||
|
||||
// Contracts are deployed using the first signer/account by default
|
||||
const [owner, otherAccount] = await ethers.getSigners();
|
||||
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
||||
|
||||
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
||||
}
|
||||
|
||||
describe("Deployment", function () {
|
||||
it("Should set the right unlockTime", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.unlockTime()).to.equal(unlockTime);
|
||||
});
|
||||
|
||||
it("Should set the right owner", async function () {
|
||||
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.owner()).to.equal(owner.address);
|
||||
});
|
||||
|
||||
it("Should receive and store the funds to lock", async function () {
|
||||
const { lock, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
expect(await ethers.provider.getBalance(lock.target)).to.equal(
|
||||
lockedAmount,
|
||||
);
|
||||
});
|
||||
|
||||
it("Should fail if the unlockTime is not in the future", async function () {
|
||||
// We don't use the fixture here because we want a different deployment
|
||||
const latestTime = await time.latest();
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
||||
"Unlock time should be in the future",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Withdrawals", function () {
|
||||
describe("Validations", function () {
|
||||
it("Should revert with the right error if called too soon", async function () {
|
||||
const { lock } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await expect(lock.withdraw()).to.be.revertedWith(
|
||||
"You can't withdraw yet",
|
||||
);
|
||||
});
|
||||
|
||||
it("Should revert with the right error if called from another account", async function () {
|
||||
const { lock, unlockTime, otherAccount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// We can increase the time in Hardhat Network
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
// We use lock.connect() to send a transaction from another account
|
||||
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
||||
"You aren't the owner",
|
||||
);
|
||||
});
|
||||
|
||||
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// Transactions are sent using the first signer by default
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).not.to.be.reverted;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("Should emit an event on withdrawals", async function () {
|
||||
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw())
|
||||
.to.emit(lock, "Withdrawal")
|
||||
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
||||
});
|
||||
});
|
||||
|
||||
describe("Transfers", function () {
|
||||
it("Should transfer the funds to the owner", async function () {
|
||||
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).to.changeEtherBalances(
|
||||
[owner, lock],
|
||||
[lockedAmount, -lockedAmount],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
13
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/README.md
generated
vendored
Executable file
13
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/README.md
generated
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
# Sample Hardhat Project
|
||||
|
||||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
||||
|
||||
Try running some of the following tasks:
|
||||
|
||||
```shell
|
||||
npx hardhat help
|
||||
npx hardhat test
|
||||
REPORT_GAS=true npx hardhat test
|
||||
npx hardhat node
|
||||
npx hardhat ignition deploy ./ignition/modules/Lock.ts
|
||||
```
|
||||
34
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/contracts/Lock.sol
generated
vendored
Executable file
34
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/contracts/Lock.sol
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
// Uncomment this line to use console.log
|
||||
// import "hardhat/console.sol";
|
||||
|
||||
contract Lock {
|
||||
uint public unlockTime;
|
||||
address payable public owner;
|
||||
|
||||
event Withdrawal(uint amount, uint when);
|
||||
|
||||
constructor(uint _unlockTime) payable {
|
||||
require(
|
||||
block.timestamp < _unlockTime,
|
||||
"Unlock time should be in the future"
|
||||
);
|
||||
|
||||
unlockTime = _unlockTime;
|
||||
owner = payable(msg.sender);
|
||||
}
|
||||
|
||||
function withdraw() public {
|
||||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
||||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
||||
|
||||
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
||||
require(msg.sender == owner, "You aren't the owner");
|
||||
|
||||
emit Withdrawal(address(this).balance, block.timestamp);
|
||||
|
||||
owner.transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
17
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/gitignore
generated
vendored
Executable file
17
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/gitignore
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
# Hardhat files
|
||||
/cache
|
||||
/artifacts
|
||||
|
||||
# TypeChain files
|
||||
/typechain
|
||||
/typechain-types
|
||||
|
||||
# solidity-coverage files
|
||||
/coverage
|
||||
/coverage.json
|
||||
|
||||
# Hardhat Ignition default folder for deployments against a local node
|
||||
ignition/deployments/chain-31337
|
||||
8
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/hardhat.config.ts
generated
vendored
Executable file
8
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/hardhat.config.ts
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
import type { HardhatUserConfig } from "hardhat/config";
|
||||
import "@nomicfoundation/hardhat-toolbox";
|
||||
|
||||
const config: HardhatUserConfig = {
|
||||
solidity: "0.8.28",
|
||||
};
|
||||
|
||||
export default config;
|
||||
20
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/ignition/modules/Lock.ts
generated
vendored
Executable file
20
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/ignition/modules/Lock.ts
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
||||
// Learn more about it at https://hardhat.org/ignition
|
||||
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
|
||||
const JAN_1ST_2030 = 1893456000;
|
||||
const ONE_GWEI: bigint = 1_000_000_000n;
|
||||
|
||||
const LockModule = buildModule("LockModule", (m) => {
|
||||
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
||||
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
||||
|
||||
const lock = m.contract("Lock", [unlockTime], {
|
||||
value: lockedAmount,
|
||||
});
|
||||
|
||||
return { lock };
|
||||
});
|
||||
|
||||
export default LockModule;
|
||||
28
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/package.json
generated
vendored
Executable file
28
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/package.json
generated
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "template-v2-mocha-ethers-ts",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "A Typescript project using Mocha and Ethers.js",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
|
||||
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
||||
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^6.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"@types/chai": "^4.2.0",
|
||||
"@types/mocha": ">=9.1.0",
|
||||
"@types/node": ">=22.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"ethers": "^6.4.0",
|
||||
"hardhat": "^2.14.0",
|
||||
"hardhat-gas-reporter": "^2.3.0",
|
||||
"solidity-coverage": "^0.8.0",
|
||||
"ts-node": ">=8.0.0",
|
||||
"typechain": "^8.3.0",
|
||||
"typescript": ">=4.5.0"
|
||||
}
|
||||
}
|
||||
127
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/test/Lock.ts
generated
vendored
Executable file
127
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/test/Lock.ts
generated
vendored
Executable file
@@ -0,0 +1,127 @@
|
||||
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
|
||||
import {
|
||||
time,
|
||||
loadFixture,
|
||||
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
|
||||
import { expect } from "chai";
|
||||
import hre from "hardhat";
|
||||
|
||||
describe("Lock", function () {
|
||||
// We define a fixture to reuse the same setup in every test.
|
||||
// We use loadFixture to run this setup once, snapshot that state,
|
||||
// and reset Hardhat Network to that snapshot in every test.
|
||||
async function deployOneYearLockFixture() {
|
||||
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
||||
const ONE_GWEI = 1_000_000_000;
|
||||
|
||||
const lockedAmount = ONE_GWEI;
|
||||
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
||||
|
||||
// Contracts are deployed using the first signer/account by default
|
||||
const [owner, otherAccount] = await hre.ethers.getSigners();
|
||||
|
||||
const Lock = await hre.ethers.getContractFactory("Lock");
|
||||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
||||
|
||||
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
||||
}
|
||||
|
||||
describe("Deployment", function () {
|
||||
it("Should set the right unlockTime", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.unlockTime()).to.equal(unlockTime);
|
||||
});
|
||||
|
||||
it("Should set the right owner", async function () {
|
||||
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.owner()).to.equal(owner.address);
|
||||
});
|
||||
|
||||
it("Should receive and store the funds to lock", async function () {
|
||||
const { lock, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
expect(await hre.ethers.provider.getBalance(lock.target)).to.equal(
|
||||
lockedAmount,
|
||||
);
|
||||
});
|
||||
|
||||
it("Should fail if the unlockTime is not in the future", async function () {
|
||||
// We don't use the fixture here because we want a different deployment
|
||||
const latestTime = await time.latest();
|
||||
const Lock = await hre.ethers.getContractFactory("Lock");
|
||||
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
||||
"Unlock time should be in the future",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Withdrawals", function () {
|
||||
describe("Validations", function () {
|
||||
it("Should revert with the right error if called too soon", async function () {
|
||||
const { lock } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await expect(lock.withdraw()).to.be.revertedWith(
|
||||
"You can't withdraw yet",
|
||||
);
|
||||
});
|
||||
|
||||
it("Should revert with the right error if called from another account", async function () {
|
||||
const { lock, unlockTime, otherAccount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// We can increase the time in Hardhat Network
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
// We use lock.connect() to send a transaction from another account
|
||||
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
||||
"You aren't the owner",
|
||||
);
|
||||
});
|
||||
|
||||
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// Transactions are sent using the first signer by default
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).not.to.be.reverted;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("Should emit an event on withdrawals", async function () {
|
||||
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw())
|
||||
.to.emit(lock, "Withdrawal")
|
||||
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
||||
});
|
||||
});
|
||||
|
||||
describe("Transfers", function () {
|
||||
it("Should transfer the funds to the owner", async function () {
|
||||
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).to.changeEtherBalances(
|
||||
[owner, lock],
|
||||
[lockedAmount, -lockedAmount],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
11
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/tsconfig.json
generated
vendored
Executable file
11
dev/env/node_modules/hardhat/templates/hardhat-2/03-mocha-ethers-ts/tsconfig.json
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
||||
13
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/README.md
generated
vendored
Executable file
13
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/README.md
generated
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
# Sample Hardhat Project
|
||||
|
||||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.
|
||||
|
||||
Try running some of the following tasks:
|
||||
|
||||
```shell
|
||||
npx hardhat help
|
||||
npx hardhat test
|
||||
REPORT_GAS=true npx hardhat test
|
||||
npx hardhat node
|
||||
npx hardhat ignition deploy ./ignition/modules/Lock.ts
|
||||
```
|
||||
34
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/contracts/Lock.sol
generated
vendored
Executable file
34
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/contracts/Lock.sol
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
// Uncomment this line to use console.log
|
||||
// import "hardhat/console.sol";
|
||||
|
||||
contract Lock {
|
||||
uint public unlockTime;
|
||||
address payable public owner;
|
||||
|
||||
event Withdrawal(uint amount, uint when);
|
||||
|
||||
constructor(uint _unlockTime) payable {
|
||||
require(
|
||||
block.timestamp < _unlockTime,
|
||||
"Unlock time should be in the future"
|
||||
);
|
||||
|
||||
unlockTime = _unlockTime;
|
||||
owner = payable(msg.sender);
|
||||
}
|
||||
|
||||
function withdraw() public {
|
||||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
|
||||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
|
||||
|
||||
require(block.timestamp >= unlockTime, "You can't withdraw yet");
|
||||
require(msg.sender == owner, "You aren't the owner");
|
||||
|
||||
emit Withdrawal(address(this).balance, block.timestamp);
|
||||
|
||||
owner.transfer(address(this).balance);
|
||||
}
|
||||
}
|
||||
17
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/gitignore
generated
vendored
Executable file
17
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/gitignore
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
# Hardhat files
|
||||
/cache
|
||||
/artifacts
|
||||
|
||||
# TypeChain files
|
||||
/typechain
|
||||
/typechain-types
|
||||
|
||||
# solidity-coverage files
|
||||
/coverage
|
||||
/coverage.json
|
||||
|
||||
# Hardhat Ignition default folder for deployments against a local node
|
||||
ignition/deployments/chain-31337
|
||||
8
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/hardhat.config.ts
generated
vendored
Executable file
8
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/hardhat.config.ts
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
import type { HardhatUserConfig } from "hardhat/config";
|
||||
import "@nomicfoundation/hardhat-toolbox-viem";
|
||||
|
||||
const config: HardhatUserConfig = {
|
||||
solidity: "0.8.28",
|
||||
};
|
||||
|
||||
export default config;
|
||||
21
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/ignition/modules/Lock.ts
generated
vendored
Executable file
21
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/ignition/modules/Lock.ts
generated
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
// This setup uses Hardhat Ignition to manage smart contract deployments.
|
||||
// Learn more about it at https://hardhat.org/ignition
|
||||
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import { parseEther } from "viem";
|
||||
|
||||
const JAN_1ST_2030 = 1893456000;
|
||||
const ONE_GWEI: bigint = parseEther("0.001");
|
||||
|
||||
const LockModule = buildModule("LockModule", (m) => {
|
||||
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
|
||||
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
|
||||
|
||||
const lock = m.contract("Lock", [unlockTime], {
|
||||
value: lockedAmount,
|
||||
});
|
||||
|
||||
return { lock };
|
||||
});
|
||||
|
||||
export default LockModule;
|
||||
25
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/package.json
generated
vendored
Executable file
25
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/package.json
generated
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "template-v2-mocha-viem-ts",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "A Typescript project using Mocha and Viem",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-ignition": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-ignition-viem": "^0.15.0",
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox-viem": "^4.1.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@nomicfoundation/hardhat-viem": "^2.0.0",
|
||||
"@types/chai": "^4.2.0",
|
||||
"@types/chai-as-promised": "^7.1.6",
|
||||
"@types/mocha": ">=9.1.0",
|
||||
"@types/node": ">=22.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"hardhat": "^2.14.0",
|
||||
"hardhat-gas-reporter": "^2.3.0",
|
||||
"solidity-coverage": "^0.8.0",
|
||||
"ts-node": ">=8.0.0",
|
||||
"typescript": "~5.0.4",
|
||||
"viem": "^2.43.0"
|
||||
}
|
||||
}
|
||||
134
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/test/Lock.ts
generated
vendored
Executable file
134
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/test/Lock.ts
generated
vendored
Executable file
@@ -0,0 +1,134 @@
|
||||
import {
|
||||
time,
|
||||
loadFixture,
|
||||
} from "@nomicfoundation/hardhat-toolbox-viem/network-helpers";
|
||||
import { expect } from "chai";
|
||||
import hre from "hardhat";
|
||||
import { getAddress, parseGwei } from "viem";
|
||||
|
||||
describe("Lock", function () {
|
||||
// We define a fixture to reuse the same setup in every test.
|
||||
// We use loadFixture to run this setup once, snapshot that state,
|
||||
// and reset Hardhat Network to that snapshot in every test.
|
||||
async function deployOneYearLockFixture() {
|
||||
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
||||
|
||||
const lockedAmount = parseGwei("1");
|
||||
const unlockTime = BigInt((await time.latest()) + ONE_YEAR_IN_SECS);
|
||||
|
||||
// Contracts are deployed using the first signer/account by default
|
||||
const [owner, otherAccount] = await hre.viem.getWalletClients();
|
||||
|
||||
const lock = await hre.viem.deployContract("Lock", [unlockTime], {
|
||||
value: lockedAmount,
|
||||
});
|
||||
|
||||
const publicClient = await hre.viem.getPublicClient();
|
||||
|
||||
return {
|
||||
lock,
|
||||
unlockTime,
|
||||
lockedAmount,
|
||||
owner,
|
||||
otherAccount,
|
||||
publicClient,
|
||||
};
|
||||
}
|
||||
|
||||
describe("Deployment", function () {
|
||||
it("Should set the right unlockTime", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.read.unlockTime()).to.equal(unlockTime);
|
||||
});
|
||||
|
||||
it("Should set the right owner", async function () {
|
||||
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.read.owner()).to.equal(
|
||||
getAddress(owner.account.address),
|
||||
);
|
||||
});
|
||||
|
||||
it("Should receive and store the funds to lock", async function () {
|
||||
const { lock, lockedAmount, publicClient } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
expect(
|
||||
await publicClient.getBalance({
|
||||
address: lock.address,
|
||||
}),
|
||||
).to.equal(lockedAmount);
|
||||
});
|
||||
|
||||
it("Should fail if the unlockTime is not in the future", async function () {
|
||||
// We don't use the fixture here because we want a different deployment
|
||||
const latestTime = BigInt(await time.latest());
|
||||
await expect(
|
||||
hre.viem.deployContract("Lock", [latestTime], {
|
||||
value: 1n,
|
||||
}),
|
||||
).to.be.rejectedWith("Unlock time should be in the future");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Withdrawals", function () {
|
||||
describe("Validations", function () {
|
||||
it("Should revert with the right error if called too soon", async function () {
|
||||
const { lock } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await expect(lock.write.withdraw()).to.be.rejectedWith(
|
||||
"You can't withdraw yet",
|
||||
);
|
||||
});
|
||||
|
||||
it("Should revert with the right error if called from another account", async function () {
|
||||
const { lock, unlockTime, otherAccount } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// We can increase the time in Hardhat Network
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
// We retrieve the contract with a different account to send a transaction
|
||||
const lockAsOtherAccount = await hre.viem.getContractAt(
|
||||
"Lock",
|
||||
lock.address,
|
||||
{ client: { wallet: otherAccount } },
|
||||
);
|
||||
await expect(lockAsOtherAccount.write.withdraw()).to.be.rejectedWith(
|
||||
"You aren't the owner",
|
||||
);
|
||||
});
|
||||
|
||||
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(
|
||||
deployOneYearLockFixture,
|
||||
);
|
||||
|
||||
// Transactions are sent using the first signer by default
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.write.withdraw()).to.be.fulfilled;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("Should emit an event on withdrawals", async function () {
|
||||
const { lock, unlockTime, lockedAmount, publicClient } =
|
||||
await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
const hash = await lock.write.withdraw();
|
||||
await publicClient.waitForTransactionReceipt({ hash });
|
||||
|
||||
// get the withdrawal events in the latest block
|
||||
const withdrawalEvents = await lock.getEvents.Withdrawal();
|
||||
expect(withdrawalEvents).to.have.lengthOf(1);
|
||||
expect(withdrawalEvents[0].args.amount).to.equal(lockedAmount);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
11
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/tsconfig.json
generated
vendored
Executable file
11
dev/env/node_modules/hardhat/templates/hardhat-2/04-mocha-viem-ts/tsconfig.json
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
||||
4
dev/env/node_modules/hardhat/templates/hardhat-2/05-empty-hardhat-config-js/hardhat.config.js
generated
vendored
Executable file
4
dev/env/node_modules/hardhat/templates/hardhat-2/05-empty-hardhat-config-js/hardhat.config.js
generated
vendored
Executable file
@@ -0,0 +1,4 @@
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.28",
|
||||
};
|
||||
9
dev/env/node_modules/hardhat/templates/hardhat-2/05-empty-hardhat-config-js/package.json
generated
vendored
Executable file
9
dev/env/node_modules/hardhat/templates/hardhat-2/05-empty-hardhat-config-js/package.json
generated
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "template-v2-empty-hardhat-config-js",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "An empty config file (hardhat.config.js)",
|
||||
"devDependencies": {
|
||||
"hardhat": "^2.14.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user