Skip to content

Commit

Permalink
chore: add auto-lint for test contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Aug 23, 2024
1 parent 4b84f0f commit 0d9df71
Show file tree
Hide file tree
Showing 44 changed files with 452 additions and 406 deletions.
13 changes: 12 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
"singleQuote": false,
"printWidth": 120,
"tabWidth": 2,
"quoteProps": "consistent"
"quoteProps": "consistent",
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"tabWidth": 4,
"useTabs": false
}
}
]
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
],
"./**/*.{ts,md,json}": [
"prettier --write"
],
"./test/**/*.sol": [
"prettier --write"
]
},
"devDependencies": {
Expand Down Expand Up @@ -80,6 +83,7 @@
"husky": "^9.1.5",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.4.1",
"solhint": "^5.0.3",
"solhint-plugin-lido": "^0.0.4",
"solidity-coverage": "^0.8.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ contract AccountingOracle__MockForLegacyOracle {
return ITimeProvider(CONSENSUS_CONTRACT).getTime();
}

function submitReportData(
AccountingOracle.ReportData calldata data,
uint256 /* contractVersion */
) external {
function submitReportData(AccountingOracle.ReportData calldata data, uint256 /* contractVersion */) external {
uint256 slotsElapsed = data.refSlot - _lastRefSlot;
_lastRefSlot = data.refSlot;

Expand Down
69 changes: 28 additions & 41 deletions test/0.4.24/contracts/HashConsensus__HarnessForLegacyOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pragma solidity 0.4.24;
import {IHashConsensus} from "contracts/0.4.24/oracle/LegacyOracle.sol";

contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {

uint256 internal _time = 2513040315;

/// Chain specification
Expand Down Expand Up @@ -47,16 +46,8 @@ contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {
_setFrameConfig(initialEpoch, epochsPerFrame, fastLaneLengthSlots);
}

function _setFrameConfig(
uint256 initialEpoch,
uint256 epochsPerFrame,
uint256 fastLaneLengthSlots
) internal {
_frameConfig = FrameConfig(
uint64(initialEpoch),
uint64(epochsPerFrame),
uint64(fastLaneLengthSlots)
);
function _setFrameConfig(uint256 initialEpoch, uint256 epochsPerFrame, uint256 fastLaneLengthSlots) internal {
_frameConfig = FrameConfig(uint64(initialEpoch), uint64(epochsPerFrame), uint64(fastLaneLengthSlots));
}

function setTime(uint256 newTime) external {
Expand All @@ -71,26 +62,20 @@ contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {
return _time;
}

function getChainConfig() external view returns (
uint256 slotsPerEpoch,
uint256 secondsPerSlot,
uint256 genesisTime
) {
function getChainConfig()
external
view
returns (uint256 slotsPerEpoch, uint256 secondsPerSlot, uint256 genesisTime)
{
return (SLOTS_PER_EPOCH, SECONDS_PER_SLOT, GENESIS_TIME);
}

function getFrameConfig() external view returns (
uint256 initialEpoch,
uint256 epochsPerFrame
) {
function getFrameConfig() external view returns (uint256 initialEpoch, uint256 epochsPerFrame) {
FrameConfig memory config = _frameConfig;
return (config.initialEpoch, config.epochsPerFrame);
}

function getCurrentFrame() external view returns (
uint256 refSlot,
uint256 reportProcessingDeadlineSlot
) {
function getCurrentFrame() external view returns (uint256 refSlot, uint256 reportProcessingDeadlineSlot) {
ConsensusFrame memory frame = _getCurrentFrame();
return (frame.refSlot, frame.reportProcessingDeadlineSlot);
}
Expand All @@ -99,15 +84,14 @@ contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {
return _getFrameAtTimestamp(_getTime(), _frameConfig);
}

function _getFrameAtTimestamp(uint256 timestamp, FrameConfig memory config)
internal view returns (ConsensusFrame memory)
{
function _getFrameAtTimestamp(
uint256 timestamp,
FrameConfig memory config
) internal view returns (ConsensusFrame memory) {
return _getFrameAtIndex(_computeFrameIndex(timestamp, config), config);
}

function _computeFrameIndex(uint256 timestamp, FrameConfig memory config)
internal view returns (uint256)
{
function _computeFrameIndex(uint256 timestamp, FrameConfig memory config) internal view returns (uint256) {
uint256 epoch = _computeEpochAtTimestamp(timestamp);
return (epoch - config.initialEpoch) / config.epochsPerFrame;
}
Expand All @@ -116,18 +100,20 @@ contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {
return _computeEpochAtSlot(_computeSlotAtTimestamp(timestamp));
}

function _getFrameAtIndex(uint256 frameIndex, FrameConfig memory config)
internal view returns (ConsensusFrame memory)
{
function _getFrameAtIndex(
uint256 frameIndex,
FrameConfig memory config
) internal view returns (ConsensusFrame memory) {
uint256 frameStartEpoch = _computeStartEpochOfFrameWithIndex(frameIndex, config);
uint256 frameStartSlot = _computeStartSlotAtEpoch(frameStartEpoch);
uint256 nextFrameStartSlot = frameStartSlot + config.epochsPerFrame * SLOTS_PER_EPOCH;

return ConsensusFrame({
index: frameIndex,
refSlot: uint64(frameStartSlot - 1),
reportProcessingDeadlineSlot: uint64(nextFrameStartSlot - 1 - DEADLINE_SLOT_OFFSET)
});
return
ConsensusFrame({
index: frameIndex,
refSlot: uint64(frameStartSlot - 1),
reportProcessingDeadlineSlot: uint64(nextFrameStartSlot - 1 - DEADLINE_SLOT_OFFSET)
});
}

// Math
Expand All @@ -146,9 +132,10 @@ contract HashConsensus__HarnessForLegacyOracle is IHashConsensus {
return epoch * SLOTS_PER_EPOCH;
}

function _computeStartEpochOfFrameWithIndex(uint256 frameIndex, FrameConfig memory config)
internal pure returns (uint256)
{
function _computeStartEpochOfFrameWithIndex(
uint256 frameIndex,
FrameConfig memory config
) internal pure returns (uint256) {
return config.initialEpoch + frameIndex * config.epochsPerFrame;
}

Expand Down
1 change: 0 additions & 1 deletion test/0.4.24/contracts/LegacyOracle__Harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface ITimeProvider {
}

contract LegacyOracle__Harness is LegacyOracle {

// @dev this is a way to not use block.timestamp in the tests
function _getTime() internal view returns (uint256) {
address accountingOracle = ACCOUNTING_ORACLE_POSITION.getStorageAddress();
Expand Down
38 changes: 14 additions & 24 deletions test/0.4.24/contracts/LegacyOracle__MockForAccountingOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ pragma solidity 0.4.24;
import "contracts/0.4.24/oracle/LegacyOracle.sol";

interface ILegacyOracle {
function getBeaconSpec() external view returns (
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime
);
function getBeaconSpec()
external
view
returns (uint64 epochsPerFrame, uint64 slotsPerEpoch, uint64 secondsPerSlot, uint64 genesisTime);

function getLastCompletedEpochId() external view returns (uint256);
}
Expand All @@ -20,9 +18,7 @@ interface ITimeProvider {
function getTime() external view returns (uint256);
}


contract LegacyOracle__MockForAccountingOracle is ILegacyOracle, LegacyOracle {

struct HandleConsensusLayerReportCallData {
uint256 totalCalls;
uint256 refSlot;
Expand All @@ -32,29 +28,27 @@ contract LegacyOracle__MockForAccountingOracle is ILegacyOracle, LegacyOracle {

HandleConsensusLayerReportCallData public lastCall__handleConsensusLayerReport;


function getBeaconSpec() external view returns (
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime
) {

function getBeaconSpec()
external
view
returns (uint64 epochsPerFrame, uint64 slotsPerEpoch, uint64 secondsPerSlot, uint64 genesisTime)
{
ChainSpec memory spec = _getChainSpec();
epochsPerFrame = spec.epochsPerFrame;
slotsPerEpoch = spec.slotsPerEpoch;
secondsPerSlot = spec.secondsPerSlot;
genesisTime = spec.genesisTime;
}

function setBeaconSpec(uint64 epochsPerFrame,
function setBeaconSpec(
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime) external {
uint64 genesisTime
) external {
_setChainSpec(ChainSpec(epochsPerFrame, slotsPerEpoch, secondsPerSlot, genesisTime));
}


function _getTime() internal view returns (uint256) {
address accountingOracle = ACCOUNTING_ORACLE_POSITION.getStorageAddress();
return ITimeProvider(accountingOracle).getTime();
Expand All @@ -64,16 +58,13 @@ contract LegacyOracle__MockForAccountingOracle is ILegacyOracle, LegacyOracle {
return _getTime();
}

function handleConsensusLayerReport(uint256 refSlot, uint256 clBalance, uint256 clValidators)
external
{
function handleConsensusLayerReport(uint256 refSlot, uint256 clBalance, uint256 clValidators) external {
++lastCall__handleConsensusLayerReport.totalCalls;
lastCall__handleConsensusLayerReport.refSlot = refSlot;
lastCall__handleConsensusLayerReport.clBalance = clBalance;
lastCall__handleConsensusLayerReport.clValidators = clValidators;
}


function setParams(
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
Expand Down Expand Up @@ -101,5 +92,4 @@ contract LegacyOracle__MockForAccountingOracle is ILegacyOracle, LegacyOracle {
function setLido(address lido) external {
LIDO_POSITION.setStorageAddress(lido);
}

}
26 changes: 18 additions & 8 deletions test/0.4.24/contracts/NodeOperatorsRegistry__Harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,29 @@ contract NodeOperatorsRegistry__Harness is NodeOperatorsRegistry {
uint256[] _nodeOperatorIds,
uint256[] _activeKeyCountsAfterAllocation
) external returns (bytes memory pubkeys, bytes memory signatures) {
(pubkeys, signatures) = _loadAllocatedSigningKeys(_keysCountToLoad, _nodeOperatorIds, _activeKeyCountsAfterAllocation);
(pubkeys, signatures) = _loadAllocatedSigningKeys(
_keysCountToLoad,
_nodeOperatorIds,
_activeKeyCountsAfterAllocation
);

obtainedPublicKeys = pubkeys;
obtainedSignatures = signatures;

emit ValidatorsKeysLoaded(pubkeys, signatures);
}

function harness__getSigningKeysAllocationData(uint256 _keysCount) external view returns (
uint256 allocatedKeysCount,
uint256[] memory nodeOperatorIds,
uint256[] memory activeKeyCountsAfterAllocation
) {
function harness__getSigningKeysAllocationData(
uint256 _keysCount
)
external
view
returns (
uint256 allocatedKeysCount,
uint256[] memory nodeOperatorIds,
uint256[] memory activeKeyCountsAfterAllocation
)
{
return _getSigningKeysAllocationData(_keysCount);
}

Expand All @@ -145,8 +155,8 @@ contract NodeOperatorsRegistry__Harness is NodeOperatorsRegistry {

/**
* @dev Extra care is needed.
* Doesn't update the active node operators counter and node operator's summary
*/
* Doesn't update the active node operators counter and node operator's summary
*/
function harness__unsafeSetNodeOperatorIsActive(uint256 _nodeOperatorId, bool _isActive) external {
_nodeOperators[_nodeOperatorId].active = _isActive;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ contract OracleReportSanityChecker__MockForLidoHandleOracleReport {
if (checkAccountingOracleReportReverts) revert();
}

function checkWithdrawalQueueOracleReport(uint256 _lastFinalizableRequestId, uint256 _reportTimestamp) external view {
function checkWithdrawalQueueOracleReport(
uint256 _lastFinalizableRequestId,
uint256 _reportTimestamp
) external view {
if (checkWithdrawalQueueOracleReportReverts) revert();
}

Expand All @@ -41,9 +44,9 @@ contract OracleReportSanityChecker__MockForLidoHandleOracleReport {
uint256 _etherToLockForWithdrawals,
uint256 _newSharesToBurnForWithdrawals
)
external
view
returns (uint256 withdrawals, uint256 elRewards, uint256 simulatedSharesToBurn, uint256 sharesToBurn)
external
view
returns (uint256 withdrawals, uint256 elRewards, uint256 simulatedSharesToBurn, uint256 sharesToBurn)
{
withdrawals = _withdrawals;
elRewards = _elRewards;
Expand Down
20 changes: 11 additions & 9 deletions test/0.4.24/contracts/SigningKeys__Harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ contract SigningKeys__Harness {
return KEYSSIGS_POSITION.saveKeysSigs(_nodeOperatorId, _startIndex, _keysCount, _publicKeys, _signatures);
}

function removeKeysSigs(uint256 _nodeOperatorId, uint256 _startIndex, uint256 _keysCount, uint256 _lastIndex)
external
returns (uint256)
{
function removeKeysSigs(
uint256 _nodeOperatorId,
uint256 _startIndex,
uint256 _keysCount,
uint256 _lastIndex
) external returns (uint256) {
return KEYSSIGS_POSITION.removeKeysSigs(_nodeOperatorId, _startIndex, _keysCount, _lastIndex);
}

function loadKeysSigs(uint256 _nodeOperatorId, uint256 _startIndex, uint256 _keysCount)
external
view
returns (bytes memory pubkeys, bytes memory signatures)
{
function loadKeysSigs(
uint256 _nodeOperatorId,
uint256 _startIndex,
uint256 _keysCount
) external view returns (bytes memory pubkeys, bytes memory signatures) {
(pubkeys, signatures) = SigningKeys.initKeysSigsBuf(_keysCount);

KEYSSIGS_POSITION.loadKeysSigs(
Expand Down
Loading

0 comments on commit 0d9df71

Please sign in to comment.