Skip to content

Commit ff144e5

Browse files
committed
Add initial tests and CI checks
1 parent a18734f commit ff144e5

File tree

11 files changed

+2539
-31
lines changed

11 files changed

+2539
-31
lines changed

.github/workflows/checks.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ jobs:
3838
- name: Run tests and generate gas report
3939
run: npm run test
4040

41+
tests-foundry:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
with:
46+
submodules: recursive
47+
- name: Set up environment
48+
uses: ./.github/actions/setup
49+
- name: Run tests
50+
run: forge test -vv
51+
52+
slither:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Set up environment
57+
uses: ./.github/actions/setup
58+
- run: rm foundry.toml
59+
- uses: crytic/[email protected]
60+
4161
codespell:
4262
runs-on: ubuntu-latest
4363
steps:

contracts/access/AccessManagerLight.sol renamed to contracts/access/manager/AccessManagerLight.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pragma solidity ^0.8.20;
44

55
import {IAuthority} from "@openzeppelin/contracts/access/manager/IAuthority.sol";
6-
import {Masks} from "../utils/Masks.sol";
6+
import {Masks} from "../../utils/Masks.sol";
77

88
contract AccessManagerLight is IAuthority {
99
using Masks for *;

contracts/utils/Masks.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
pragma solidity ^0.8.20;
44

5+
/// @dev Library for handling bit masks
56
library Masks {
67
using Masks for *;
78

89
type Mask is bytes32;
910

11+
/// @dev Returns a new mask with the bit at `group` index set to 1.
1012
function toMask(uint8 group) internal pure returns (Mask) {
1113
return Mask.wrap(bytes32(1 << group));
1214
}
1315

16+
/// @dev Returns a new mask with the bits at `groups` indices set to 1.
1417
function toMask(uint8[] memory groups) internal pure returns (Mask) {
1518
Masks.Mask set = Mask.wrap(0);
1619
for (uint256 i = 0; i < groups.length; ++i) {
@@ -19,31 +22,38 @@ library Masks {
1922
return set;
2023
}
2124

25+
/// @dev Get value of the mask at `group` index
2226
function get(Mask self, uint8 group) internal pure returns (bool) {
2327
return !group.toMask().intersection(self).isEmpty();
2428
}
2529

30+
/// @dev Whether the mask is `bytes32(0)`
2631
function isEmpty(Mask self) internal pure returns (bool) {
2732
return Mask.unwrap(self) == bytes32(0);
2833
}
2934

35+
/// @dev Invert the bits of a mask
3036
function complement(Mask m1) internal pure returns (Mask) {
3137
return Mask.wrap(~Mask.unwrap(m1));
3238
}
3339

40+
/// @dev Perform a bitwise OR operation on two masks
3441
function union(Mask m1, Mask m2) internal pure returns (Mask) {
3542
return Mask.wrap(Mask.unwrap(m1) | Mask.unwrap(m2));
3643
}
3744

45+
/// @dev Perform a bitwise AND operation on two masks
3846
function intersection(Mask m1, Mask m2) internal pure returns (Mask) {
3947
return Mask.wrap(Mask.unwrap(m1) & Mask.unwrap(m2));
4048
}
4149

50+
/// @dev Perform a bitwise difference operation on two masks (m1 - m2)
4251
function difference(Mask m1, Mask m2) internal pure returns (Mask) {
4352
return m1.intersection(m2.complement());
4453
}
4554

46-
function symetric_difference(Mask m1, Mask m2) internal pure returns (Mask) {
55+
/// @dev Returns the symmetric difference (∆) of two masks, also known as disjunctive union or exclusive OR (XOR)
56+
function symmetric_difference(Mask m1, Mask m2) internal pure returns (Mask) {
4757
return m1.union(m2).difference(m1.intersection(m2));
4858
}
4959
}

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ src = 'contracts'
55
out = 'out'
66
libs = ['node_modules', 'lib']
77
test = 'test'
8-
cache_path = 'cache_forge'
8+
cache_path = 'cache_forge'
99

1010
[fuzz]
1111
runs = 5000

hardhat.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const { argv } = require('yargs/yargs')()
1313

1414
require('@nomicfoundation/hardhat-chai-matchers');
1515
require('@nomicfoundation/hardhat-ethers');
16+
require('hardhat-exposed');
1617
require('./hardhat/remappings');
1718

1819
module.exports = {

0 commit comments

Comments
 (0)