Skip to content

Commit

Permalink
feat: add ci to bc-fusion contracts and lint code (#431)
Browse files Browse the repository at this point in the history
* feat: add ci and add lint check script

* chore: lint code in BC_fusion

* chore: add bc-fusion branch to ci

* fix: test error in SlashIndicator.t.sol
  • Loading branch information
cosinlink authored Dec 5, 2023
1 parent 1416b07 commit 4a77036
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
RPC_BSC=https://bsc-dataseed1.ninicoin.io

UNLOCK_RECEIVER=
OPERATOR_PRIVATE_KEY=
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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
* ...
30 changes: 30 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
release
59 changes: 59 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Unit Test
on:
push:
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.
# 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/[email protected]
- 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
5 changes: 2 additions & 3 deletions contracts/BC_fusion/interface/ITokenHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 8 additions & 3 deletions contracts/BC_fusion/interface/ITokenRecoverPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 6 additions & 6 deletions contracts/BC_fusion/lib/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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<len; ++i) {
data[index++] = _bytes[i];
for (uint256 i; i < len; ++i) {
data[index++] = _bytes[i];
}
}

Expand All @@ -49,7 +49,7 @@ library Utils {
}

if (prefix) {
return string(abi.encodePacked('0x',converted));
return string(abi.encodePacked("0x", converted));
}
return string(converted);
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/SlashIndicator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 4a77036

Please sign in to comment.