Skip to content

Commit

Permalink
add pre-commit hook and update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Dec 18, 2023
1 parent ae46852 commit 2e7a514
Show file tree
Hide file tree
Showing 16 changed files with 1,456 additions and 1,472 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ jobs:
- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Install Pnpm"
uses: "pnpm/action-setup@v2"
with:
version: "8"

- name: "Install Node.js"
uses: "actions/setup-node@v3"
with:
cache: "pnpm"
node-version: "lts/*"

- name: "Install the Node.js dependencies"
run: "pnpm install"
run: "npm install"

- name: "Lint the contracts"
run: "pnpm lint"
run: "npm run lint"

- name: "Add lint summary"
run: |
Expand Down
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run prettier:write
npm run lint
7 changes: 0 additions & 7 deletions .prettier.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ out
*.env
*.log
.DS_Store
.pnp.*
lcov.info
package-lock.json
pnpm-lock.yaml
yarn.lock
21 changes: 21 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 140,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
],
"tabWidth": 4,
"printWidth": 140,
"trailingComma": "all",
"singleQuote": false,
"semi": true
}
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.20"],
"compiler-version": ["error", ">=0.8.19"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
Expand Down
41 changes: 8 additions & 33 deletions addresses/Addresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,21 @@ contract Addresses is IAddresses, Test {
constructor(string memory addressesPath) {
chainId = block.chainid;

string memory addressesData = string(
abi.encodePacked(vm.readFile(addressesPath))
);
string memory addressesData = string(abi.encodePacked(vm.readFile(addressesPath)));

bytes memory parsedJson = vm.parseJson(addressesData);

SavedAddresses[] memory savedAddresses = abi.decode(
parsedJson,
(SavedAddresses[])
);
SavedAddresses[] memory savedAddresses = abi.decode(parsedJson, (SavedAddresses[]));

for (uint256 i = 0; i < savedAddresses.length; i++) {
require(
getAddress(savedAddresses[i].name, savedAddresses[i].chainId) ==
address(0),
"Addresses: duplicate address in json"
);

_addAddress(
savedAddresses[i].name,
savedAddresses[i].chainId,
savedAddresses[i].addr
);
require(getAddress(savedAddresses[i].name, savedAddresses[i].chainId) == address(0), "Addresses: duplicate address in json");

_addAddress(savedAddresses[i].name, savedAddresses[i].chainId, savedAddresses[i].addr);
}
}

/// @notice add an address for a specific chainId
function _addAddress(
string memory name,
uint256 _chainId,
address addr
) private {
function _addAddress(string memory name, uint256 _chainId, address addr) private {
address currentAddress = _addresses[name][_chainId];

require(currentAddress == address(0), string(abi.encodePacked("Address:", name, "already set on chain:", _chainId.toString())));
Expand All @@ -95,10 +78,7 @@ contract Addresses is IAddresses, Test {
}

/// @notice get an address for a specific chainId
function getAddress(
string memory name,
uint256 _chainId
) public view returns (address) {
function getAddress(string memory name, uint256 _chainId) public view returns (address) {
return _getAddress(name, _chainId);
}

Expand All @@ -110,7 +90,6 @@ contract Addresses is IAddresses, Test {
/// @notice add an address for a specific chainId
function addAddress(string memory name, uint256 _chainId, address addr) public {
_addAddress(name, _chainId, addr);

}

/// @notice remove recorded addresses
Expand All @@ -119,11 +98,7 @@ contract Addresses is IAddresses, Test {
}

/// @notice get recorded addresses from a proposal's deployment
function getRecordedAddresses()
external
view
returns (string[] memory names, address[] memory addresses)
{
function getRecordedAddresses() external view returns (string[] memory names, address[] memory addresses) {
names = new string[](recordedAddresses.length);
addresses = new address[](recordedAddresses.length);
for (uint256 i = 0; i < recordedAddresses.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion addresses/IAddresses.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.19;


/// @notice This is a contract that stores addresses for different networks.
/// It allows a project to have a single source of truth to get all the addresses
/// for a given network.
Expand Down
Loading

0 comments on commit 2e7a514

Please sign in to comment.