From 5240913a320eea3193636969d661099c811f0bf6 Mon Sep 17 00:00:00 2001 From: Ethan Date: Tue, 5 Dec 2023 16:21:10 +0800 Subject: [PATCH 1/4] feat: add ci and add lint check script --- .env.example | 2 ++ .github/PULL_REQUEST_TEMPLATE.md | 17 ++++++++++ .github/workflows/lint-pr.yml | 30 +++++++++++++++++ .github/workflows/unit-test.yml | 57 ++++++++++++++++++++++++++++++++ package.json | 4 +++ 5 files changed, 110 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/lint-pr.yml create mode 100644 .github/workflows/unit-test.yml diff --git a/.env.example b/.env.example index 0adf5e0e..1497afec 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ +RPC_BSC=https://bsc-dataseed1.ninicoin.io + UNLOCK_RECEIVER= OPERATOR_PRIVATE_KEY= diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..d9bdc912 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +### Description + +add a description of your changes here... + +### Rationale + +tell us why we need these changes... + +### Example + +add an example CLI or API response... + +### Changes + +Notable changes: +* add each change in a bullet point here +* ... \ No newline at end of file diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml new file mode 100644 index 00000000..7b92cf9c --- /dev/null +++ b/.github/workflows/lint-pr.yml @@ -0,0 +1,30 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v4.5.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + feat + fix + docs + style + refactor + perf + test + build + ci + chore + revert + release diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 00000000..8fe8b663 --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,57 @@ +name: Unit Test +on: + push: + branches: + - master + - develop + pull_request: + branches: + - master + - develop +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + unit-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v1 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + + - name: Install Project Dependencies + run: | + npm install + forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3 + + - name: Lint Check + run: | + npm run lint:check + + - name: Build + run: | + forge build + + - name: Start Local Chain + run: | + npm install pm2 -g + pm2 start --name local-chain "anvil -f https://bsc-dataseed1.ninicoin.io" + sleep 5 + env: + PORT: 8545 + + - name: Unit Test + run: | + forge test --rpc-url http://127.0.0.1:8545 diff --git a/package.json b/package.json index b84e0c66..e1292df0 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,10 @@ "description": "", "author": "", "license": "MIT", + "scripts": { + "lint:check": "forge fmt ./contracts/BC_fusion --check", + "lint:write": "forge fmt ./contracts/BC_fusion" + }, "dependencies": { "@openzeppelin/contracts": "^4.9.3", "@openzeppelin/contracts-upgradeable": "^4.9.3", From 60422351f1a15407ca8e63a9096b5d8c70fd22a6 Mon Sep 17 00:00:00 2001 From: Ethan Date: Tue, 5 Dec 2023 16:21:31 +0800 Subject: [PATCH 2/4] chore: lint code in BC_fusion --- contracts/BC_fusion/interface/ITokenHub.sol | 5 ++--- .../BC_fusion/interface/ITokenRecoverPortal.sol | 11 ++++++++--- contracts/BC_fusion/lib/Utils.sol | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/contracts/BC_fusion/interface/ITokenHub.sol b/contracts/BC_fusion/interface/ITokenHub.sol index c6ece4dd..a34d1fc4 100644 --- a/contracts/BC_fusion/interface/ITokenHub.sol +++ b/contracts/BC_fusion/interface/ITokenHub.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.17; interface ITokenHub { - function recoverBCAsset(bytes32 tokenSymbol, address recipient, uint256 amount) - external; - function cancelTokenRecoverLock(bytes32 tokenSymbol, address attacker) external; + function recoverBCAsset(bytes32 tokenSymbol, address recipient, uint256 amount) external; + function cancelTokenRecoverLock(bytes32 tokenSymbol, address attacker) external; } diff --git a/contracts/BC_fusion/interface/ITokenRecoverPortal.sol b/contracts/BC_fusion/interface/ITokenRecoverPortal.sol index c3957c38..38fe8e66 100644 --- a/contracts/BC_fusion/interface/ITokenRecoverPortal.sol +++ b/contracts/BC_fusion/interface/ITokenRecoverPortal.sol @@ -12,9 +12,14 @@ interface ITokenRecoverPortal { // Returns true if the index has been marked recovered. function isRecovered(bytes32 index) external view returns (bool); // recover the given amount of the token to the given address. Reverts if the inputs are invalid. - function recover(bytes32 tokenSymbol, uint256 amount, - bytes calldata ownerPubKey, bytes calldata ownerSignature, bytes calldata approvalSignature, - bytes32[] calldata merkleProof) external; + function recover( + bytes32 tokenSymbol, + uint256 amount, + bytes calldata ownerPubKey, + bytes calldata ownerSignature, + bytes calldata approvalSignature, + bytes32[] calldata merkleProof + ) external; // Cancel the user token recover request by the assetProtector. function cancelTokenRecover(bytes32 tokenSymbol, address recipient) external; } diff --git a/contracts/BC_fusion/lib/Utils.sol b/contracts/BC_fusion/lib/Utils.sol index 810badc0..09e91826 100644 --- a/contracts/BC_fusion/lib/Utils.sol +++ b/contracts/BC_fusion/lib/Utils.sol @@ -24,16 +24,16 @@ library Utils { } } - function bytesToBytes32(uint _offst, bytes memory _input, bytes32 _output) internal pure { + function bytesToBytes32(uint256 _offst, bytes memory _input, bytes32 _output) internal pure { assembly { - mstore(_output , add(_input, _offst)) - mstore(add(_output,32) , add(add(_input, _offst),32)) + mstore(_output, add(_input, _offst)) + mstore(add(_output, 32), add(add(_input, _offst), 32)) } } function bytesConcat(bytes memory data, bytes memory _bytes, uint256 index, uint256 len) internal pure { - for (uint i; i Date: Tue, 5 Dec 2023 16:22:42 +0800 Subject: [PATCH 3/4] chore: add bc-fusion branch to ci --- .github/workflows/unit-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 8fe8b663..3b90170b 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -4,10 +4,12 @@ on: branches: - master - develop + - bc-fusion pull_request: branches: - master - develop + - bc-fusion permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. From 4ef9974f5f6bc34e8096c55df658e5726cb0c954 Mon Sep 17 00:00:00 2001 From: Ethan Date: Tue, 5 Dec 2023 16:33:18 +0800 Subject: [PATCH 4/4] fix: test error in SlashIndicator.t.sol --- test/SlashIndicator.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SlashIndicator.t.sol b/test/SlashIndicator.t.sol index 5db4ad4c..51b2cbd2 100644 --- a/test/SlashIndicator.t.sol +++ b/test/SlashIndicator.t.sol @@ -301,7 +301,7 @@ contract SlashIndicatorTest is Deployer { hex"00000000000000000000000023618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f" ); vm.prank(relayer); - vm.expectRevert(bytes("VALIDATOR_NOT_EXIST")); // as no such operator address existed + vm.expectRevert(); // as no such operator address existed slashIndicator.submitDoubleSignEvidence(headerA, headerB); }