endstep2
This commit is contained in:
19
tokenizerRendu/code/contracts/Counter.sol
Normal file
19
tokenizerRendu/code/contracts/Counter.sol
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.34;
|
||||
|
||||
contract Counter {
|
||||
uint public x;
|
||||
|
||||
event Increment(uint by);
|
||||
|
||||
function inc() public {
|
||||
x++;
|
||||
emit Increment(1);
|
||||
}
|
||||
|
||||
function incBy(uint by) public {
|
||||
require(by > 0, "incBy: increment should be positive");
|
||||
x += by;
|
||||
emit Increment(by);
|
||||
}
|
||||
}
|
||||
32
tokenizerRendu/code/contracts/Counter.t.sol
Normal file
32
tokenizerRendu/code/contracts/Counter.t.sol
Normal file
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.34;
|
||||
|
||||
import {Counter} from "./Counter.sol";
|
||||
import {Test} from "forge-std/Test.sol";
|
||||
|
||||
// Solidity tests are compatible with foundry, so they
|
||||
// use the same syntax and offer the same functionality.
|
||||
|
||||
contract CounterTest is Test {
|
||||
Counter counter;
|
||||
|
||||
function setUp() public {
|
||||
counter = new Counter();
|
||||
}
|
||||
|
||||
function test_InitialValue() public view {
|
||||
require(counter.x() == 0, "Initial value should be 0");
|
||||
}
|
||||
|
||||
function testFuzz_Inc(uint8 x) public {
|
||||
for (uint8 i = 0; i < x; i++) {
|
||||
counter.inc();
|
||||
}
|
||||
require(counter.x() == x, "Value after calling inc x times should be x");
|
||||
}
|
||||
|
||||
function test_IncByZero() public {
|
||||
vm.expectRevert();
|
||||
counter.incBy(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user