FoundryTesting/test/Counter.t.sol

35 lines
726 B
Solidity
Raw Permalink Normal View History

2023-07-27 06:12:00 +00:00
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
2023-08-20 06:57:02 +00:00
import {Test, stdError} from "forge-std/Test.sol";
2023-07-27 06:12:00 +00:00
import {Counter} from "../src/Counter.sol";
contract CounterTest is Test {
Counter public counter;
function setUp() public {
counter = new Counter();
}
2023-08-20 06:57:02 +00:00
function testInc() public {
counter.inc();
assertEq(counter.count(), 1);
2023-07-27 06:12:00 +00:00
}
2023-08-20 06:57:02 +00:00
function testFailDec() public {
counter.dec();
}
2023-08-24 06:19:29 +00:00
2023-08-20 06:57:02 +00:00
function testDecUnderFlow() public {
vm.expectRevert(stdError.arithmeticError);
counter.dec();
}
function testDec() public {
counter.inc();
counter.inc();
counter.dec();
assertEq(counter.count(), 1);
2023-07-27 06:12:00 +00:00
}
}