Skip to content

Commit e6fb416

Browse files
committed
simple storage example
1 parent e8171ff commit e6fb416

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/SimpleStorage.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.12;
4+
5+
contract SimpleStorage {
6+
uint8 public storedData;
7+
8+
function setAddition(uint8 x) public {
9+
storedData = x * 2;
10+
}
11+
}

test/SimpleStorageTest.t.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import "forge-std/Test.sol";
5+
import "../src/SimpleStorage.sol";
6+
7+
contract SimplestorageTest is Test {
8+
SimpleStorage simpleStorage;
9+
10+
function setUp() public {
11+
simpleStorage = new SimpleStorage();
12+
}
13+
14+
function testSetAdditionValid() public {
15+
uint8 testValue = 128; // This value we want to test.
16+
console.log("Test value is: ", testValue);
17+
simpleStorage.setAddition(testValue);
18+
assert(simpleStorage.storedData() < 255);
19+
console.log("Stored data is: ", simpleStorage.storedData());
20+
}
21+
22+
function testSetAdditionValidFuzz(uint8 testValue) public {
23+
// uint8 testValue = 128; Commented value
24+
console.log("Test value is: ", testValue);
25+
simpleStorage.setAddition(testValue);
26+
assert(simpleStorage.storedData() < 255);
27+
console.log("Stored data is: ", simpleStorage.storedData());
28+
}
29+
}

0 commit comments

Comments
 (0)