add SimpleStorage smart contract
This commit is contained in:
parent
c7c46dfc2c
commit
ce127dbc28
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
||||
[submodule "hello_foundry/lib/forge-std"]
|
||||
path = hello_foundry/lib/forge-std
|
||||
url = https://github.com/foundry-rs/forge-std
|
||||
[submodule "simple-storage/lib/forge-std"]
|
||||
path = simple-storage/lib/forge-std
|
||||
url = https://github.com/foundry-rs/forge-std
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {Script, console} from "forge-std/Script.sol";
|
||||
import {Counter} from "../src/Counter.sol";
|
||||
|
||||
contract CounterScript is Script {
|
||||
Counter public counter;
|
||||
|
||||
function setUp() public {}
|
||||
|
||||
function run() public {
|
||||
vm.startBroadcast();
|
||||
|
||||
counter = new Counter();
|
||||
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
contract Counter {
|
||||
uint256 public number;
|
||||
|
||||
function setNumber(uint256 newNumber) public {
|
||||
number = newNumber;
|
||||
}
|
||||
|
||||
function increment() public {
|
||||
number++;
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import {Counter} from "../src/Counter.sol";
|
||||
|
||||
contract CounterTest is Test {
|
||||
Counter public counter;
|
||||
|
||||
function setUp() public {
|
||||
counter = new Counter();
|
||||
counter.setNumber(0);
|
||||
}
|
||||
|
||||
function test_Increment() public {
|
||||
counter.increment();
|
||||
assertEq(counter.number(), 1);
|
||||
}
|
||||
|
||||
function testFuzz_SetNumber(uint256 x) public {
|
||||
counter.setNumber(x);
|
||||
assertEq(counter.number(), x);
|
||||
}
|
||||
}
|
||||
21
simple-storage/README_PRVKEY_BEST_PRACTICE.md
Normal file
21
simple-storage/README_PRVKEY_BEST_PRACTICE.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Private Key Best Practice
|
||||
|
||||
Utilize `cast wallet`
|
||||
|
||||
```bash
|
||||
cast wallet import nameOfWalletOrAddress --interactive
|
||||
```
|
||||
|
||||
Then run everything with private key from account
|
||||
|
||||
Previously:
|
||||
|
||||
```bash
|
||||
forge script script/DeploySimpleStorage.s.sol --rpc-url $RPC_URL --broadcast --private-key $PRIVATE_KEY
|
||||
```
|
||||
|
||||
Now:
|
||||
|
||||
```bash
|
||||
forge script script/DeploySimpleStorage.s.sol --rpc-url http://127.0.0.1:8545 --broadcast --account nameOfAccountGoesHere --sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
||||
```
|
||||
15
simple-storage/script/DeploySimpleStorage.s.sol
Normal file
15
simple-storage/script/DeploySimpleStorage.s.sol
Normal file
@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import {Script} from "forge-std/Script.sol";
|
||||
import {SimpleStorage} from "../src/SimpleStorage.sol";
|
||||
|
||||
contract DeploySimpleStorage is Script {
|
||||
function run() external returns (SimpleStorage) {
|
||||
vm.startBroadcast();
|
||||
SimpleStorage simpleStorage = new SimpleStorage();
|
||||
vm.stopBroadcast();
|
||||
return simpleStorage;
|
||||
}
|
||||
}
|
||||
33
simple-storage/src/SimpleStorage.sol
Normal file
33
simple-storage/src/SimpleStorage.sol
Normal file
@ -0,0 +1,33 @@
|
||||
// I'm a comment!
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
// pragma solidity ^0.8.0;
|
||||
// pragma solidity >=0.8.0 <0.9.0;
|
||||
|
||||
contract SimpleStorage {
|
||||
uint256 myFavoriteNumber;
|
||||
|
||||
struct Person {
|
||||
uint256 favoriteNumber;
|
||||
string name;
|
||||
}
|
||||
// uint256[] public anArray;
|
||||
Person[] public listOfPeople;
|
||||
|
||||
mapping(string => uint256) public nameToFavoriteNumber;
|
||||
|
||||
function store(uint256 _favoriteNumber) public {
|
||||
myFavoriteNumber = _favoriteNumber;
|
||||
}
|
||||
|
||||
function retrieve() public view returns (uint256) {
|
||||
return myFavoriteNumber;
|
||||
}
|
||||
|
||||
function addPerson(string memory _name, uint256 _favoriteNumber) public {
|
||||
listOfPeople.push(Person(_favoriteNumber, _name));
|
||||
nameToFavoriteNumber[_name] = _favoriteNumber;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user