From 32f52ad27ee88891faa214985115da30d17b7d82 Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Tue, 21 May 2024 10:53:55 +0100 Subject: [PATCH] chore: add ci and license --- .github/workflows/ci.yaml | 21 +++++++++++++++++++++ .github/workflows/test.yml | 34 ---------------------------------- LICENSE | 20 ++++++++++++++++++++ foundry.toml | 12 +++++++++++- src/BytesLib.sol | 6 +++++- test/BytesLib.t.sol | 12 +++++++----- test/GasTest.t.sol | 13 ++++++++----- 7 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/test.yml create mode 100644 LICENSE diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..61e4a1a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,21 @@ +on: + workflow_dispatch: + push: + branches: + - "main" + pull_request: + +jobs: + lint: + uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-lint.yaml@main" + + build: + uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-build.yaml@main" + + test: + needs: ["lint", "build"] + uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-test.yaml@main" + with: + foundry-fuzz-runs: 5000 + foundry-profile: "test" + match-path: "test/**/*.sol" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 9282e82..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: test - -on: workflow_dispatch - -env: - FOUNDRY_PROFILE: ci - -jobs: - check: - strategy: - fail-fast: true - - name: Foundry project - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly - - - name: Run Forge build - run: | - forge --version - forge build --sizes - id: build - - - name: Run Forge tests - run: | - forge test -vvv - id: test diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eb2ee1a --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2024 Rhinestone + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/foundry.toml b/foundry.toml index c642703..9abd44a 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,16 @@ [profile.default] +emv_version = "paris" src = "src" out = "out" +script = "script" libs = ["node_modules"] -# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options +[fmt] +bracket_spacing = true +int_types = "long" +line_length = 100 +multiline_func_header = "all" +number_underscore = "thousands" +quote_style = "double" +tab_width = 4 +wrap_comments = true diff --git a/src/BytesLib.sol b/src/BytesLib.sol index 8040418..760501d 100644 --- a/src/BytesLib.sol +++ b/src/BytesLib.sol @@ -65,7 +65,11 @@ library AssociatedBytesLib { INTERNAL //////////////////////////////////////////////////////////////////////////*/ - function toArray(bytes memory data) internal pure returns (uint256 totalLength, bytes32[] memory dataList) { + function toArray(bytes memory data) + internal + pure + returns (uint256 totalLength, bytes32[] memory dataList) + { // Find 32 bytes segments nb totalLength = data.length; if (totalLength > 32 * 10) revert(); diff --git a/test/BytesLib.t.sol b/test/BytesLib.t.sol index 36589d7..7285398 100644 --- a/test/BytesLib.t.sol +++ b/test/BytesLib.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -import {Test} from "forge-std/Test.sol"; -import {AssociatedBytesLib} from "../src/BytesLib.sol"; +import { Test } from "forge-std/Test.sol"; +import { AssociatedBytesLib } from "../src/BytesLib.sol"; contract BytesLibTest is Test { using AssociatedBytesLib for AssociatedBytesLib.Bytes; @@ -11,10 +11,11 @@ contract BytesLibTest is Test { AssociatedBytesLib.Bytes data; mapping(address account => AssociatedBytesLib.Bytes) internal dataMapping; - function setUp() public {} + function setUp() public { } function testStore() public { - bytes memory _data = hex"424141414141414141414141414141414141414141414141414141414141414141414143"; + bytes memory _data = + hex"424141414141414141414141414141414141414141414141414141414141414141414143"; vm.record(); data.store(_data); @@ -32,7 +33,8 @@ contract BytesLibTest is Test { } function testStore_WhenUsing_Mapping() public { - bytes memory _data = hex"424141414141414141414141414141414141414141414141414141414141414141414143"; + bytes memory _data = + hex"424141414141414141414141414141414141414141414141414141414141414141414143"; vm.record(); dataMapping[address(2)].store(_data); diff --git a/test/GasTest.t.sol b/test/GasTest.t.sol index 721c396..2310214 100644 --- a/test/GasTest.t.sol +++ b/test/GasTest.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -import {Test, console2} from "forge-std/Test.sol"; -import {AssociatedBytesLib} from "../src/BytesLib.sol"; +import { Test, console2 } from "forge-std/Test.sol"; +import { AssociatedBytesLib } from "../src/BytesLib.sol"; contract GasTest is Test { using AssociatedBytesLib for AssociatedBytesLib.Bytes; @@ -10,7 +10,7 @@ contract GasTest is Test { bytes _data; AssociatedBytesLib.Bytes _bytesData; - function setUp() public {} + function setUp() public { } function gasDiff(bytes memory d) public { uint256 gasSplit = gasleft(); @@ -28,7 +28,8 @@ contract GasTest is Test { } function testGas_Short() public { - bytes memory d = hex"424141414141414141414141414141414141414141414141414141414141414141414143"; + bytes memory d = + hex"424141414141414141414141414141414141414141414141414141414141414141414143"; gasDiff(d); } @@ -41,7 +42,9 @@ contract GasTest is Test { function testGas_Long() public { bytes memory d; for (uint256 i = 0; i < 5; i++) { - d = abi.encodePacked(d, hex"424141414141414141414141414141414141414141414141414141414141414141414143"); + d = abi.encodePacked( + d, hex"424141414141414141414141414141414141414141414141414141414141414141414143" + ); } gasDiff(d); }