diff --git a/regression/revert/hardhat/Makefile b/regression/revert/hardhat/Makefile new file mode 100644 index 00000000..c49b2687 --- /dev/null +++ b/regression/revert/hardhat/Makefile @@ -0,0 +1,33 @@ +SHELL := /bin/bash + +.PHONY: init test clean + +default: test + +init: + @if [ -f hardhat.config.js ]; then \ + echo "Skipping: Hardhat already initialized."; \ + else \ + echo "Initializing Hardhat project..."; \ + npm init -y >/dev/null && \ + npm install --save-dev hardhat --silent --no-progress >/dev/null && \ + printf '3\n' | npx hardhat init && \ + npm install --save-dev @nomicfoundation/hardhat-toolbox --silent --no-progress >/dev/null && \ + if ! grep -q '@nomicfoundation/hardhat-toolbox' hardhat.config.js; then \ + sed -i '1irequire("@nomicfoundation/hardhat-toolbox")\n' hardhat.config.js; \ + fi; \ + echo "Done."; \ + fi + +test: init + npx hardhat test + + +clean: + @echo "Cleaning project (preserving Makefile, contracts/, and test/)..." + @find . -mindepth 1 -maxdepth 1 \ + ! -name 'Makefile' \ + ! -name 'contracts' \ + ! -name 'test' \ + -exec rm -rf {} + + @echo "Clean complete." diff --git a/regression/revert/hardhat/contracts/Revert_v1.sol b/regression/revert/hardhat/contracts/Revert_v1.sol new file mode 100644 index 00000000..3050c8e7 --- /dev/null +++ b/regression/revert/hardhat/contracts/Revert_v1.sol @@ -0,0 +1,22 @@ +//https://github.com/leonardoalt/cav_2022_artifact/blob/main/regression/control_flow/revert_complex_flow.sol +pragma solidity ^0.8.25; + +contract Revert { + uint c; + uint x; + function f(bool b, uint a) public { + require(a <= 256); + x = a; + if (b) + revert(); + c = a + 1; + if (b) + c--; + else + c++; + } + + function get_c () public view returns (uint) { + return c; + } +} \ No newline at end of file diff --git a/regression/revert/hardhat/test/test.js b/regression/revert/hardhat/test/test.js new file mode 100644 index 00000000..bf2ba117 --- /dev/null +++ b/regression/revert/hardhat/test/test.js @@ -0,0 +1,28 @@ +const { + loadFixture, +} = require("@nomicfoundation/hardhat-toolbox/network-helpers"); +const { expect } = require("chai"); + + +describe("Revert", function () { + async function deployContract () { + const Revert = await ethers.deployContract("Revert"); + + return { Revert }; + } + + it("c-equals-a-with-b-true", async function () { + const { Revert } = await loadFixture(deployContract); + const a = 12; + + + await expect(Revert.f(true, a)).to.be.reverted; + }) + + it("c-equals-a-with-b-false", async function() { + const { Revert } = await loadFixture(deployContract); + const a = 12; + await Revert.f(false, a); + expect(await Revert.get_c()).to.not.be.equal(a); + }) +}) \ No newline at end of file