-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from hakymulla/mock_contract
Mock Test Contract
- Loading branch information
Showing
6 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "ethereum/lib/forge-std"] | ||
path = ethereum/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
|
||
# Full reference https://github.com/foundry-rs/foundry/tree/master/crates/config | ||
|
||
[profile.default] | ||
script = "script" | ||
solc = "0.8.26" | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
test = "test" | ||
libs = ["dependencies"] | ||
fs_permissions = [{ access = "read-write", path = "./logs" }] | ||
|
||
[dependencies] # <= Dependencies will be added under this config | ||
forge-std = { version = "1.8.2", url = "https://github.com/foundry-rs/foundry.git" } | ||
[dependencies] | ||
forge-std = { version = "1.8.2", url = "https://github.com/foundry-rs/foundry.git" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {Script} from "@forge-std/src/Script.sol"; | ||
import {MockStorage} from "../src/Mock/MockStorage.sol"; | ||
|
||
contract DeployMockStorage is Script{ | ||
|
||
uint256 public val1 = 1000; | ||
uint256 public val2 = 2000; | ||
address public addr = 0x9D7f74d0C41E726EC95884E0e97Fa6129e3b5E99; | ||
address public addr2 = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4; | ||
|
||
function run() external returns (MockStorage) { | ||
|
||
uint256 deployerPrivateKey = vm.envUint("ACCOUNT_PRIVATE_KEY"); | ||
|
||
vm.startBroadcast(deployerPrivateKey); | ||
MockStorage mockStorage = new MockStorage(); | ||
mockStorage.setValue(val1); | ||
mockStorage.setMapValues(val1, addr); | ||
mockStorage.setMapValues(val2, addr2); | ||
mockStorage.setArrValues(addr); | ||
mockStorage.setArrValues(addr2); | ||
vm.stopBroadcast(); | ||
|
||
return mockStorage; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
contract MockStorage { | ||
uint256 public value; | ||
mapping(uint256 => address) public mapValues; | ||
address[] public arrValues; | ||
|
||
function setValue(uint256 _value) public { | ||
value = _value; | ||
} | ||
|
||
function getValue() public view returns (uint256) { | ||
return value; | ||
} | ||
|
||
function setMapValues(uint256 _value, address _add) public { | ||
mapValues[_value] = _add; | ||
} | ||
|
||
function getMapValues(uint256 _value) public view returns (address) { | ||
return mapValues[_value]; | ||
} | ||
|
||
function setArrValues(address _value) public { | ||
arrValues.push(_value); | ||
} | ||
|
||
function getArrValues(uint256 i) public view returns (address) { | ||
return arrValues[i]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {Script} from "@forge-std/src/Script.sol"; | ||
import {MockStorage} from "../src/Mock/MockStorage.sol"; | ||
import {DeployMockStorage} from "../script/DeployMockStorage.s.sol"; | ||
import {Test, console} from "@forge-std/src/Test.sol"; | ||
|
||
contract MockStorageTest is Test{ | ||
MockStorage mockStorage; | ||
|
||
function setUp() external { | ||
DeployMockStorage deployer = new DeployMockStorage(); | ||
mockStorage = deployer.run(); | ||
} | ||
|
||
|
||
function testMockStorage() public view { | ||
|
||
assert( mockStorage.getValue() == 1000); | ||
assert( mockStorage.getMapValues(1000) == 0x9D7f74d0C41E726EC95884E0e97Fa6129e3b5E99); | ||
assert( mockStorage.getMapValues(2000) == 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4); | ||
assert( mockStorage.getArrValues(0) == 0x9D7f74d0C41E726EC95884E0e97Fa6129e3b5E99); | ||
assert( mockStorage.getArrValues(1) == 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4); | ||
|
||
} | ||
} |