Skip to content

Commit

Permalink
test: add unit tests with harness contract
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Dec 4, 2024
1 parent eb25059 commit e05771f
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 114 deletions.
210 changes: 116 additions & 94 deletions lcov.info
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
TN:
SF:script/Common.sol
FN:33,Common.setUp
FNDA:22,Common.setUp
DA:35,22
DA:51,22
DA:52,22
DA:53,22
DA:54,22
DA:56,22
FN:72,Common._deployContracts
FNDA:22,Common._deployContracts
DA:73,22
DA:75,22
DA:76,22
FNF:2
FNH:2
LF:9
LH:9
FN:39,Common.setUp
FNDA:29,Common.setUp
DA:41,29
DA:57,29
DA:58,29
DA:59,29
DA:60,29
DA:62,29
FN:78,Common._deployBuilderManager
FNDA:29,Common._deployBuilderManager
DA:79,29
DA:81,29
DA:82,29
FN:95,Common._deployBuilderManagerAsHarness
FNDA:29,Common._deployBuilderManagerAsHarness
DA:96,29
DA:98,29
DA:99,29
FNF:3
FNH:3
LF:12
LH:12
BRF:0
BRH:0
end_of_record
Expand All @@ -42,35 +47,35 @@ end_of_record
TN:
SF:src/contracts/BuildersManager.sol
FN:64,BuildersManager.eligible
FNDA:10,BuildersManager.eligible
DA:65,10
FNDA:23,BuildersManager.eligible
DA:65,23
BRDA:65,0,0,1
DA:66,9
DA:66,22
BRDA:66,1,0,1
DA:67,1
BRDA:67,2,0,1
FN:74,BuildersManager.
FNDA:22,BuildersManager.
DA:75,22
FNDA:58,BuildersManager.
DA:75,58
FN:79,BuildersManager.initialize
FNDA:22,BuildersManager.initialize
DA:86,22
DA:87,22
FNDA:58,BuildersManager.initialize
DA:86,58
DA:87,58
BRDA:87,3,0,-
DA:88,22
DA:88,58
BRDA:88,4,0,-
DA:89,22
DA:89,58
BRDA:89,5,0,-
DA:90,22
DA:90,58
BRDA:90,6,0,-
DA:92,22
DA:93,22
DA:95,22
DA:96,22
DA:97,22
DA:99,22
DA:100,22
DA:101,66
DA:92,58
DA:93,58
DA:95,58
DA:96,58
DA:97,58
DA:99,58
DA:100,58
DA:101,174
FN:108,BuildersManager.vouch
FNDA:1,BuildersManager.vouch
DA:109,1
Expand All @@ -84,8 +89,8 @@ DA:116,5
BRDA:116,9,0,-
DA:117,4
FN:121,BuildersManager.vouch
FNDA:4,BuildersManager.vouch
DA:122,4
FNDA:17,BuildersManager.vouch
DA:122,17
FN:126,BuildersManager.vouch
FNDA:1,BuildersManager.vouch
DA:127,1
Expand All @@ -98,12 +103,12 @@ BRDA:133,11,0,-
BRDA:133,11,1,3
DA:134,3
FN:138,BuildersManager.distributeYield
FNDA:0,BuildersManager.distributeYield
DA:139,0
DA:140,0
BRDA:140,12,0,-
DA:141,0
BRDA:141,13,0,-
FNDA:2,BuildersManager.distributeYield
DA:139,2
DA:140,2
BRDA:140,12,0,1
DA:141,1
BRDA:141,13,0,1
DA:142,0
DA:144,0
DA:145,0
Expand Down Expand Up @@ -137,21 +142,21 @@ FN:186,BuildersManager.settings
FNDA:3,BuildersManager.settings
DA:187,3
FN:191,BuildersManager.currentProjects
FNDA:0,BuildersManager.currentProjects
DA:192,0
FNDA:6,BuildersManager.currentProjects
DA:192,6
FN:196,BuildersManager.optimismFoundationAttesters
FNDA:0,BuildersManager.optimismFoundationAttesters
DA:197,0
FNDA:1,BuildersManager.optimismFoundationAttesters
DA:197,1
FN:203,BuildersManager.hashProject
FNDA:22,BuildersManager.hashProject
DA:204,33
FNDA:29,BuildersManager.hashProject
DA:204,40
FN:228,BuildersManager._vouch
FNDA:10,BuildersManager._vouch
DA:229,7
DA:230,7
DA:231,7
DA:232,7
BRDA:232,18,0,-
FNDA:23,BuildersManager._vouch
DA:229,20
DA:230,20
DA:231,20
DA:232,20
BRDA:232,18,0,4
FN:241,BuildersManager._validateOptimismVoter
FNDA:10,BuildersManager._validateOptimismVoter
DA:242,0
Expand Down Expand Up @@ -259,11 +264,11 @@ BRDA:346,40,0,-
DA:347,0
DA:348,0
FNF:22
FNH:18
FNH:21
LF:115
LH:75
LH:80
BRF:58
BRH:30
BRH:33
end_of_record
TN:
SF:test/integration/IntegrationBase.sol
Expand All @@ -285,18 +290,18 @@ end_of_record
TN:
SF:test/unit/UnitBuildersManagerBase.sol
FN:33,UnitBuildersManagerBase.setUp
FNDA:22,UnitBuildersManagerBase.setUp
DA:34,22
DA:35,22
DA:36,22
DA:38,22
DA:39,22
DA:40,22
DA:42,22
DA:43,22
DA:44,22
DA:46,22
DA:47,22
FNDA:29,UnitBuildersManagerBase.setUp
DA:34,29
DA:35,29
DA:36,29
DA:38,29
DA:39,29
DA:40,29
DA:41,29
DA:43,29
DA:44,29
DA:45,29
DA:47,29
FN:52,UnitBuildersManagerBase._mockVerifyIdentityAttestation
FNDA:11,UnitBuildersManagerBase._mockVerifyIdentityAttestation
DA:53,11
Expand All @@ -306,29 +311,46 @@ DA:61,5
DA:64,5
DA:70,5
DA:76,5
FN:81,UnitBuildersManagerBase._rsvFromJson
FNDA:22,UnitBuildersManagerBase._rsvFromJson
DA:82,22
DA:84,22
DA:85,22
DA:86,22
FN:89,UnitBuildersManagerBase._getSchemaHash
FNDA:22,UnitBuildersManagerBase._getSchemaHash
DA:90,22
DA:91,22
FN:94,UnitBuildersManagerBase._createOffchainAttestationsFromJson
FNDA:22,UnitBuildersManagerBase._createOffchainAttestationsFromJson
DA:99,22
DA:101,22
DA:118,22
FN:121,UnitBuildersManagerBase._createIdentityAttestations
FNDA:44,UnitBuildersManagerBase._createIdentityAttestations
DA:122,44
DA:124,44
FNF:7
FNH:7
LF:27
LH:27
FN:81,UnitBuildersManagerBase._getSchemaHash
FNDA:29,UnitBuildersManagerBase._getSchemaHash
DA:82,29
DA:83,29
FN:86,UnitBuildersManagerBase._createOffchainAttestationsFromJson
FNDA:29,UnitBuildersManagerBase._createOffchainAttestationsFromJson
DA:91,29
DA:93,29
DA:110,29
FN:113,UnitBuildersManagerBase._createIdentityAttestations
FNDA:58,UnitBuildersManagerBase._createIdentityAttestations
DA:114,58
DA:116,58
FNF:6
FNH:6
LF:23
LH:23
BRF:0
BRH:0
end_of_record
TN:
SF:test/unit/harness/BuilderManagerHarness.sol
FN:7,BuilderManagerHarness.populateEligibleProjects
FNDA:5,BuilderManagerHarness.populateEligibleProjects
DA:8,5
DA:9,15
FN:13,BuilderManagerHarness.populateEligibleVoters
FNDA:5,BuilderManagerHarness.populateEligibleVoters
DA:14,5
DA:15,20
FN:19,BuilderManagerHarness.populateCurrentProjects
FNDA:1,BuilderManagerHarness.populateCurrentProjects
DA:20,1
DA:21,3
DA:22,3
DA:23,3
FNF:3
FNH:3
LF:8
LH:8
BRF:0
BRH:0
end_of_record
44 changes: 41 additions & 3 deletions script/Common.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {BuildersDollar} from '@builders-dollar-token/BuildersDollar.sol';
import {EIP173ProxyWithReceive} from '@builders-dollar-token/vendor/EIP173ProxyWithReceive.sol';
import {TransparentUpgradeableProxy} from '@oz/proxy/transparent/TransparentUpgradeableProxy.sol';
import {BuildersManager, IBuildersManager} from 'contracts/BuildersManager.sol';
import {Script} from 'forge-std/Script.sol';
import {BuilderManagerHarness} from 'test/unit/harness/BuilderManagerHarness.sol';
// solhint-disable-next-line
import 'script/Registry.sol';

