diff --git a/README.md b/README.md index 3a54631..107b4c7 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ A repo to get the most recent deployment from a given environment in foundry. Th It will look through your `broadcast` folder at your most recent deployment. -- [foundry-devops](#foundry-devops) -- [Getting Started](#getting-started) - - [Requirements](#requirements) - - [Installation](#installation) - - [Usage](#usage) -- [Contributing](#contributing) - - [Testing](#testing) +- [foundry-devops](#foundry-devops) +- [Getting Started](#getting-started) + - [Requirements](#requirements) + - [Installation](#installation) + - [Usage](#usage) +- [Contributing](#contributing) + - [Testing](#testing) # Getting Started @@ -65,6 +65,12 @@ function interactWithPreviouslyDeployedContracts() public { } ``` +3. To work with aderyn as a script, also set `ffi` to true in your `foundry.toml`: + +``` +ffi = true +``` + # Contributing PRs are welcome! diff --git a/foundry.toml b/foundry.toml index ee1f80e..099226e 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,6 +2,10 @@ src = "src" out = "out" libs = ["lib"] -fs_permissions = [{ access = "read", path = "./broadcast" }, { access = "read", path = "./reports" }] +fs_permissions = [ + { access = "read", path = "./broadcast" }, + { access = "read", path = "./reports" }, +] +# ffi = true # See more config options https://github.com/foundry-rs/foundry/tree/master/config diff --git a/lib/forge-std b/lib/forge-std index c22437a..978ac6f 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit c22437a63d1c3418869bc35a7c55a5175a09b701 +Subproject commit 978ac6fadb62f5f0b723c996f64be52eddba6801 diff --git a/src/AderynRunnerTool.sol b/src/AderynRunnerTool.sol index 25a5878..bef9a4b 100644 --- a/src/AderynRunnerTool.sol +++ b/src/AderynRunnerTool.sol @@ -7,17 +7,12 @@ import {console} from "forge-std/console.sol"; import {stdJson} from "forge-std/StdJson.sol"; import {console} from "forge-std/console.sol"; - struct IssueCount { - int256 critical; int256 high; - int256 medium; int256 low; - int256 nc; } library AderynRunnerTool { - using stdJson for string; Vm public constant vm = Vm(address(bytes20(uint160(uint256(keccak256("hevm cheat code")))))); @@ -39,18 +34,8 @@ library AderynRunnerTool { function get_issue_count(string memory filePath) public view returns (IssueCount memory) { string memory json = vm.readFile(filePath); - int256 critical = json.readInt("$.issue_count.critical"); int256 high = json.readInt("$.issue_count.high"); - int256 medium = json.readInt("$.issue_count.medium"); int256 low = json.readInt("$.issue_count.low"); - int256 nc = json.readInt("$.issue_count.nc"); - return IssueCount({ - critical: critical, - high: high, - medium: medium, - low: low, - nc:nc - }); + return IssueCount({high: high, low: low}); } - -} \ No newline at end of file +} diff --git a/src/DevOpsTools.sol b/src/DevOpsTools.sol index e2e734f..6a788f4 100644 --- a/src/DevOpsTools.sol +++ b/src/DevOpsTools.sol @@ -8,12 +8,11 @@ import {StdCheatsSafe} from "forge-std/StdCheats.sol"; import {console} from "forge-std/console.sol"; import {StringUtils} from "./StringUtils.sol"; - library DevOpsTools { using stdJson for string; using StringUtils for string; - Vm public constant vm = Vm(address(bytes20(uint160(uint256(keccak256("hevm cheat code")))))); + Vm public constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); string public constant RELATIVE_BROADCAST_PATH = "./broadcast"; @@ -70,12 +69,13 @@ library DevOpsTools { view returns (address) { - for(uint256 i = 0; vm.keyExists(json, string.concat("$.transactions[", vm.toString(i), "]")); i++) { + for (uint256 i = 0; vm.keyExistsJson(json, string.concat("$.transactions[", vm.toString(i), "]")); i++) { string memory contractNamePath = string.concat("$.transactions[", vm.toString(i), "].contractName"); - if (vm.keyExists(json, contractNamePath)) { + if (vm.keyExistsJson(json, contractNamePath)) { string memory deployedContractName = json.readString(contractNamePath); if (deployedContractName.isEqualTo(contractName)) { - latestAddress = json.readAddress(string.concat("$.transactions[", vm.toString(i), "].contractAddress")); + latestAddress = + json.readAddress(string.concat("$.transactions[", vm.toString(i), "].contractAddress")); } } } diff --git a/test/AderynRunnerTest.t.sol b/test/AderynRunnerTest.t.sol index b1ebb49..f1659f3 100644 --- a/test/AderynRunnerTest.t.sol +++ b/test/AderynRunnerTest.t.sol @@ -6,34 +6,26 @@ import "../src/AderynRunnerTool.sol"; import {console} from "forge-std/console.sol"; contract AderynRunnerTest is Test { - function setUp() public { - // Path to aderyn executable in your local computer - string memory ADERYN_PATH = "../aderyn/target/release/aderyn"; + string memory ADERYN_PATH = "aderyn"; // Test if markdown creation works AderynRunnerTool.run_with(ADERYN_PATH, "./reports/my_report.md"); - + // Test if json output works AderynRunnerTool.run_with(ADERYN_PATH, "./reports/my_report.json"); } - // function testDefaultsAderynRunnerWorks() public { - // AderynRunnerTool.run_with_defaults(); - // } - + // forge-config: default.ffi = true function testAderynThereAreNoCriticalErrors() public view { IssueCount memory ic = AderynRunnerTool.get_issue_count("./reports/my_report.json"); - assert(ic.critical == 0); assert(ic.high == 0); } + // forge-config: default.ffi = true function testAderynThereAreLessThan10MediumOrLessSevereErrors() public view { IssueCount memory ic = AderynRunnerTool.get_issue_count("./reports/my_report.json"); - assert(ic.medium < 10); assert(ic.low < 10); - assert(ic.nc < 10); } - -} \ No newline at end of file +} diff --git a/test/DevOpsToolsTest.t.sol b/test/DevOpsToolsTest.t.sol index 7e9015b..4a78b68 100644 --- a/test/DevOpsToolsTest.t.sol +++ b/test/DevOpsToolsTest.t.sol @@ -7,27 +7,19 @@ import {DevOpsTools} from "../src/DevOpsTools.sol"; contract DevOpsToolsTest is Test { string public constant SEARCH_PATH = "broadcast"; - function testGetMostRecentlyDeployedContract() public { + function testGetMostRecentlyDeployedContract() public view { string memory contractName = "Stuff"; uint256 chainId = 31337; address expectedAddress = 0x5FbDB2315678afecb367f032d93F642f64180aa3; - address mostRecentDeployment = DevOpsTools.get_most_recent_deployment( - contractName, - chainId, - SEARCH_PATH - ); + address mostRecentDeployment = DevOpsTools.get_most_recent_deployment(contractName, chainId, SEARCH_PATH); assertEq(mostRecentDeployment, expectedAddress); } - function testGetMostRecentlyDeployedEvenWhenMultipleAreDeployed() public { + function testGetMostRecentlyDeployedEvenWhenMultipleAreDeployed() public view { string memory contractName = "FundMe"; uint256 chainId = 1234; address expectedAddress = 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9; - address mostRecentDeployment = DevOpsTools.get_most_recent_deployment( - contractName, - chainId, - SEARCH_PATH - ); + address mostRecentDeployment = DevOpsTools.get_most_recent_deployment(contractName, chainId, SEARCH_PATH); assertEq(mostRecentDeployment, expectedAddress); } @@ -35,35 +27,23 @@ contract DevOpsToolsTest is Test { string memory contractName = "FundMe"; uint256 chainId = 9999; vm.expectRevert("No deployment artifacts were found for specified chain"); - DevOpsTools.get_most_recent_deployment( - contractName, - chainId, - SEARCH_PATH - ); + DevOpsTools.get_most_recent_deployment(contractName, chainId, SEARCH_PATH); } function testExpectRevertIfNoDeployment() public { string memory contractName = "MissingContract"; uint256 chainId = 1234; vm.expectRevert("No contract deployed"); - DevOpsTools.get_most_recent_deployment( - contractName, - chainId, - SEARCH_PATH - ); + DevOpsTools.get_most_recent_deployment(contractName, chainId, SEARCH_PATH); } // All other tests use what appear to be legacy broadcast files // This one uses the newer type with no rpc property - function testNonLegacyBroadcast() public { + function testNonLegacyBroadcast() public view { string memory contractName = "NewStuff"; uint256 chainId = 31337; address expectedAddress = 0x5FbDB2315678afecb367f032d93F642f64180aa3; - address mostRecentDeployment = DevOpsTools.get_most_recent_deployment( - contractName, - chainId, - SEARCH_PATH - ); + address mostRecentDeployment = DevOpsTools.get_most_recent_deployment(contractName, chainId, SEARCH_PATH); assertEq(mostRecentDeployment, expectedAddress); } }