Skip to content

Commit c233d2e

Browse files
committed
test: foundry migrations
1 parent aeca287 commit c233d2e

File tree

83 files changed

+797
-2041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+797
-2041
lines changed

.openzeppelin/unknown-80002.json

-940
This file was deleted.

.prettierrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"plugins": ["prettier-plugin-solidity"],
3+
"useTabs": false,
4+
"printWidth": 120,
5+
"trailingComma": "es5",
6+
"tabWidth": 4,
7+
"semi": false,
8+
"singleQuote": false,
9+
"bracketSpacing": true,
10+
"overrides": [
11+
{
12+
"files": "*.sol",
13+
"options": {
14+
"singleQuote": false
15+
}
16+
}
17+
]
18+
}

.solhint.json

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
{
2-
"extends": "solhint:default"
3-
}
2+
"extends": "solhint:recommended",
3+
"plugins": ["prettier"],
4+
"rules": {
5+
"code-complexity": ["error", 9],
6+
"compiler-version": ["error", ">=0.8.23"],
7+
"const-name-snakecase": "off",
8+
"no-empty-blocks": "off",
9+
"constructor-syntax": "error",
10+
"func-visibility": ["error", { "ignoreConstructors": true }],
11+
"max-line-length": ["error", 120],
12+
"not-rely-on-time": "off",
13+
"reason-string": ["warn", { "maxLength": 64 }],
14+
"no-unused-import": "error",
15+
"no-unused-vars": "off",
16+
"no-inline-assembly": "off",
17+
"avoid-low-level-calls": "off",
18+
"no-global-import": "error",
19+
"prettier/prettier": "error",
20+
"private-vars-leading-underscore": "off",
21+
"func-name-mixedcase": "off",
22+
"var-name-mixedcase": "off",
23+
"modifier-name-mixedcase": "off"
24+
}
25+
}

Makefile

+31-26
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,39 @@ bootstrap: install
1515
@npx husky install
1616
@npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
1717

18-
# https://jestjs.io/docs/cli#--coverageboolean
19-
.PHONY: test ## run tests
20-
test:
21-
@npx hardhat test --network $(network)
22-
23-
# https://jestjs.io/docs/cli#--coverageboolean
24-
.PHONY: testfy ## run tests
25-
testfy:
26-
@forge test --via-ir --gas-report -vv
27-
28-
.PHONY: testcov ## run tests coverage report
29-
testcov:
30-
@npx hardhat coverage
31-
32-
.PHONY: compile ## compile contracts
33-
compile:
34-
@npx hardhat compile
35-
3618
.PHONY: clean ## clean installation and dist files
3719
clean:
3820
@rm -rf cache
3921
@rm -rf artifacts
4022
@rm -rf node_modules
4123
@rm -rf cache_forge
24+
@forge clean
25+
26+
.PHONY: forge-clean ## clean forge
27+
forge-clean:
28+
rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && touch .gitmodules && git add . && git commit -m "modules"
29+
30+
.PHONY: compile ## compile contracts
31+
compile:
32+
@forge build
33+
34+
.PHONY: force-compile ## compile contracts
35+
force-compile:
36+
@forge clean && forge build
37+
38+
# https://jestjs.io/docs/cli#--coverageboolean
39+
.PHONY: test ## run tests
40+
test:
41+
@forge test --via-ir --gas-report --show-progress -vvv --force
42+
43+
.PHONY: coverage ## run tests coverage report
44+
coverage:
45+
mkdir -p coverage
46+
forge coverage --report lcov --no-match-path "test/foundry/invariants/*"
47+
lcov --remove lcov.info -o coverage/lcov.info 'test/*' 'script/*' --rc lcov_branch_coverage=1
48+
genhtml coverage/lcov.info -o coverage --rc lcov_branch_coverage=1
49+
4250

43-
.PHONY: install ## install dependencies
44-
install:
45-
@npm ci
4651

4752
.PHONY: secreport ## generate a security analysis report using aderyn
4853
secreport:
@@ -53,12 +58,12 @@ sectest:
5358
@export PATH=$HOME/.local/bin:$PATH
5459
@slither .
5560