Expand All @@ -22,9 +25,10 @@ struct DeploymentParams {
* @dev This contract is intended for use in Scripts and Integration Tests
*/
contract Common is Script {
/// @notice BuildersManager contract
IBuildersManager public buildersManager;

// @notice Deployer address will be the owner of the proxy
/// @notice Deployer address will be the owner of the proxy
address public deployer;

/// @notice Deployment parameters for each chain
Expand Down Expand Up @@ -69,11 +73,11 @@ contract Common is Script {
});
}

function _deployContracts() internal {
function _deployBuildersManager() internal returns (BuildersManager _buildersManager) {
DeploymentParams memory _s = _deploymentParams[block.chainid];

address _implementation = address(new BuildersManager());
buildersManager = BuildersManager(
_buildersManager = BuildersManager(
address(
new TransparentUpgradeableProxy(
_implementation,
Expand All @@ -85,4 +89,38 @@ contract Common is Script {
)
);
}

function _deployBuildersManagerAsHarness() internal returns (BuilderManagerHarness _buildersManagerHarness) {
DeploymentParams memory _s = _deploymentParams[block.chainid];

address _implementation = address(new BuilderManagerHarness());
_buildersManagerHarness = BuilderManagerHarness(
address(
new TransparentUpgradeableProxy(
_implementation,
deployer,
abi.encodeWithSelector(
IBuildersManager.initialize.selector, _s.token, _s.eas, _s.name, _s.version, _s.settings
)
)
)
);
}

function _deployBuildersDollar() internal returns (BuildersDollar _buildersDollar, EIP173ProxyWithReceive _proxy) {
address _dai = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1;
address _aDai = 0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE;
address _aavePool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD;
address _aaveRewards = 0x929EC64c34a17401F460460D4B9390518E5B473e;
string memory _name = 'Builders Dollar';
string memory _symbol = 'OBDUSD';

_buildersDollar = new BuildersDollar(_dai, _aDai, _aavePool, _aaveRewards);

_proxy = new EIP173ProxyWithReceive(
address(_buildersDollar),
address(this),
abi.encodeWithSelector(_buildersDollar.initialize.selector, _name, _symbol)
);
}
}
2 changes: 1 addition & 1 deletion script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Deploy is Common {

function run() public {
vm.startBroadcast();
_deployContracts();
_deployBuildersManager();
vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion src/contracts/BuildersManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ contract BuildersManager is EIP712Upgradeable, Ownable2StepUpgradeable, IBuilder

/// @inheritdoc IBuildersManager
function validateOptimismVoter(bytes32 _identityAttestation) external returns (bool _verified) {
if (optimismFoundationAttester[msg.sender]) _verified = true;
if (eligibleVoter[msg.sender]) _verified = true;
else _verified = _validateOptimismVoter(_identityAttestation, msg.sender);
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/E2EDeploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract E2EDeploy is Deploy, Test {
function setUp() public override {
super.setUp();
vm.startPrank(deployer);
_deployContracts();
buildersManager = _deployBuildersManager();
vm.stopPrank();
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract IntegrationBase is Common, Test {
vm.createSelectFork(vm.rpcUrl('gnosis'));

vm.startPrank(owner);
_deployContracts();
_deployBuildersManager();
vm.stopPrank();
}
}
Loading

0 comments on commit e05771f

Please sign in to comment.