mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 01:38:32 +00:00
## Summary
### Configuration
- Remove deprecated `deny_warnings` config key from foundry.toml
- Add global `[lint]` config to suppress naming convention warnings for
AVS/EL/ERC patterns (`mixed-case-function`, `mixed-case-variable`)
### DataHavenServiceManager Refactoring
- Rename immutable variables to SCREAMING_SNAKE_CASE
(`_allocationManager` → `_ALLOCATION_MANAGER`, `_rewardsCoordinator` →
`_REWARDS_COORDINATOR`)
- Wrap modifier logic in internal functions (`_checkRewardsInitiator`,
`_checkValidator`, `_checkAllocationManager`) to reduce contract size
- Add `_toAddress` helper with assembly for safe bytes-to-address
conversion
### Safe Typecasting
- Replace direct typecasts with OpenZeppelin's SafeCast library in
deploy scripts and test utilities
- Use `.toUint32()`, `.toUint64()`, `.toUint160()` for
overflow-protected conversions
- Replace `bytes32("wrong origin")` string cast with hex literal in test
deployer
### Code Cleanup
- Remove 25+ unused imports across script and test files
- Convert plain imports to named imports for better clarity
- Use `SafeERC20.safeTransfer()` for token transfers in tests
- Change `view` to `pure` where appropriate
## Test plan
- [x] `forge build` completes with no warnings
- [x] `forge test` passes all 10 tests
68 lines
2.2 KiB
Solidity
68 lines
2.2 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity ^0.8.27;
|
|
|
|
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
|
|
|
|
/**
|
|
* @title TestUtils
|
|
* @notice Utility functions for testing DataHaven contracts
|
|
*/
|
|
library TestUtils {
|
|
using SafeCast for uint256;
|
|
|
|
/**
|
|
* @notice Generates mock validator addresses for testing
|
|
* @param count Number of validators to generate
|
|
* @param startIndex Starting index for validator numbering (defaults to 0)
|
|
* @return Array of validator addresses
|
|
*/
|
|
function generateMockValidatorsAddresses(
|
|
uint256 count,
|
|
uint256 startIndex
|
|
) internal pure returns (address[] memory) {
|
|
address[] memory validators = new address[](count);
|
|
for (uint256 i = 0; i < count; i++) {
|
|
validators[i] = address((startIndex + i + 1).toUint160());
|
|
}
|
|
return validators;
|
|
}
|
|
|
|
/**
|
|
* @notice Generates mock validator addresses for testing (overload with default startIndex = 0)
|
|
* @param count Number of validators to generate
|
|
* @return Array of validator addresses
|
|
*/
|
|
function generateMockValidatorsAddresses(
|
|
uint256 count
|
|
) internal pure returns (address[] memory) {
|
|
return generateMockValidatorsAddresses(count, 0);
|
|
}
|
|
|
|
/**
|
|
* @notice Generates mock validator addresses for testing
|
|
* @param count Number of validators to generate
|
|
* @param startIndex Starting index for validator numbering (defaults to 0)
|
|
* @return Array of validator addresses
|
|
*/
|
|
function generateMockValidators(
|
|
uint256 count,
|
|
uint256 startIndex
|
|
) internal pure returns (bytes32[] memory) {
|
|
bytes32[] memory validators = new bytes32[](count);
|
|
for (uint256 i = 0; i < count; i++) {
|
|
validators[i] = bytes32(startIndex + i + 1);
|
|
}
|
|
return validators;
|
|
}
|
|
|
|
/**
|
|
* @notice Generates mock validator addresses for testing (overload with default startIndex = 0)
|
|
* @param count Number of validators to generate
|
|
* @return Array of validator addresses
|
|
*/
|
|
function generateMockValidators(
|
|
uint256 count
|
|
) internal pure returns (bytes32[] memory) {
|
|
return generateMockValidators(count, 0);
|
|
}
|
|
}
|