Skip to content

Commit

Permalink
chore: lint json (#2)
Browse files Browse the repository at this point in the history
* chore: lint json

* fix test run
  • Loading branch information
arr00 authored Jul 24, 2024
1 parent 0c5770e commit 9bb2af0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
)" >> $GITHUB_ENV
- name: "Run the tests"
run: "forge test"
run: "bun run test"

- name: "Add test summary"
run: |
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
solc = "0.8.25"
src = "src"
test = "test"
fs_permissions = [{ access = "read-write", path = "./out"}]

[profile.ci]
fuzz = { runs = 10_000 }
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"devDependencies": {
"forge-std": "github:foundry-rs/forge-std#v1.9.1",
"prettier": "^3.0.0",
"solhint": "^3.6.2"
"solhint": "^3.6.2",
"ts-node": "^10.9.2"
},
"keywords": [
"blockchain",
Expand All @@ -34,8 +35,8 @@
"lint:sol": "forge fmt --check && bun solhint {script,src,test}/**/*.sol",
"prettier:check": "prettier --check \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"",
"prettier:write": "prettier --write \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"",
"test": "forge test",
"test:coverage": "forge coverage",
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage"
"test": "forge test --ffi",
"test:coverage": "COVERAGE=true forge coverage",
"test:coverage:report": "COVERAGE=true forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage"
}
}
12 changes: 6 additions & 6 deletions test/DropERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pragma solidity ^0.8.0;
import { TestBase } from "./util/TestBase.t.sol";
import { DropERC1155 } from "src/DropERC1155.sol";
import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol";
import { LintJSON } from "./util/LintJSON.t.sol";

contract DropERC1155Test is TestBase {
contract DropERC1155Test is TestBase, LintJSON {
DropERC1155 token;

function setUp() external {
Expand Down Expand Up @@ -41,12 +42,11 @@ contract DropERC1155Test is TestBase {
assertEq(royaltyReceiver, address(this));
assertEq(royalties, 0.01 ether);

// TODO: lint
token.contractURI();
_lintJSON(token.contractURI());
}

function test_uri() external {
// TODO: lint
token.uri(1);
function test_uri_lintJSON() external {
_lintJSON(token.uri(1));
_lintJSON(token.uri(2));
}
}
28 changes: 28 additions & 0 deletions test/util/LintJSON.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;

import "forge-std/src/Test.sol";

contract LintJSON is Test {
function _lintJSON(string memory json) internal {
if (vm.envOr("COVERAGE", false)) {
// Don't check if we're running coverage
return;
}

vm.writeFile("./out/lint-json.json", json);
string[] memory inputs = new string[](3);
inputs[0] = "npx";
inputs[1] = "ts-node";
inputs[2] = "./utils/lint-json.ts";
bytes memory ffiResp = vm.ffi(inputs);

uint256 resAsInt;
assembly {
resAsInt := mload(add(ffiResp, 0x20))
}
if (resAsInt != 1) {
revert("JSON lint failed");
}
}
}
13 changes: 13 additions & 0 deletions utils/lint-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from "fs";

const jsonString = fs.readFileSync("./out/lint-json.json", "utf8");
try {
JSON.parse(jsonString.substring(27));
} catch {
// Invalid json
process.stdout.write("0x0000000000000000000000000000000000000000000000000000000000000002");
process.exit();
}

process.stdout.write("0x0000000000000000000000000000000000000000000000000000000000000001");
process.exit();

0 comments on commit 9bb2af0

Please sign in to comment.