Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions regression/revert/hardhat/Makefile
Original file line number Diff line number Diff line change
@@ -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."
22 changes: 22 additions & 0 deletions regression/revert/hardhat/contracts/Revert_v1.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 28 additions & 0 deletions regression/revert/hardhat/test/test.js
Original file line number Diff line number Diff line change
@@ -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);
})
})