From cc2be7e92fb1a3877f4f848c71fca4ba29432325 Mon Sep 17 00:00:00 2001 From: jayydy Date: Mon, 28 Jul 2025 22:29:52 +0100 Subject: [PATCH 1/3] set multiple transactions --- package-lock.json | 14 ++++++-------- package.json | 7 ++++--- test/Counter.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 656a34f..7d1d93d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "hardhat-project", "devDependencies": { "@nomicfoundation/hardhat-toolbox": "^5.0.0", + "@types/minimatch": "^5.1.2", "hardhat": "^2.26.1" } }, @@ -1113,6 +1114,7 @@ "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-toolbox/-/hardhat-toolbox-5.0.0.tgz", "integrity": "sha512-FnUtUC5PsakCbwiVNsqlXVIWG5JIb5CEZoSXbJUsEBun22Bivx2jhF1/q9iQbzuaGpJKFQyOhemPB2+XlEE6pQ==", "dev": true, + "license": "MIT", "peerDependencies": { "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", "@nomicfoundation/hardhat-ethers": "^3.0.0", @@ -1678,15 +1680,11 @@ } }, "node_modules/@types/minimatch": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-6.0.0.tgz", - "integrity": "sha512-zmPitbQ8+6zNutpwgcQuLcsEpn/Cj54Kbn7L5pX0Os5kdWplB7xPgEh/g+SWOB/qmows2gpuCaPyduq8ZZRnxA==", - "deprecated": "This is a stub types definition. minimatch provides its own type definitions, so you do not need this installed.", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", "dev": true, - "peer": true, - "dependencies": { - "minimatch": "*" - } + "license": "MIT" }, "node_modules/@types/mocha": { "version": "10.0.10", diff --git a/package.json b/package.json index 0586079..d58dca8 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,12 @@ "name": "hardhat-project", "devDependencies": { "@nomicfoundation/hardhat-toolbox": "^5.0.0", + "@types/minimatch": "^5.1.2", "hardhat": "^2.26.1" - }, + }, "scripts": { - "test": "npx hardhat test", - "compile": "npx hardhat compile", + "test": "npx hardhat test", + "compile": "npx hardhat compile", "node": "npx hardhat node" } } diff --git a/test/Counter.js b/test/Counter.js index 99b2931..ab3438b 100644 --- a/test/Counter.js +++ b/test/Counter.js @@ -30,19 +30,57 @@ describe("Counter Test Suite", () => { let count2 = await counter.getCount(); // check initial count value before txn expect(count2).to.eq(10) // check final count = 10 }) - + it("Should set appropriate values for multiple setCount txns", async () => { - + const counter = await loadFixture(deployCounter); + let count1 = await counter.getCount(); + expect(count1).to.eq(0); + await counter.setCount(10) + + let count2 = await counter.getCount(); + expect(count2).to.eq(10); + await counter.setCount(20) + + let count3 = await counter.getCount(); + expect(count3).to.eq(20); + await counter.setCount(30) + + let count4 = await counter.getCount(); + expect(count4).to.eq(30) + }) }) describe("IncreaseCountByOne", () => { it("Should set appropriate increaseCountByOne value", async () => { - + const counter = await loadFixture(deployCounter); + let count4 = await counter.getCount(); + expect(count4).to.eq(0); + + await counter.increaseCountByOne(); + let inccount = await counter.getCount(); + expect(inccount).to.eq(1) }) it("Should set appropriate values for multiple increaseCountByOne txns", async () => { + const counter = await loadFixture(deployCounter); + let count = await counter.getCount(); + expect(count).to.eq(0); + + await counter.increaseCountByOne(); + let inccount = await counter.getCount(); + expect(inccount).to.eq(1); + + await counter.increaseCountByOne(); + let inccount2 = await counter.getCount(); + expect(inccount2).to.eq(2); + + await counter.increaseCountByOne(); + let inccount3 = await counter.getCount(); + expect(inccount3).to.eq(3); + + }) }) }) From 24912cb6aef64555618cab3400fad2b1b4f3a4ff Mon Sep 17 00:00:00 2001 From: jayydy Date: Mon, 28 Jul 2025 22:53:38 +0100 Subject: [PATCH 2/3] feat:sub contract utilizing decrease function --- contracts/Counter.sol | 48 ------ contracts/CounterV2.sol | 121 ++++++++++++++ test/Counter.js | 87 ---------- test/CounterV2.js | 345 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+), 135 deletions(-) delete mode 100644 contracts/Counter.sol create mode 100644 contracts/CounterV2.sol delete mode 100644 test/Counter.js create mode 100644 test/CounterV2.js diff --git a/contracts/Counter.sol b/contracts/Counter.sol deleted file mode 100644 index fa8560c..0000000 --- a/contracts/Counter.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.28; - -interface ICounter { - function setCount(uint256 _count) external; - function increaseCountByOne() external; - function getCount() external view returns(uint256); - -} - -contract Counter is ICounter { - uint256 public count; - - function setCount(uint256 _count) external { - count = _count; - } - - function increaseCountByOne() public { - count += 1; - } - - function getCount() public view returns(uint256) { - return count; - } -} - - -// contract F { -// // Initializing interface IC -// IC public _ic; -// // Initializing the contract address -// address public contractCAddress; - -// constructor(address _contractCAddress) { -// // Set the contract address to the state variable contract address -// contractCAddress = _contractCAddress; -// // Passing the contract address into interface using the address instance of another contract -// _ic = IC(_contractCAddress); -// } - -// function setCount(uint256 _count) public { -// _ic.setCount(_count); -// } - -// function getCount() public view returns(uint256) { -// return _ic.getCount(); -// } -// } \ No newline at end of file diff --git a/contracts/CounterV2.sol b/contracts/CounterV2.sol new file mode 100644 index 0000000..463687a --- /dev/null +++ b/contracts/CounterV2.sol @@ -0,0 +1,121 @@ + + +// interface ICounter { +// function setCount(uint256 _count) external; +// function getCount() external view returns(uint256); +// function decreaseCountByOne() external; +// function resetCount() external returns(uint256); + +// } + +// contract CounterV2 is ICounter { + +// uint public count; +// address public caller; + +// constructor(address _caller){ +// caller = _caller; +// } + +// function setCount(uint256 _count) external { +// require(count <= 0, "Count already has input value"); +// require(caller == msg.sender, "Wrong caller"); +// count = _count; +// } + +// function getCount() external view returns(uint256){ +// return count; +// } + +// function increaseCountByOne() public { +// require(caller == msg.sender, "Wrong caller"); +// require(count >= 0, "Count value is indefinite"); +// count += 1; +// } + +// function decreaseCountByOne() public { +// count -= 1; +// } + +// function resetCount () external returns (uint){ +// require (caller == msg.sender, "Wrong caller"); +// require(count > 0, "Count value is empty"); +// count = 0; +// return count; +// } + +// } + +// contract CounterV2Caller { + +// ICounter public ic; +// address public contractAddress; + +// constructor(address _contractAddress){ +// contractAddress = _contractAddress; +// ic = ICounter(_contractAddress); +// } + +// function decreaseCountByOne() public { +// ic.decreaseCountByOne(); +// } +// } + + +// SPDX-License-Identifier: MIT + +pragma solidity >= 0.7.0 < 0.9.0; + +interface ICounterV2{ + function setCount(uint256 _count) external; + function getCount() external view returns(uint256); + function resetCount() external; + function decrementCount() external; +} + +contract CounterV2 is ICounterV2{ + address public owner; + uint256 public count; + + constructor(){ + owner = msg.sender; + } + + function setCount(uint256 _count) external { + require(msg.sender == owner, "Unauthorized Caller"); + require(_count > 0, "Cannot pass zero value as argument"); + + count = _count; + } + + function getCount() external view returns(uint256) { + return count; + } + + function resetCount() external { + require(msg.sender == owner, "Unauthorized Caller"); + if (count > 0) { + count = 0; + } + } + + function decrementCount() external { + count -= 1; + } +} + +contract CounterV2Caller { + ICounterV2 public _iCounterV2; + address public contractCounterV2Address; + + constructor(address _contractCounterV2Address) { + contractCounterV2Address = _contractCounterV2Address; + _iCounterV2 = ICounterV2(_contractCounterV2Address); + } + + function callDecrement() external { + _iCounterV2.decrementCount(); + } +} + + diff --git a/test/Counter.js b/test/Counter.js deleted file mode 100644 index ab3438b..0000000 --- a/test/Counter.js +++ /dev/null @@ -1,87 +0,0 @@ -const {loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers"); -// const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs"); -const { expect } = require("chai"); - -// util functon -const deployCounter = async () => { - // target the Counter contract within our contract folder - const CounterContract = await ethers.getContractFactory("Counter"); // target Counter.sol - const counter = await CounterContract.deploy(); // deploy the Counter contract - return counter ; // return the deployed instance of our counter contract -} - -// Counter Test Suite -describe("Counter Test Suite", () => { - describe("Deployment", () => { - it("Should return default values upon deployment", async () => { - const counter = await loadFixture(deployCounter); - expect(await counter.count()).to.eq(0); // assert that count = 0 upon deployment - }) - }) - - describe("Transactions", () => { - describe("SetCount", () => { - it("Should set appropriate count values", async () => { - const counter = await loadFixture(deployCounter); // extract deployed counter instace - let count1 = await counter.getCount(); // check initial count value before txn - expect(count1).to.eq(0); - await counter.setCount(10) // assert that count = 0 upon deployment - - let count2 = await counter.getCount(); // check initial count value before txn - expect(count2).to.eq(10) // check final count = 10 - }) - - it("Should set appropriate values for multiple setCount txns", async () => { - const counter = await loadFixture(deployCounter); - let count1 = await counter.getCount(); - expect(count1).to.eq(0); - await counter.setCount(10) - - let count2 = await counter.getCount(); - expect(count2).to.eq(10); - await counter.setCount(20) - - let count3 = await counter.getCount(); - expect(count3).to.eq(20); - await counter.setCount(30) - - let count4 = await counter.getCount(); - expect(count4).to.eq(30) - - }) - }) - - describe("IncreaseCountByOne", () => { - it("Should set appropriate increaseCountByOne value", async () => { - const counter = await loadFixture(deployCounter); - let count4 = await counter.getCount(); - expect(count4).to.eq(0); - - await counter.increaseCountByOne(); - let inccount = await counter.getCount(); - expect(inccount).to.eq(1) - }) - - it("Should set appropriate values for multiple increaseCountByOne txns", async () => { - const counter = await loadFixture(deployCounter); - let count = await counter.getCount(); - expect(count).to.eq(0); - - await counter.increaseCountByOne(); - let inccount = await counter.getCount(); - expect(inccount).to.eq(1); - - await counter.increaseCountByOne(); - let inccount2 = await counter.getCount(); - expect(inccount2).to.eq(2); - - await counter.increaseCountByOne(); - let inccount3 = await counter.getCount(); - expect(inccount3).to.eq(3); - - - - }) - }) - }) -}) \ No newline at end of file diff --git a/test/CounterV2.js b/test/CounterV2.js new file mode 100644 index 0000000..d84967b --- /dev/null +++ b/test/CounterV2.js @@ -0,0 +1,345 @@ +// const {loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers"); +// // const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs"); +// const { expect } = require("chai"); +// const { ethers } = require("hardhat"); + + +// // // util function +// // const deployCounter = async () => { +// // const CounterContract = await ethers.getContractFactory("CounterV2"); +// // const counterV2 = await CounterContract.deploy(); +// // return counterV2; +// // } + +// // // Counter Test Suite +// // describe("Counter Test Suite", () => { +// // describe("Deployment", () => { +// // it("Should return default values upon deployment", async () => { +// // const counterV2 = await loadFixture(deployCounter); +// // expect(await counterV2.count()).to.eq(0); +// // }) +// // }) + + +// // describe("Transactions", () => { +// // describe("SetCount", () => { +// // it("Should set appropriate count values", async () => { +// // const counterV2 = await loadFixture(deployCounter); +// // let count1 = await counterV2.getCount(); +// // expect(count1).to.eq(0); + +// // await counterV2.setCount(20) + +// // let count2 = await counterV2.getCount(); +// // expect(count2).to.eq(20) + +// // }) +// // }) + +// // describe("IncreaseCountByOne", () => { +// // it("Should set appropriate increaseCountByOne value", async () => { +// // const counter = await loadFixture(deployCounter); +// // let count2 = await counter.setCount(); +// // expect(count2).to.eq(20); + +// // await counter.increaseCountByOne(); +// // let inccount = await counter.getCount(); +// // expect(inccount).to.eq(1) +// // }) +// // }) + +// // describe("resetCount", () => { +// // it("Should reset current count value", async () => { +// // const counterV2 = await loadFixture(deployCounter); + +// // await counterV2.setCount(20); +// // let count2 = await counterV2.getCount(); +// // expect(count2).to.eq(20); + +// // await counterV2.resetCount(); +// // let retCount = counterV2.getCount; +// // expect(retCount).to.eq(0) +// // }) +// // }) + +// // describe("CounterCallerV2", () => async function () { + + +// // it("should decrease count by one via caller contract", async () => { +// // const counterV2 = await loadFixture(deployCounter); +// // await counterV2.setCount(20); + +// // const CallerF = await ethers.getContractFactory("CounterV2Caller"); +// // const counterCaller = await CallerF.deploy(counterV2.target); // or .address in some versions +// // await counterCaller.deployed(); + +// // await counterCaller.decreaseCountByOne(); + +// // const currentCount = await counterV2.getCount(); +// // expect(currentCount).to.eq(19); + +// // }); +// // }) + + + +// // }) +// // }) + + +// // const { expect } = require("chai"); +// // const { ethers } = require("hardhat"); + +// describe("CounterV2 and CounterV2Caller", function () { +// let counterV2, counterV2Caller; +// let owner, other; + +// beforeEach(async () => { +// [owner, other] = await ethers.getSigners(); + +// const CounterV2 = await ethers.getContractFactory("CounterV2"); +// counterV2 = await CounterV2.deploy(owner.address); +// // await counterV2.deployed(); +// await counterV2.deployed(); +// console.log("CounterV2 deployed at:", counterV2.address); + +// const CounterV2Caller = await ethers.getContractFactory("CounterV2Caller"); +// counterV2Caller = await CounterV2Caller.deploy(counterV2.address); +// await counterV2Caller.deployed(); + +// }); + +// describe("CounterV2 basic tests", function () { +// it("should deploy with count 0 and caller as msg.sender", async function () { +// expect(await counterV2.count()).to.equal(0); +// expect(await counterV2.caller()).to.equal(owner.address); +// }); + +// it("should allow caller to set count", async function () { +// await counterV2.setCount(5); +// expect(await counterV2.getCount()).to.equal(5); +// }); + +// it("should not allow non-caller to set count", async function () { +// await expect(counterV2.connect(other).setCount(5)).to.be.revertedWith("Wrong caller"); +// }); + +// it("should not allow setting count more than once", async function () { +// await counterV2.setCount(5); +// await expect(counterV2.setCount(10)).to.be.revertedWith("Count already has input value"); +// }); + +// it("should increase count by one (caller only)", async function () { +// await counterV2.setCount(5); +// await counterV2.increaseCountByOne(); +// expect(await counterV2.getCount()).to.equal(6); +// }); + +// it("should revert increaseCountByOne if called by non-caller", async function () { +// await counterV2.setCount(5); +// await expect(counterV2.connect(other).increaseCountByOne()).to.be.revertedWith("Wrong caller"); +// }); + +// // it("should decrease count by one (no restriction)", async function () { +// // await counterV2.setCount(5); +// // await counterV2.decreaseCountByOne(); +// // expect(await counterV2.getCount()).to.equal(4); +// // }); + +// it("should reset count to zero if > 0 and by caller only", async function () { +// await counterV2.setCount(5); +// const tx = await counterV2.resetCount(); +// await tx.wait(); +// expect(await counterV2.getCount()).to.equal(0); +// }); + +// it("should revert resetCount if called by non-caller", async function () { +// await counterV2.setCount(5); +// await expect(counterV2.connect(other).resetCount()).to.be.revertedWith("Wrong caller"); +// }); + +// it("should revert resetCount if count is already zero", async function () { +// await expect(counterV2.resetCount()).to.be.revertedWith("Count value is empty"); +// }); +// }); + +// describe("CounterV2Caller interaction", function () { +// it("should call decreaseCountByOne through CounterV2Caller", async function () { +// await counterV2.setCount(5); +// await counterV2Caller.decreaseCountByOne(); +// expect(await counterV2.getCount()).to.equal(4); +// }); +// }); +// }); + + +const { + loadFixture, +} = require("@nomicfoundation/hardhat-toolbox/network-helpers"); +// const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs"); +const { expect } = require("chai"); +const { ethers } = require("hardhat"); + +// util functon +const deployCounter = async () => { + // target the CounterV2 contract within our contract folder + const CounterContract1 = await ethers.getContractFactory("CounterV2"); + const counterV2 = await CounterContract1.deploy(); + + // target the CounterV2Caller contract within our contract folder + const CounterContract2 = await ethers.getContractFactory("CounterV2Caller"); + const targetAddress = await counterV2.getAddress(); + // console.log(targetAddress); + + // deploy the contract with the target address we got from calling the getContractFactory() method on the ethers.js library passing in the target contract + const counterV2caller = await CounterContract2.deploy(targetAddress); + + // console.log("This is the counterV2 object:", counterV2); + // console.log("This is the counterV2Caller object:", counterV2caller); + + return { counterV2, counterV2caller }; // Returns the deployed contracts as an object +}; + +// Counter Test Suite +describe("CounterV2 Test Suite", () => { + describe("Deployment", () => { + describe("CounterV2 Deployment", () => { + it("Should return default values upon deployment", async () => { + const { counterV2 } = await loadFixture(deployCounter); + expect(await counterV2.count()).to.eq(0); + }); + }); + }); + + describe("Transactions", () => { + describe("SetCount from counterV2", () => { + it("Should return count value set by user from the counterV2 contract", async () => { + const { counterV2 } = await loadFixture(deployCounter); + let count1 = await counterV2.getCount(); + expect(count1).to.eq(0); + await counterV2.setCount(10); + + let count2 = await counterV2.getCount(); + expect(count2).to.eq(10); + }); + }); + + describe("DecreaseCountByOne", () => { + it("Should decrease the count by one from the contractV2caller contract", async () => { + const { counterV2, counterV2caller } = await loadFixture(deployCounter); + let count1 = await counterV2.getCount(); + expect(count1).to.eq(0); + await counterV2.setCount(10); + + let count2 = await counterV2.getCount(); + expect(count2).to.eq(10); + await counterV2caller.callDecrement(); + + let count3 = await counterV2.getCount(); + expect(count3).to.eq(9); + await counterV2caller.callDecrement(); + + let count4 = await counterV2.getCount(); + expect(count4).to.eq(8); + }); + }); + + describe("ResetCount", () => { + it("Should reset the count set by the user", async () => { + const { counterV2 } = await loadFixture(deployCounter); + let count1 = await counterV2.getCount(); + expect(count1).to.eq(0); + await counterV2.setCount(10); + + let count2 = await counterV2.getCount(); + expect(count2).to.eq(10); + await counterV2.setCount(40); + + let count3 = await counterV2.getCount(); + expect(count3).to.eq(40); + await counterV2.resetCount(); + + let count4 = await counterV2.getCount(); + expect(count4).to.eq(0); + }); + }); + }); + + describe("Reverts", () => { + describe("Unauthorized Caller of the setCount() function", () => { + it("Should revert if the caller is unauthorized", async () => { + const { counterV2 } = await loadFixture(deployCounter); + // console.log(await ethers.getSigners()); + const [, attacker] = await ethers.getSigners(); // This returns an array of accounts object and we destructure immediately to get the second account in the array as the first account is the default deployer/signer of the message + + await expect( + counterV2.connect(attacker).setCount(10) + ).to.be.revertedWith("Unauthorized Caller"); // The .connect(attacker) calls the counterV2 contract instance with a different signer and the ".to.be.revertedWith()" expects the same string message passed in your require statement in the solidity contract function you wrote + }); + }); + + describe("Unauthorized Caller of the resetCount() function", () => { + it("Should revert if the caller is unauthorized", async () => { + const { counterV2 } = await loadFixture(deployCounter); + const [, attacker] = await ethers.getSigners(); + + await counterV2.setCount(20); + await expect( + counterV2.connect(attacker).resetCount() + ).to.be.revertedWith("Unauthorized Caller"); + }); + }); + + describe("Zero value argument in setCount() function", () => { + it("Should revert if the user passes in zero as the argument for the setCount() function", async () => { + const { counterV2 } = await loadFixture(deployCounter); + + await expect(counterV2.setCount(0)).to.be.revertedWith( + "Cannot pass zero value as argument" + ); + }); + }); + }); + + describe("Indirect Interaction", () => { + it("Should successfully decrement count in counterV2 via counterV2Caller", async () => { + const { counterV2, counterV2caller } = await loadFixture(deployCounter); + + await counterV2.setCount(10); + + await counterV2caller.callDecrement(); + + const countAfterChange = await counterV2.count(); + expect(countAfterChange).to.eq(9); + }); + }); +}); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3024b9e4330104bfd308f069fc45c93e17e44bd2 Mon Sep 17 00:00:00 2001 From: jayydy Date: Tue, 29 Jul 2025 20:28:04 +0100 Subject: [PATCH 3/3] Feat: complete transfer and transferFrom tests --- contracts/BlockToken.sol | 39 +++++ contracts/CounterV2.sol | 121 -------------- package-lock.json | 10 ++ package.json | 3 + test/BlockHeaderToken.js | 293 +++++++++++++++++++++++++++++++++ test/CounterV2.js | 345 --------------------------------------- 6 files changed, 345 insertions(+), 466 deletions(-) create mode 100644 contracts/BlockToken.sol delete mode 100644 contracts/CounterV2.sol create mode 100644 test/BlockHeaderToken.js delete mode 100644 test/CounterV2.js diff --git a/contracts/BlockToken.sol b/contracts/BlockToken.sol new file mode 100644 index 0000000..17a84e8 --- /dev/null +++ b/contracts/BlockToken.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.28; + +import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +contract BlockToken is ERC20{ + + address public owner; + + modifier onlyOwner { + require(msg.sender == owner, "BlockToken:: Unauthorized User"); + _; + } + + modifier notAmount0(uint256 _amount){ + require(_amount != 0, "BlockToken:: Zero amount not supported"); + _; + } + constructor(string memory _name, string memory _symbol, address _owner) ERC20(_name, _symbol){ + require(_owner != address(0), "BlockToken:: Zero address not supported"); + owner = _owner; + } + + function mint(uint256 _amount, address _recepient) onlyOwner notAmount0(_amount) external { + _mint(_recepient, _amount); + } + + function burn(uint256 _amount) notAmount0(_amount) external { + _burn(msg.sender, _amount); + } + + function burnFrom(address _user, uint256 _amount)onlyOwner notAmount0(_amount) external { + _burn(_user, _amount); + } + + + + +} \ No newline at end of file diff --git a/contracts/CounterV2.sol b/contracts/CounterV2.sol deleted file mode 100644 index 463687a..0000000 --- a/contracts/CounterV2.sol +++ /dev/null @@ -1,121 +0,0 @@ - - -// interface ICounter { -// function setCount(uint256 _count) external; -// function getCount() external view returns(uint256); -// function decreaseCountByOne() external; -// function resetCount() external returns(uint256); - -// } - -// contract CounterV2 is ICounter { - -// uint public count; -// address public caller; - -// constructor(address _caller){ -// caller = _caller; -// } - -// function setCount(uint256 _count) external { -// require(count <= 0, "Count already has input value"); -// require(caller == msg.sender, "Wrong caller"); -// count = _count; -// } - -// function getCount() external view returns(uint256){ -// return count; -// } - -// function increaseCountByOne() public { -// require(caller == msg.sender, "Wrong caller"); -// require(count >= 0, "Count value is indefinite"); -// count += 1; -// } - -// function decreaseCountByOne() public { -// count -= 1; -// } - -// function resetCount () external returns (uint){ -// require (caller == msg.sender, "Wrong caller"); -// require(count > 0, "Count value is empty"); -// count = 0; -// return count; -// } - -// } - -// contract CounterV2Caller { - -// ICounter public ic; -// address public contractAddress; - -// constructor(address _contractAddress){ -// contractAddress = _contractAddress; -// ic = ICounter(_contractAddress); -// } - -// function decreaseCountByOne() public { -// ic.decreaseCountByOne(); -// } -// } - - -// SPDX-License-Identifier: MIT - -pragma solidity >= 0.7.0 < 0.9.0; - -interface ICounterV2{ - function setCount(uint256 _count) external; - function getCount() external view returns(uint256); - function resetCount() external; - function decrementCount() external; -} - -contract CounterV2 is ICounterV2{ - address public owner; - uint256 public count; - - constructor(){ - owner = msg.sender; - } - - function setCount(uint256 _count) external { - require(msg.sender == owner, "Unauthorized Caller"); - require(_count > 0, "Cannot pass zero value as argument"); - - count = _count; - } - - function getCount() external view returns(uint256) { - return count; - } - - function resetCount() external { - require(msg.sender == owner, "Unauthorized Caller"); - if (count > 0) { - count = 0; - } - } - - function decrementCount() external { - count -= 1; - } -} - -contract CounterV2Caller { - ICounterV2 public _iCounterV2; - address public contractCounterV2Address; - - constructor(address _contractCounterV2Address) { - contractCounterV2Address = _contractCounterV2Address; - _iCounterV2 = ICounterV2(_contractCounterV2Address); - } - - function callDecrement() external { - _iCounterV2.decrementCount(); - } -} - - diff --git a/package-lock.json b/package-lock.json index 7d1d93d..1e3faf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,9 @@ "packages": { "": { "name": "hardhat-project", + "dependencies": { + "@openzeppelin/contracts": "^5.4.0" + }, "devDependencies": { "@nomicfoundation/hardhat-toolbox": "^5.0.0", "@types/minimatch": "^5.1.2", @@ -1307,6 +1310,12 @@ "node": ">= 12" } }, + "node_modules/@openzeppelin/contracts": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.4.0.tgz", + "integrity": "sha512-eCYgWnLg6WO+X52I16TZt8uEjbtdkgLC0SUX/xnAksjjrQI4Xfn4iBRoI5j55dmlOhDv1Y7BoR3cU7e3WWhC6A==", + "license": "MIT" + }, "node_modules/@scure/base": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.2.6.tgz", @@ -3990,6 +3999,7 @@ "resolved": "https://registry.npmjs.org/hardhat/-/hardhat-2.26.1.tgz", "integrity": "sha512-CXWuUaTtehxiHPCdlitntctfeYRgujmXkNX5gnrD5jdA6HhRQt+WWBZE/gHXbE29y/wDmmUL2d652rI0ctjqjw==", "dev": true, + "license": "MIT", "dependencies": { "@ethereumjs/util": "^9.1.0", "@ethersproject/abi": "^5.1.2", diff --git a/package.json b/package.json index d58dca8..3af3ab2 100644 --- a/package.json +++ b/package.json @@ -9,5 +9,8 @@ "test": "npx hardhat test", "compile": "npx hardhat compile", "node": "npx hardhat node" + }, + "dependencies": { + "@openzeppelin/contracts": "^5.4.0" } } diff --git a/test/BlockHeaderToken.js b/test/BlockHeaderToken.js new file mode 100644 index 0000000..ca98006 --- /dev/null +++ b/test/BlockHeaderToken.js @@ -0,0 +1,293 @@ + +const { + loadFixture, +} = require("@nomicfoundation/hardhat-toolbox/network-helpers"); +const { expect } = require("chai"); + +const deployContract = async () => { + let _name = "BlockToken"; + let _symbol = "BCT"; + const [_owner, addr1, addr2] = await ethers.getSigners(); + const BlockTokenContract = await ethers.getContractFactory("BlockToken"); + const BlockToken = await BlockTokenContract.deploy( + _name, + _symbol, + _owner.address + ); + + return { BlockToken, _owner, addr1, addr2, _name, _symbol }; +}; + +describe("BlockToken Test Suite", () => { + describe("Deployment", () => { + it("Should return set values upon deployment", async () => { + const { BlockToken, _name, _symbol, _owner } = await loadFixture( + deployContract + ); + // console.log(_owner.address); + expect(await BlockToken.name()).to.eq(_name); + expect(await BlockToken.symbol()).to.eq(_symbol); + expect(await BlockToken.owner()).to.eq(_owner.address); + }); + + it("Should revert if owner is zero address", async () => { + const BlockTokenContract = await ethers.getContractFactory("BlockToken"); + const zeroAddress = "0x0000000000000000000000000000000000000000"; + + await expect( + BlockTokenContract.deploy("Token", "TKN", zeroAddress) + ).to.be.reverted + }); + }); + + describe("Minting", () => { + it("Should allow only owner to mint", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(10, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(10); + + await expect( + BlockToken.connect(addr1).mint(1000, addr2) + ).to.be.revertedWith("BlockToken:: Unauthorized User"); + }); + + it("Should revert if minting amount is zero", async () => { + const { BlockToken, _owner, addr1 } = await loadFixture(deployContract); + await expect( + BlockToken.connect(_owner).mint(0, addr1) + ).to.be.revertedWith("BlockToken:: Zero amount not supported"); + }); + }); + + describe("Burning", () => { + it("Should not burn if user doesn't have tokens", async () => { + const { BlockToken, _owner, addr1 } = await loadFixture(deployContract); + + await expect( + BlockToken.connect(addr1).burn(1000) + ).to.be.revertedWithCustomError(BlockToken, "ERC20InsufficientBalance"); + }); + + it("Should burn tokens successfully", async () => { + const { BlockToken, _owner } = await loadFixture(deployContract); + + await BlockToken.connect(_owner).mint(1000, _owner); + + const balance = await BlockToken.balanceOf(_owner); + expect(balance).to.eq(1000); + + await BlockToken.connect(_owner).burn(100); + const balance2 = await BlockToken.balanceOf(_owner); + expect(balance2).to.eq(900); + }); + + it("Should allow only owner to burnFrom", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + // Check if address 1 can burn from his address + await expect( + BlockToken.connect(addr1).burnFrom(addr1, 800) + ).to.be.revertedWith("BlockToken:: Unauthorized User"); + + await BlockToken.connect(_owner).mint(900, addr2); + expect(await BlockToken.balanceOf(addr2)).to.eq(900); + + // Check if address 1 can burn from another address + await expect( + BlockToken.connect(addr1).burnFrom(addr2, 800) + ).to.be.revertedWith("BlockToken:: Unauthorized User"); + + // Check if owner can burn from successfully + await BlockToken.connect(_owner).burnFrom(addr1, 200); + + const balance = await BlockToken.balanceOf(addr1); + expect(balance).to.eq(800); + }); + + it("Should not burn zero amount", async () => { + const { BlockToken, _owner, addr1 } = await loadFixture(deployContract); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await expect( + BlockToken.connect(_owner).burnFrom(addr1, 0) + ).to.be.revertedWith("BlockToken:: Zero amount not supported"); + }); + }); + + describe("Transactions", () => { + describe("Transfers", () => { + it("Should transfer tokens from one account to another", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + const zeroAddress = "0x0000000000000000000000000000000000000000"; + + // Transfer to zero address + await expect(BlockToken.connect(_owner).transfer(zeroAddress, 800)).to + .be.reverted; + + await BlockToken.connect(_owner).mint(1000, _owner); + expect(await BlockToken.balanceOf(_owner)).to.eq(1000); + + // Transfer from owner to other account + await BlockToken.connect(_owner).transfer(addr1, 700); + expect(await BlockToken.balanceOf(_owner)).to.eq(300); + expect(await BlockToken.balanceOf(addr1)).to.eq(700); + + // Transfer from account to account + await BlockToken.connect(addr1).transfer(addr2, 400); + expect(await BlockToken.balanceOf(addr1)).to.eq(300); + expect(await BlockToken.balanceOf(addr2)).to.eq(400); + }); + + it("Should transfer tokens less than or equal to balance", async () => { + const { BlockToken, _owner, addr1 } = await loadFixture(deployContract); + + await BlockToken.connect(_owner).mint(1000, _owner); + expect(await BlockToken.balanceOf(_owner)).to.eq(1000); + + await BlockToken.connect(_owner).transfer(addr1, 1000); + expect(await BlockToken.balanceOf(_owner)).to.eq(0); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await expect( + BlockToken.connect(_owner).transfer(addr1, 100) + ).to.be.revertedWithCustomError(BlockToken, "ERC20InsufficientBalance"); + expect(await BlockToken.balanceOf(_owner)).to.eq(0); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + }); + + it("Should approve for transferFrom function", async () => { + const { BlockToken, _owner, addr1 } = await loadFixture(deployContract); + + await BlockToken.connect(_owner).mint(1000, _owner); + expect(await BlockToken.balanceOf(_owner)).to.eq(1000); + + await BlockToken.connect(_owner).approve(addr1, 500); + expect(await BlockToken.allowance(_owner, addr1)).to.eq(500); + }); + + it("Should transferFrom based on approve and allowance", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 500); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 500 + ); + await BlockToken.connect(_owner).transferFrom(addr1, addr2, 400); + + expect(await BlockToken.connect(addr2).balanceOf(addr2)).to.eq(400); + }); + + it("Should revert if balance of 'from' is insufficient", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 500); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 500 + ); + await expect( + BlockToken.connect(_owner).transferFrom(addr1, addr2, 700) + ).to.be.revertedWithCustomError( + BlockToken, + "ERC20InsufficientAllowance" + ); + }); + + it("Should revert if balance of 'from' is insufficient", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 500); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 500 + ); + await expect( + BlockToken.connect(_owner).transferFrom(addr1, addr2, 700) + ).to.be.revertedWithCustomError( + BlockToken, + "ERC20InsufficientAllowance" + ); + }); + + it("Should revert if allowance is zero for spender", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 0); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 0 + ); + await expect( + BlockToken.connect(_owner).transferFrom(addr1, addr2, 700) + ).to.be.revertedWithCustomError( + BlockToken, + "ERC20InsufficientAllowance" + ); + }); + + it("Should revert if address 'to' is address zero", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + const zeroAddress = "0x0000000000000000000000000000000000000000"; + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 500); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 500 + ); + await expect( + BlockToken.connect(_owner).transferFrom(addr1, zeroAddress, 400) + ).to.be.revertedWithCustomError(BlockToken, "ERC20InvalidReceiver"); + }); + + it("Should revert if allowance is increased and not replaced", async () => { + const { BlockToken, _owner, addr1, addr2 } = await loadFixture( + deployContract + ); + + await BlockToken.connect(_owner).mint(1000, addr1); + expect(await BlockToken.balanceOf(addr1)).to.eq(1000); + + await BlockToken.connect(addr1).approve(_owner, 500); + + await BlockToken.connect(addr1).approve(_owner, 700); + expect(await BlockToken.connect(addr1).allowance(addr1, _owner)).to.eq( + 700 + ); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/CounterV2.js b/test/CounterV2.js deleted file mode 100644 index d84967b..0000000 --- a/test/CounterV2.js +++ /dev/null @@ -1,345 +0,0 @@ -// const {loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers"); -// // const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs"); -// const { expect } = require("chai"); -// const { ethers } = require("hardhat"); - - -// // // util function -// // const deployCounter = async () => { -// // const CounterContract = await ethers.getContractFactory("CounterV2"); -// // const counterV2 = await CounterContract.deploy(); -// // return counterV2; -// // } - -// // // Counter Test Suite -// // describe("Counter Test Suite", () => { -// // describe("Deployment", () => { -// // it("Should return default values upon deployment", async () => { -// // const counterV2 = await loadFixture(deployCounter); -// // expect(await counterV2.count()).to.eq(0); -// // }) -// // }) - - -// // describe("Transactions", () => { -// // describe("SetCount", () => { -// // it("Should set appropriate count values", async () => { -// // const counterV2 = await loadFixture(deployCounter); -// // let count1 = await counterV2.getCount(); -// // expect(count1).to.eq(0); - -// // await counterV2.setCount(20) - -// // let count2 = await counterV2.getCount(); -// // expect(count2).to.eq(20) - -// // }) -// // }) - -// // describe("IncreaseCountByOne", () => { -// // it("Should set appropriate increaseCountByOne value", async () => { -// // const counter = await loadFixture(deployCounter); -// // let count2 = await counter.setCount(); -// // expect(count2).to.eq(20); - -// // await counter.increaseCountByOne(); -// // let inccount = await counter.getCount(); -// // expect(inccount).to.eq(1) -// // }) -// // }) - -// // describe("resetCount", () => { -// // it("Should reset current count value", async () => { -// // const counterV2 = await loadFixture(deployCounter); - -// // await counterV2.setCount(20); -// // let count2 = await counterV2.getCount(); -// // expect(count2).to.eq(20); - -// // await counterV2.resetCount(); -// // let retCount = counterV2.getCount; -// // expect(retCount).to.eq(0) -// // }) -// // }) - -// // describe("CounterCallerV2", () => async function () { - - -// // it("should decrease count by one via caller contract", async () => { -// // const counterV2 = await loadFixture(deployCounter); -// // await counterV2.setCount(20); - -// // const CallerF = await ethers.getContractFactory("CounterV2Caller"); -// // const counterCaller = await CallerF.deploy(counterV2.target); // or .address in some versions -// // await counterCaller.deployed(); - -// // await counterCaller.decreaseCountByOne(); - -// // const currentCount = await counterV2.getCount(); -// // expect(currentCount).to.eq(19); - -// // }); -// // }) - - - -// // }) -// // }) - - -// // const { expect } = require("chai"); -// // const { ethers } = require("hardhat"); - -// describe("CounterV2 and CounterV2Caller", function () { -// let counterV2, counterV2Caller; -// let owner, other; - -// beforeEach(async () => { -// [owner, other] = await ethers.getSigners(); - -// const CounterV2 = await ethers.getContractFactory("CounterV2"); -// counterV2 = await CounterV2.deploy(owner.address); -// // await counterV2.deployed(); -// await counterV2.deployed(); -// console.log("CounterV2 deployed at:", counterV2.address); - -// const CounterV2Caller = await ethers.getContractFactory("CounterV2Caller"); -// counterV2Caller = await CounterV2Caller.deploy(counterV2.address); -// await counterV2Caller.deployed(); - -// }); - -// describe("CounterV2 basic tests", function () { -// it("should deploy with count 0 and caller as msg.sender", async function () { -// expect(await counterV2.count()).to.equal(0); -// expect(await counterV2.caller()).to.equal(owner.address); -// }); - -// it("should allow caller to set count", async function () { -// await counterV2.setCount(5); -// expect(await counterV2.getCount()).to.equal(5); -// }); - -// it("should not allow non-caller to set count", async function () { -// await expect(counterV2.connect(other).setCount(5)).to.be.revertedWith("Wrong caller"); -// }); - -// it("should not allow setting count more than once", async function () { -// await counterV2.setCount(5); -// await expect(counterV2.setCount(10)).to.be.revertedWith("Count already has input value"); -// }); - -// it("should increase count by one (caller only)", async function () { -// await counterV2.setCount(5); -// await counterV2.increaseCountByOne(); -// expect(await counterV2.getCount()).to.equal(6); -// }); - -// it("should revert increaseCountByOne if called by non-caller", async function () { -// await counterV2.setCount(5); -// await expect(counterV2.connect(other).increaseCountByOne()).to.be.revertedWith("Wrong caller"); -// }); - -// // it("should decrease count by one (no restriction)", async function () { -// // await counterV2.setCount(5); -// // await counterV2.decreaseCountByOne(); -// // expect(await counterV2.getCount()).to.equal(4); -// // }); - -// it("should reset count to zero if > 0 and by caller only", async function () { -// await counterV2.setCount(5); -// const tx = await counterV2.resetCount(); -// await tx.wait(); -// expect(await counterV2.getCount()).to.equal(0); -// }); - -// it("should revert resetCount if called by non-caller", async function () { -// await counterV2.setCount(5); -// await expect(counterV2.connect(other).resetCount()).to.be.revertedWith("Wrong caller"); -// }); - -// it("should revert resetCount if count is already zero", async function () { -// await expect(counterV2.resetCount()).to.be.revertedWith("Count value is empty"); -// }); -// }); - -// describe("CounterV2Caller interaction", function () { -// it("should call decreaseCountByOne through CounterV2Caller", async function () { -// await counterV2.setCount(5); -// await counterV2Caller.decreaseCountByOne(); -// expect(await counterV2.getCount()).to.equal(4); -// }); -// }); -// }); - - -const { - loadFixture, -} = require("@nomicfoundation/hardhat-toolbox/network-helpers"); -// const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs"); -const { expect } = require("chai"); -const { ethers } = require("hardhat"); - -// util functon -const deployCounter = async () => { - // target the CounterV2 contract within our contract folder - const CounterContract1 = await ethers.getContractFactory("CounterV2"); - const counterV2 = await CounterContract1.deploy(); - - // target the CounterV2Caller contract within our contract folder - const CounterContract2 = await ethers.getContractFactory("CounterV2Caller"); - const targetAddress = await counterV2.getAddress(); - // console.log(targetAddress); - - // deploy the contract with the target address we got from calling the getContractFactory() method on the ethers.js library passing in the target contract - const counterV2caller = await CounterContract2.deploy(targetAddress); - - // console.log("This is the counterV2 object:", counterV2); - // console.log("This is the counterV2Caller object:", counterV2caller); - - return { counterV2, counterV2caller }; // Returns the deployed contracts as an object -}; - -// Counter Test Suite -describe("CounterV2 Test Suite", () => { - describe("Deployment", () => { - describe("CounterV2 Deployment", () => { - it("Should return default values upon deployment", async () => { - const { counterV2 } = await loadFixture(deployCounter); - expect(await counterV2.count()).to.eq(0); - }); - }); - }); - - describe("Transactions", () => { - describe("SetCount from counterV2", () => { - it("Should return count value set by user from the counterV2 contract", async () => { - const { counterV2 } = await loadFixture(deployCounter); - let count1 = await counterV2.getCount(); - expect(count1).to.eq(0); - await counterV2.setCount(10); - - let count2 = await counterV2.getCount(); - expect(count2).to.eq(10); - }); - }); - - describe("DecreaseCountByOne", () => { - it("Should decrease the count by one from the contractV2caller contract", async () => { - const { counterV2, counterV2caller } = await loadFixture(deployCounter); - let count1 = await counterV2.getCount(); - expect(count1).to.eq(0); - await counterV2.setCount(10); - - let count2 = await counterV2.getCount(); - expect(count2).to.eq(10); - await counterV2caller.callDecrement(); - - let count3 = await counterV2.getCount(); - expect(count3).to.eq(9); - await counterV2caller.callDecrement(); - - let count4 = await counterV2.getCount(); - expect(count4).to.eq(8); - }); - }); - - describe("ResetCount", () => { - it("Should reset the count set by the user", async () => { - const { counterV2 } = await loadFixture(deployCounter); - let count1 = await counterV2.getCount(); - expect(count1).to.eq(0); - await counterV2.setCount(10); - - let count2 = await counterV2.getCount(); - expect(count2).to.eq(10); - await counterV2.setCount(40); - - let count3 = await counterV2.getCount(); - expect(count3).to.eq(40); - await counterV2.resetCount(); - - let count4 = await counterV2.getCount(); - expect(count4).to.eq(0); - }); - }); - }); - - describe("Reverts", () => { - describe("Unauthorized Caller of the setCount() function", () => { - it("Should revert if the caller is unauthorized", async () => { - const { counterV2 } = await loadFixture(deployCounter); - // console.log(await ethers.getSigners()); - const [, attacker] = await ethers.getSigners(); // This returns an array of accounts object and we destructure immediately to get the second account in the array as the first account is the default deployer/signer of the message - - await expect( - counterV2.connect(attacker).setCount(10) - ).to.be.revertedWith("Unauthorized Caller"); // The .connect(attacker) calls the counterV2 contract instance with a different signer and the ".to.be.revertedWith()" expects the same string message passed in your require statement in the solidity contract function you wrote - }); - }); - - describe("Unauthorized Caller of the resetCount() function", () => { - it("Should revert if the caller is unauthorized", async () => { - const { counterV2 } = await loadFixture(deployCounter); - const [, attacker] = await ethers.getSigners(); - - await counterV2.setCount(20); - await expect( - counterV2.connect(attacker).resetCount() - ).to.be.revertedWith("Unauthorized Caller"); - }); - }); - - describe("Zero value argument in setCount() function", () => { - it("Should revert if the user passes in zero as the argument for the setCount() function", async () => { - const { counterV2 } = await loadFixture(deployCounter); - - await expect(counterV2.setCount(0)).to.be.revertedWith( - "Cannot pass zero value as argument" - ); - }); - }); - }); - - describe("Indirect Interaction", () => { - it("Should successfully decrement count in counterV2 via counterV2Caller", async () => { - const { counterV2, counterV2caller } = await loadFixture(deployCounter); - - await counterV2.setCount(10); - - await counterV2caller.callDecrement(); - - const countAfterChange = await counterV2.count(); - expect(countAfterChange).to.eq(9); - }); - }); -}); - - - - - - - - - - - - - - - - - - - - - - - - - - - - -