56-
.PHONY: solformat ## auto-format solidity source files
57-
solformat:
58-
@npx solhint 'contracts/**/*.sol' --fix
61+
.PHONY: format ## auto-format solidity source files
62+
format:
63+
@npx prettier --write contracts
5964

60-
.PHONY: solhint ## lint standard solidity
61-
solhint:
65+
.PHONY: hint ## lint standard solidity
66+
lint:
6267
@npx solhint 'contracts/**/*.sol'
6368

6469
.PHONE: release ## generate a new release version

contracts/Ownership.sol

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// SPDX-License-Identifier: MIT
22
// NatSpec format convention - https://docs.soliditylang.org/en/v0.5.10/natspec-format.html
3-
pragma solidity ^0.8.24;
3+
pragma solidity ^0.8.26;
44

5-
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
6-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
8-
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
9-
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
10-
import {ERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
5+
import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol";
6+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7+
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
8+
import { ERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
9+
import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
10+
import { ERC721EnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
1111

12-
import {GovernableUpgradeable} from "contracts/base/upgradeable/GovernableUpgradeable.sol";
13-
import {IReferendumVerifiable} from "contracts/interfaces/IReferendumVerifiable.sol";
14-
import {IOwnership} from "contracts/interfaces/IOwnership.sol";
12+
import { GovernableUpgradeable } from "contracts/base/upgradeable/GovernableUpgradeable.sol";
13+
import { IReferendumVerifiable } from "contracts/interfaces/IReferendumVerifiable.sol";
14+
import { IOwnership } from "contracts/interfaces/IOwnership.sol";
1515

1616
// TODO imp ERC404
1717

@@ -61,9 +61,7 @@ contract Ownership is
6161
/// @notice Function that should revert when msg.sender is not authorized to upgrade the contract.
6262
/// @param newImplementation The address of the new implementation contract.
6363
/// @dev See https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable-_authorizeUpgrade-address-
64-
function _authorizeUpgrade(
65-
address newImplementation
66-
) internal override onlyAdmin {}
64+
function _authorizeUpgrade(address newImplementation) internal override onlyAdmin {}
6765

6866
/// @notice Modifier to ensure content is approved before distribution.
6967
/// @param to The address attempting to distribute the content.
@@ -73,19 +71,15 @@ contract Ownership is
7371
/// It also ensures that the recipient is the one who initially submitted the content for approval.
7472
modifier onlyApprovedContent(address to, uint256 contentId) {
7573
// Revert if the content is not approved or if the recipient is not the original submitter
76-
if (!referendum.isApproved(to, contentId))
77-
revert InvalidNotApprovedContent();
74+
if (!referendum.isApproved(to, contentId)) revert InvalidNotApprovedContent();
7875
_;
7976
}
8077

8178
/// @notice Mints a new NFT to the specified address.
8279
/// @dev Our naive assumption is that only those who know the content id can mint the corresponding token.
8380
/// @param to The address to mint the NFT to.
8481
/// @param contentId The content id of the NFT. This should be a unique identifier for the NFT.
85-
function registerContent(
86-
address to,
87-
uint256 contentId
88-
) external onlyApprovedContent(to, contentId) {
82+
function registerContent(address to, uint256 contentId) external onlyApprovedContent(to, contentId) {
8983
_mint(to, contentId);
9084
emit RegisteredContent(contentId);
9185
}
@@ -99,11 +93,7 @@ contract Ownership is
9993
address to,
10094
uint256 tokenId,
10195
address auth
102-
)
103-
internal
104-
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
105-
returns (address)
106-
{
96+
) internal override(ERC721Upgradeable, ERC721EnumerableUpgradeable) returns (address) {
10797
return super._update(to, tokenId, auth);
10898
}
10999

@@ -126,12 +116,7 @@ contract Ownership is
126116
public
127117
view
128118
virtual
129-
override(
130-
IERC165,
131-
ERC721Upgradeable,
132-
AccessControlUpgradeable,
133-
ERC721EnumerableUpgradeable
134-
)
119+
override(IERC165, ERC721Upgradeable, AccessControlUpgradeable, ERC721EnumerableUpgradeable)
135120
returns (bool)
136121
{
137122
return super.supportsInterface(interfaceId);

contracts/Referendum.sol

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// SPDX-License-Identifier: MIT
22
// NatSpec format convention - https://docs.soliditylang.org/en/v0.5.10/natspec-format.html
3-
pragma solidity ^0.8.24;
3+
pragma solidity ^0.8.26;
44

5-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
6-
import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
7-
import {NoncesUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/NoncesUpgradeable.sol";
8-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
9-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
10-
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
5+
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
6+
import { EIP712Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
7+
import { NoncesUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/NoncesUpgradeable.sol";
8+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
9+
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
10+
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
1111

12-
import {GovernableUpgradeable} from "contracts/base/upgradeable/GovernableUpgradeable.sol";
13-
import {QuorumUpgradeable} from "contracts/base/upgradeable/QuorumUpgradeable.sol";
14-
import {IReferendum} from "contracts/interfaces/IReferendum.sol";
15-
import {IReferendumRoleManager} from "contracts/interfaces/IReferendumRoleManager.sol";
16-
import {IReferendumVerifiable} from "contracts/interfaces/IReferendumVerifiable.sol";
12+
import { GovernableUpgradeable } from "contracts/base/upgradeable/GovernableUpgradeable.sol";
13+
import { QuorumUpgradeable } from "contracts/base/upgradeable/QuorumUpgradeable.sol";
14+
import { IReferendum } from "contracts/interfaces/IReferendum.sol";
15+
import { IReferendumRoleManager } from "contracts/interfaces/IReferendumRoleManager.sol";
16+
import { IReferendumVerifiable } from "contracts/interfaces/IReferendumVerifiable.sol";
1717

18-
import {C} from "contracts/libraries/Constants.sol";
19-
import {T} from "contracts/libraries/Types.sol";
18+
import { C } from "contracts/libraries/Constants.sol";
19+
import { T } from "contracts/libraries/Types.sol";
2020

2121
/// @title Content curation contract.
2222
/// @notice This contract allows for the submission, voting, and approval/rejection of content.
@@ -72,9 +72,7 @@ contract Referendum is
7272
/// @notice Function that should revert when msg.sender is not authorized to upgrade the contract.
7373
/// @param newImplementation The address of the new implementation contract.
7474
/// @dev See https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable-_authorizeUpgrade-address-
75-
function _authorizeUpgrade(
76-
address newImplementation
77-
) internal override onlyAdmin {}
75+
function _authorizeUpgrade(address newImplementation) internal override onlyAdmin {}
7876

7977
/// @notice Checks if the content is active nor blocked.
8078
/// @param contentId The ID of the content.
@@ -87,10 +85,7 @@ contract Referendum is
8785
/// @param initiator The submission account address .
8886
/// @param contentId The ID of the content.
8987
/// @return True if the content is approved, false otherwise.
90-
function isApproved(
91-
address initiator,
92-
uint256 contentId
93-
) public view returns (bool) {
88+
function isApproved(address initiator, uint256 contentId) public view returns (bool) {
9489
bool approved = isActive(contentId);
9590
bool validAccount = submissions[initiator].contains(contentId);
9691
bool verifiedRole = hasRole(VERIFIED_ROLE, initiator);
@@ -128,21 +123,10 @@ contract Referendum is
128123
/// @param contentId The ID of the content to be submitted.
129124
/// @param initiator The address of the initiator submitting the content.
130125
/// @param sig The EIP712 signature for the submission.
131-
function submitWithSig(
132-
uint256 contentId,
133-
address initiator,
134-
T.EIP712Signature calldata sig
135-
) external {
126+
function submitWithSig(uint256 contentId, address initiator, T.EIP712Signature calldata sig) external {
136127
// https://eips.ethereum.org/EIPS/eip-712
137128
uint256 nonce = _useNonce(initiator);
138-
bytes32 structHash = keccak256(
139-
abi.encode(
140-
C.REFERENDUM_SUBMIT_TYPEHASH,
141-
contentId,
142-
initiator,
143-
nonce
144-
)
145-
);
129+
bytes32 structHash = keccak256(abi.encode(C.REFERENDUM_SUBMIT_TYPEHASH, contentId, initiator, nonce));
146130

147131
// retrieve the signer from digest and signature to check if the signature correspond to expected signer.
148132
bytes32 digest = _hashTypedDataV4(structHash); // expected keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message))

0 commit comments

Comments
 (0)