Skip to content

Commit 71d6ec2

Browse files
committed
Add test to improve code coverage
1 parent 299ac75 commit 71d6ec2

5 files changed

Lines changed: 172 additions & 2 deletions

File tree

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[profile.default]
2-
solc = "0.8.30"
2+
solc = "0.8.33"
33
src = 'src'
44
out = 'out'
55
libs = ['lib']

hardhat.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require("@nomicfoundation/hardhat-foundry");
33
require('solidity-docgen');
44
module.exports = {
5-
solidity: "0.8.30",
5+
solidity: "0.8.33",
66
settings: {
77
optimizer: {
88
enabled: true,

src/mocks/RuleEngineExposed.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import {RuleEngine} from "../RuleEngine.sol";
5+
import {RuleEngineOwnable} from "../RuleEngineOwnable.sol";
6+
7+
/**
8+
* @title RuleEngineExposed
9+
* @dev Exposes internal functions for testing coverage
10+
*/
11+
contract RuleEngineExposed is RuleEngine {
12+
constructor(
13+
address admin,
14+
address forwarder,
15+
address token
16+
) RuleEngine(admin, forwarder, token) {}
17+
18+
function exposedMsgData() external view returns (bytes memory) {
19+
return _msgData();
20+
}
21+
}
22+
23+
/**
24+
* @title RuleEngineOwnableExposed
25+
* @dev Exposes internal functions for testing coverage
26+
*/
27+
contract RuleEngineOwnableExposed is RuleEngineOwnable {
28+
constructor(
29+
address owner_,
30+
address forwarder,
31+
address token
32+
) RuleEngineOwnable(owner_, forwarder, token) {}
33+
34+
function exposedMsgData() external view returns (bytes memory) {
35+
return _msgData();
36+
}
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Test.sol";
5+
import "../HelperContract.sol";
6+
import {RuleEngineExposed} from "src/mocks/RuleEngineExposed.sol";
7+
8+
/**
9+
* @title Coverage tests for RuleEngine (supportsInterface, _msgData)
10+
*/
11+
contract RuleEngineCoverageTest is Test, HelperContract {
12+
RuleEngineExposed public ruleEngineExposed;
13+
14+
// Known interface IDs
15+
bytes4 constant RULE_ENGINE_ID = 0x20c49ce7;
16+
bytes4 constant ERC1404_EXTEND_ID = 0x78a8de7d;
17+
bytes4 constant ERC165_ID = 0x01ffc9a7;
18+
bytes4 constant INVALID_ID = 0xffffffff;
19+
20+
function setUp() public {
21+
ruleEngineMock = new RuleEngine(
22+
RULE_ENGINE_OPERATOR_ADDRESS,
23+
ZERO_ADDRESS,
24+
ZERO_ADDRESS
25+
);
26+
ruleEngineExposed = new RuleEngineExposed(
27+
RULE_ENGINE_OPERATOR_ADDRESS,
28+
ZERO_ADDRESS,
29+
ZERO_ADDRESS
30+
);
31+
}
32+
33+
/*//////////////////////////////////////////////////////////////
34+
SUPPORTS INTERFACE
35+
//////////////////////////////////////////////////////////////*/
36+
37+
function testSupportsRuleEngineInterface() public view {
38+
assertTrue(ruleEngineMock.supportsInterface(RULE_ENGINE_ID));
39+
}
40+
41+
function testSupportsERC1404ExtendInterface() public view {
42+
assertTrue(ruleEngineMock.supportsInterface(ERC1404_EXTEND_ID));
43+
}
44+
45+
function testSupportsERC165Interface() public view {
46+
assertTrue(ruleEngineMock.supportsInterface(ERC165_ID));
47+
}
48+
49+
function testDoesNotSupportInvalidInterface() public view {
50+
assertFalse(ruleEngineMock.supportsInterface(INVALID_ID));
51+
}
52+
53+
/*//////////////////////////////////////////////////////////////
54+
MSG DATA
55+
//////////////////////////////////////////////////////////////*/
56+
57+
function testMsgDataReturnsCalldata() public view {
58+
bytes memory data = ruleEngineExposed.exposedMsgData();
59+
// Should return the calldata (selector of exposedMsgData)
60+
assertEq(data.length, 4);
61+
assertEq(bytes4(data), ruleEngineExposed.exposedMsgData.selector);
62+
}
63+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Test.sol";
5+
import "../HelperContractOwnable.sol";
6+
import {RuleEngineOwnableExposed} from "src/mocks/RuleEngineExposed.sol";
7+
8+
/**
9+
* @title Coverage tests for RuleEngineOwnable (supportsInterface fallback, _msgData)
10+
*/
11+
contract RuleEngineOwnableCoverageTest is Test, HelperContractOwnable {
12+
RuleEngineOwnableExposed public ruleEngineOwnableExposed;
13+
14+
// Known interface IDs
15+
bytes4 constant RULE_ENGINE_ID = 0x20c49ce7;
16+
bytes4 constant ERC1404_EXTEND_ID = 0x78a8de7d;
17+
bytes4 constant ERC173_ID = 0x7f5828d0;
18+
bytes4 constant ERC165_ID = 0x01ffc9a7;
19+
bytes4 constant INVALID_ID = 0xffffffff;
20+
21+
function setUp() public {
22+
ruleEngineMock = new RuleEngineOwnable(
23+
OWNER_ADDRESS,
24+
ZERO_ADDRESS,
25+
ZERO_ADDRESS
26+
);
27+
ruleEngineOwnableExposed = new RuleEngineOwnableExposed(
28+
OWNER_ADDRESS,
29+
ZERO_ADDRESS,
30+
ZERO_ADDRESS
31+
);
32+
}
33+
34+
/*//////////////////////////////////////////////////////////////
35+
SUPPORTS INTERFACE
36+
//////////////////////////////////////////////////////////////*/
37+
38+
function testSupportsRuleEngineInterface() public view {
39+
assertTrue(ruleEngineMock.supportsInterface(RULE_ENGINE_ID));
40+
}
41+
42+
function testSupportsERC1404ExtendInterface() public view {
43+
assertTrue(ruleEngineMock.supportsInterface(ERC1404_EXTEND_ID));
44+
}
45+
46+
function testSupportsERC173Interface() public view {
47+
assertTrue(ruleEngineMock.supportsInterface(ERC173_ID));
48+
}
49+
50+
function testSupportsERC165ViaAccessControlFallback() public view {
51+
// This hits line 61: AccessControl.supportsInterface(interfaceId)
52+
assertTrue(ruleEngineMock.supportsInterface(ERC165_ID));
53+
}
54+
55+
function testDoesNotSupportInvalidInterface() public view {
56+
// Falls through all checks including AccessControl.supportsInterface → false
57+
assertFalse(ruleEngineMock.supportsInterface(INVALID_ID));
58+
}
59+
60+
/*//////////////////////////////////////////////////////////////
61+
MSG DATA
62+
//////////////////////////////////////////////////////////////*/
63+
64+
function testMsgDataReturnsCalldata() public view {
65+
bytes memory data = ruleEngineOwnableExposed.exposedMsgData();
66+
// Should return the calldata (selector of exposedMsgData)
67+
assertEq(data.length, 4);
68+
assertEq(bytes4(data), ruleEngineOwnableExposed.exposedMsgData.selector);
69+
}
70+
}

0 commit comments

Comments
 (0)