From 6606b8f5c62adef5487fdfd5401c32f8c524db06 Mon Sep 17 00:00:00 2001 From: scolear Date: Wed, 25 Sep 2024 11:44:47 +0200 Subject: [PATCH] forge fmt --- src/DLCBTC.sol | 10 +- src/DLCManager.sol | 212 +++++++------------------ src/MapWithTimeData.sol | 32 ++-- src/SimpleKeyRegistry32.sol | 9 +- test/MapWithTimeData.t.sol | 90 ++--------- test/mocks/MapWithTimeDataContract.sol | 22 +-- 6 files changed, 93 insertions(+), 282 deletions(-) diff --git a/src/DLCBTC.sol b/src/DLCBTC.sol index bdcba44..8432c07 100644 --- a/src/DLCBTC.sol +++ b/src/DLCBTC.sol @@ -20,12 +20,7 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; * @custom:contact eng@dlc.link * @custom:website https://www.dlc.link */ -contract DLCBTC is - Initializable, - ERC20Upgradeable, - ERC20PermitUpgradeable, - OwnableUpgradeable -{ +contract DLCBTC is Initializable, ERC20Upgradeable, ERC20PermitUpgradeable, OwnableUpgradeable { mapping(address => bool) public blacklisted; // deprecated. there is no blacklisting anymore address private _minter; address private _burner; @@ -48,8 +43,9 @@ contract DLCBTC is } modifier onlyOwnerOrCCIPMinter() { - if (msg.sender != _minter && msg.sender != owner()) + if (msg.sender != _minter && msg.sender != owner()) { revert NotAuthorized(); + } _; } diff --git a/src/DLCManager.sol b/src/DLCManager.sol index 1f355cf..a04a4b6 100644 --- a/src/DLCManager.sol +++ b/src/DLCManager.sol @@ -25,11 +25,7 @@ import "./DLCBTC.sol"; * @custom:contact eng@dlc.link * @custom:website https://www.dlc.link */ -contract DLCManager is - Initializable, - AccessControlDefaultAdminRulesUpgradeable, - PausableUpgradeable -{ +contract DLCManager is Initializable, AccessControlDefaultAdminRulesUpgradeable, PausableUpgradeable { using DLCLink for DLCLink.DLC; using DLCLink for DLCLink.DLCStatus; using SafeERC20 for DLCBTC; @@ -38,12 +34,9 @@ contract DLCManager is // STATE VARIABLES // //////////////////////////////////////////////////////////////// - bytes32 public constant DLC_ADMIN_ROLE = - 0x2bf88000669ee6f7a648a231f4adbc117f5a8e34f980c08420b9b9a9f2640aa1; // keccak256("DLC_ADMIN_ROLE") - bytes32 public constant WHITELISTED_CONTRACT = - 0xec26500344858148ae6c4dd068dc3bae426095ee44cdb32b94288d883648f619; // keccak256("WHITELISTED_CONTRACT") - bytes32 public constant APPROVED_SIGNER = - 0xc726b34d4e524d7255dc7e36b5dfca6bd2dcd2891ae8c75d511a7e82da8696e5; // keccak256("APPROVED_SIGNER") + bytes32 public constant DLC_ADMIN_ROLE = 0x2bf88000669ee6f7a648a231f4adbc117f5a8e34f980c08420b9b9a9f2640aa1; // keccak256("DLC_ADMIN_ROLE") + bytes32 public constant WHITELISTED_CONTRACT = 0xec26500344858148ae6c4dd068dc3bae426095ee44cdb32b94288d883648f619; // keccak256("WHITELISTED_CONTRACT") + bytes32 public constant APPROVED_SIGNER = 0xc726b34d4e524d7255dc7e36b5dfca6bd2dcd2891ae8c75d511a7e82da8696e5; // keccak256("APPROVED_SIGNER") uint256 private _index; mapping(uint256 => DLCLink.DLC) public dlcs; @@ -114,8 +107,9 @@ contract DLCManager is } modifier onlyWhitelisted() { - if (whitelistingEnabled && !_whitelistedAddresses[msg.sender]) + if (whitelistingEnabled && !_whitelistedAddresses[msg.sender]) { revert NotWhitelisted(); + } _; } @@ -134,8 +128,9 @@ contract DLCManager is __AccessControlDefaultAdminRules_init(2 days, defaultAdmin); _grantRole(DLC_ADMIN_ROLE, dlcAdminRole); _minimumThreshold = 2; - if (threshold < _minimumThreshold) + if (threshold < _minimumThreshold) { revert ThresholdTooLow(_minimumThreshold); + } _threshold = threshold; _index = 0; tssCommitment = 0x0; @@ -159,20 +154,8 @@ contract DLCManager is event CreateDLC(bytes32 uuid, address creator, uint256 timestamp); - event SetStatusFunded( - bytes32 uuid, - string btcTxId, - address creator, - uint256 newValueLocked, - uint256 amountToMint - ); - event SetStatusPending( - bytes32 uuid, - string btcTxId, - address creator, - string taprootPubKey, - uint256 newValueLocked - ); + event SetStatusFunded(bytes32 uuid, string btcTxId, address creator, uint256 newValueLocked, uint256 amountToMint); + event SetStatusPending(bytes32 uuid, string btcTxId, address creator, string taprootPubKey, uint256 newValueLocked); event Withdraw(bytes32 uuid, uint256 amount, address sender); event SetThreshold(uint16 newThreshold); @@ -195,19 +178,8 @@ contract DLCManager is // INTERNAL FUNCTIONS // //////////////////////////////////////////////////////////////// - function _generateUUID( - address sender, - uint256 nonce - ) private view returns (bytes32) { - return - keccak256( - abi.encodePacked( - sender, - nonce, - blockhash(block.number - 1), - block.chainid - ) - ); + function _generateUUID(address sender, uint256 nonce) private view returns (bytes32) { + return keccak256(abi.encodePacked(sender, nonce, blockhash(block.number - 1), block.chainid)); } /** @@ -218,25 +190,18 @@ contract DLCManager is * @param message Original message that was signed. * @param signatures Byte array of at least 'threshold' number of signatures. */ - function _attestorMultisigIsValid( - bytes memory message, - bytes[] memory signatures - ) internal view { + function _attestorMultisigIsValid(bytes memory message, bytes[] memory signatures) internal view { if (signatures.length < _threshold) revert NotEnoughSignatures(); - bytes32 prefixedMessageHash = MessageHashUtils.toEthSignedMessageHash( - keccak256(message) - ); + bytes32 prefixedMessageHash = MessageHashUtils.toEthSignedMessageHash(keccak256(message)); if (_hasDuplicates(signatures)) revert DuplicateSignature(); for (uint256 i = 0; i < signatures.length; i++) { - address attestorPubKey = ECDSA.recover( - prefixedMessageHash, - signatures[i] - ); - if (!hasRole(APPROVED_SIGNER, attestorPubKey)) + address attestorPubKey = ECDSA.recover(prefixedMessageHash, signatures[i]); + if (!hasRole(APPROVED_SIGNER, attestorPubKey)) { revert InvalidSigner(); + } } } @@ -246,11 +211,9 @@ contract DLCManager is * @param signatures Array of signatures. * @return bool True if there are duplicates, false otherwise. */ - function _hasDuplicates( - bytes[] memory signatures - ) internal pure returns (bool) { - for (uint i = 0; i < signatures.length - 1; i++) { - for (uint j = i + 1; j < signatures.length; j++) { + function _hasDuplicates(bytes[] memory signatures) internal pure returns (bool) { + for (uint256 i = 0; i < signatures.length - 1; i++) { + for (uint256 j = i + 1; j < signatures.length; j++) { if (keccak256(signatures[i]) == keccak256(signatures[j])) { return true; } @@ -277,12 +240,7 @@ contract DLCManager is * @notice Creates a new vault for the user * @return bytes32 uuid of the new vault/DLC */ - function setupVault() - external - whenNotPaused - onlyWhitelisted - returns (bytes32) - { + function setupVault() external whenNotPaused onlyWhitelisted returns (bytes32) { bytes32 _uuid = _generateUUID(tx.origin, _index); dlcs[_index] = DLCLink.DLC({ @@ -319,16 +277,12 @@ contract DLCManager is * @param signatures Signatures of the Attestors. * @param newValueLocked New value locked in the DLC. */ - function setStatusFunded( - bytes32 uuid, - string calldata btcTxId, - bytes[] calldata signatures, - uint256 newValueLocked - ) external whenNotPaused onlyApprovedSigners { - _attestorMultisigIsValid( - abi.encode(uuid, btcTxId, "set-status-funded", newValueLocked), - signatures - ); + function setStatusFunded(bytes32 uuid, string calldata btcTxId, bytes[] calldata signatures, uint256 newValueLocked) + external + whenNotPaused + onlyApprovedSigners + { + _attestorMultisigIsValid(abi.encode(uuid, btcTxId, "set-status-funded", newValueLocked), signatures); DLCLink.DLC storage dlc = dlcs[dlcIDsByUUID[uuid]]; if (dlc.uuid == bytes32(0)) revert DLCNotFound(); @@ -362,13 +316,7 @@ contract DLCManager is _mintTokens(dlc.creator, amountToMint); - emit SetStatusFunded( - uuid, - btcTxId, - dlc.creator, - newValueLocked, - amountToMint - ); + emit SetStatusFunded(uuid, btcTxId, dlc.creator, newValueLocked, amountToMint); } /** @@ -387,29 +335,19 @@ contract DLCManager is string calldata taprootPubKey, uint256 newValueLocked ) external whenNotPaused onlyApprovedSigners { - _attestorMultisigIsValid( - abi.encode(uuid, wdTxId, "set-status-pending", newValueLocked), - signatures - ); + _attestorMultisigIsValid(abi.encode(uuid, wdTxId, "set-status-pending", newValueLocked), signatures); DLCLink.DLC storage dlc = dlcs[dlcIDsByUUID[uuid]]; if (dlc.uuid == bytes32(0)) revert DLCNotFound(); - if ( - dlc.status != DLCLink.DLCStatus.READY && - dlc.status != DLCLink.DLCStatus.FUNDED - ) revert DLCNotReadyOrFunded(); + if (dlc.status != DLCLink.DLCStatus.READY && dlc.status != DLCLink.DLCStatus.FUNDED) { + revert DLCNotReadyOrFunded(); + } dlc.status = DLCLink.DLCStatus.AUX_STATE_1; dlc.wdTxId = wdTxId; dlc.taprootPubKey = taprootPubKey; - emit SetStatusPending( - uuid, - wdTxId, - dlc.creator, - taprootPubKey, - newValueLocked - ); + emit SetStatusPending(uuid, wdTxId, dlc.creator, taprootPubKey, newValueLocked); } /** @@ -418,20 +356,15 @@ contract DLCManager is * @param uuid uuid of the vault/DLC * @param amount amount of tokens to burn */ - function withdraw( - bytes32 uuid, - uint256 amount - ) external onlyVaultCreator(uuid) whenNotPaused { + function withdraw(bytes32 uuid, uint256 amount) external onlyVaultCreator(uuid) whenNotPaused { DLCLink.DLC storage dlc = dlcs[dlcIDsByUUID[uuid]]; // Validation checks if (dlc.uuid == bytes32(0)) revert DLCNotFound(); if (dlc.status != DLCLink.DLCStatus.FUNDED) revert DLCNotFunded(); - if (amount > dlcBTC.balanceOf(dlc.creator)) - revert InsufficientTokenBalance( - dlcBTC.balanceOf(dlc.creator), - amount - ); + if (amount > dlcBTC.balanceOf(dlc.creator)) { + revert InsufficientTokenBalance(dlcBTC.balanceOf(dlc.creator), amount); + } if (amount > dlc.valueMinted) { revert InsufficientMintedBalance(dlc.valueMinted, amount); } @@ -452,9 +385,7 @@ contract DLCManager is return _dlc; } - function getDLCByIndex( - uint256 index - ) external view returns (DLCLink.DLC memory) { + function getDLCByIndex(uint256 index) external view returns (DLCLink.DLC memory) { return dlcs[index]; } @@ -464,16 +395,11 @@ contract DLCManager is * @param endIndex end index (not inclusive). * @return DLCLink.DLC[] list of DLCs. */ - function getAllDLCs( - uint256 startIndex, - uint256 endIndex - ) external view returns (DLCLink.DLC[] memory) { + function getAllDLCs(uint256 startIndex, uint256 endIndex) external view returns (DLCLink.DLC[] memory) { if (startIndex >= endIndex) revert InvalidRange(); if (endIndex > _index) endIndex = _index; - DLCLink.DLC[] memory dlcSubset = new DLCLink.DLC[]( - endIndex - startIndex - ); + DLCLink.DLC[] memory dlcSubset = new DLCLink.DLC[](endIndex - startIndex); for (uint256 i = startIndex; i < endIndex; i++) { dlcSubset[i - startIndex] = dlcs[i]; @@ -486,15 +412,11 @@ contract DLCManager is return getDLC(uuid); } - function getAllVaultUUIDsForAddress( - address owner - ) public view returns (bytes32[] memory) { + function getAllVaultUUIDsForAddress(address owner) public view returns (bytes32[] memory) { return userVaults[owner]; } - function getAllVaultsForAddress( - address owner - ) public view returns (DLCLink.DLC[] memory) { + function getAllVaultsForAddress(address owner) public view returns (DLCLink.DLC[] memory) { bytes32[] memory uuids = getAllVaultUUIDsForAddress(owner); DLCLink.DLC[] memory vaults = new DLCLink.DLC[](uuids.length); for (uint256 i = 0; i < uuids.length; i++) { @@ -524,16 +446,11 @@ contract DLCManager is //////////////////////////////////////////////////////////////// function _hasAnyRole(address account) internal view returns (bool) { - return - hasRole(DLC_ADMIN_ROLE, account) || - hasRole(WHITELISTED_CONTRACT, account) || - hasRole(APPROVED_SIGNER, account); + return hasRole(DLC_ADMIN_ROLE, account) || hasRole(WHITELISTED_CONTRACT, account) + || hasRole(APPROVED_SIGNER, account); } - function grantRole( - bytes32 role, - address account - ) public override(AccessControlDefaultAdminRulesUpgradeable) { + function grantRole(bytes32 role, address account) public override(AccessControlDefaultAdminRulesUpgradeable) { if (_hasAnyRole(account)) revert IncompatibleRoles(); // role based setup ensures that address can only be added once @@ -541,15 +458,13 @@ contract DLCManager is if (role == APPROVED_SIGNER) _signerCount++; } - function revokeRole( - bytes32 role, - address account - ) public override(AccessControlDefaultAdminRulesUpgradeable) { + function revokeRole(bytes32 role, address account) public override(AccessControlDefaultAdminRulesUpgradeable) { super.revokeRole(role, account); if (role == APPROVED_SIGNER) { - if (_signerCount == _minimumThreshold) + if (_signerCount == _minimumThreshold) { revert ThresholdMinimumReached(_minimumThreshold); + } _signerCount--; } } @@ -563,8 +478,9 @@ contract DLCManager is } function setThreshold(uint16 newThreshold) external onlyAdmin { - if (newThreshold < _minimumThreshold) + if (newThreshold < _minimumThreshold) { revert ThresholdTooLow(_minimumThreshold); + } _threshold = newThreshold; emit SetThreshold(newThreshold); } @@ -582,9 +498,7 @@ contract DLCManager is emit WhitelistAddress(addressToWhitelist); } - function unwhitelistAddress( - address addressToUnWhitelist - ) external onlyAdmin { + function unwhitelistAddress(address addressToUnWhitelist) external onlyAdmin { _whitelistedAddresses[addressToUnWhitelist] = false; emit UnwhitelistAddress(addressToUnWhitelist); } @@ -600,44 +514,34 @@ contract DLCManager is } function setBtcMintFeeRate(uint256 newBtcMintFeeRate) external onlyAdmin { - if (newBtcMintFeeRate > 10000) + if (newBtcMintFeeRate > 10000) { revert FeeRateOutOfBounds(newBtcMintFeeRate); + } btcMintFeeRate = newBtcMintFeeRate; emit SetBtcMintFeeRate(newBtcMintFeeRate); } - function setBtcRedeemFeeRate( - uint256 newBtcRedeemFeeRate - ) external onlyAdmin { + function setBtcRedeemFeeRate(uint256 newBtcRedeemFeeRate) external onlyAdmin { btcRedeemFeeRate = newBtcRedeemFeeRate; emit SetBtcRedeemFeeRate(newBtcRedeemFeeRate); } - function setBtcFeeRecipient( - string calldata btcFeeRecipientToSet - ) external onlyAdmin { + function setBtcFeeRecipient(string calldata btcFeeRecipientToSet) external onlyAdmin { btcFeeRecipient = btcFeeRecipientToSet; emit SetBtcFeeRecipient(btcFeeRecipient); } - function setBtcFeeRecipientForVault( - bytes32 uuid, - string calldata btcFeeRecipientToSet - ) external onlyAdmin { + function setBtcFeeRecipientForVault(bytes32 uuid, string calldata btcFeeRecipientToSet) external onlyAdmin { DLCLink.DLC storage dlc = dlcs[dlcIDsByUUID[uuid]]; dlc.btcFeeRecipient = btcFeeRecipientToSet; } - function setWhitelistingEnabled( - bool isWhitelistingEnabled - ) external onlyAdmin { + function setWhitelistingEnabled(bool isWhitelistingEnabled) external onlyAdmin { whitelistingEnabled = isWhitelistingEnabled; emit SetWhitelistingEnabled(isWhitelistingEnabled); } - function transferTokenContractOwnership( - address newOwner - ) external onlyAdmin { + function transferTokenContractOwnership(address newOwner) external onlyAdmin { dlcBTC.transferOwnership(newOwner); emit TransferTokenContractOwnership(newOwner); } diff --git a/src/MapWithTimeData.sol b/src/MapWithTimeData.sol index 66038a3..42129b1 100644 --- a/src/MapWithTimeData.sol +++ b/src/MapWithTimeData.sol @@ -13,22 +13,15 @@ library MapWithTimeData { error AlreadyEnabled(); uint256 private constant ENABLED_TIME_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFF; - uint256 private constant DISABLED_TIME_MASK = - 0xFFFFFFFFFFFFFFFFFFFFFFFF << 48; + uint256 private constant DISABLED_TIME_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFF << 48; - function add( - EnumerableMap.AddressToUintMap storage self, - address addr - ) internal { + function add(EnumerableMap.AddressToUintMap storage self, address addr) internal { if (!self.set(addr, uint256(0))) { revert AlreadyAdded(); } } - function disable( - EnumerableMap.AddressToUintMap storage self, - address addr - ) internal { + function disable(EnumerableMap.AddressToUintMap storage self, address addr) internal { uint256 value = self.get(addr); if (uint48(value) == 0 || uint48(value >> 48) != 0) { @@ -39,10 +32,7 @@ library MapWithTimeData { self.set(addr, value); } - function enable( - EnumerableMap.AddressToUintMap storage self, - address addr - ) internal { + function enable(EnumerableMap.AddressToUintMap storage self, address addr) internal { uint256 value = self.get(addr); if (uint48(value) != 0 && uint48(value >> 48) == 0) { @@ -53,10 +43,7 @@ library MapWithTimeData { self.set(addr, value); } - function atWithTimes( - EnumerableMap.AddressToUintMap storage self, - uint256 idx - ) + function atWithTimes(EnumerableMap.AddressToUintMap storage self, uint256 idx) internal view returns (address key, uint48 enabledTime, uint48 disabledTime) @@ -67,10 +54,11 @@ library MapWithTimeData { disabledTime = uint48(value >> 48); } - function getTimes( - EnumerableMap.AddressToUintMap storage self, - address addr - ) internal view returns (uint48 enabledTime, uint48 disabledTime) { + function getTimes(EnumerableMap.AddressToUintMap storage self, address addr) + internal + view + returns (uint48 enabledTime, uint48 disabledTime) + { uint256 value = self.get(addr); enabledTime = uint48(value); disabledTime = uint48(value >> 48); diff --git a/src/SimpleKeyRegistry32.sol b/src/SimpleKeyRegistry32.sol index b9a8c75..90f5de6 100644 --- a/src/SimpleKeyRegistry32.sol +++ b/src/SimpleKeyRegistry32.sol @@ -22,9 +22,7 @@ abstract contract SimpleKeyRegistry32 { return keyToOperator[key]; } - function getCurrentOperatorKey( - address operator - ) public view returns (bytes32) { + function getCurrentOperatorKey(address operator) public view returns (bytes32) { uint208 keyIdx = operatorToIdx[operator].latest(); if (keyIdx == EMPTY_KEY_IDX) { @@ -34,10 +32,7 @@ abstract contract SimpleKeyRegistry32 { return idxToKey[keyIdx]; } - function getOperatorKeyAt( - address operator, - uint48 timestamp - ) public view returns (bytes32) { + function getOperatorKeyAt(address operator, uint48 timestamp) public view returns (bytes32) { uint208 keyIdx = operatorToIdx[operator].upperLookup(timestamp); if (keyIdx == EMPTY_KEY_IDX) { diff --git a/test/MapWithTimeData.t.sol b/test/MapWithTimeData.t.sol index daa6c88..351e481 100644 --- a/test/MapWithTimeData.t.sol +++ b/test/MapWithTimeData.t.sol @@ -24,8 +24,8 @@ contract DefaultOperatorRewardsTest is Test { } function test_All() public { - uint256 blockTimestamp = (((block.timestamp * block.timestamp) / - block.timestamp) * block.timestamp) / block.timestamp; + uint256 blockTimestamp = + (((block.timestamp * block.timestamp) / block.timestamp) * block.timestamp) / block.timestamp; blockTimestamp = blockTimestamp + 1_720_700_948; vm.warp(blockTimestamp); @@ -34,11 +34,7 @@ contract DefaultOperatorRewardsTest is Test { vm.expectRevert(MapWithTimeData.AlreadyAdded.selector); mapWithTimeDataContract.add(alice); - ( - address key, - uint48 enabledTime, - uint48 disabledTime - ) = mapWithTimeDataContract.atWithTimes(0); + (address key, uint48 enabledTime, uint48 disabledTime) = mapWithTimeDataContract.atWithTimes(0); assertEq(key, alice); assertEq(enabledTime, 0); assertEq(disabledTime, 0); @@ -47,19 +43,14 @@ contract DefaultOperatorRewardsTest is Test { assertEq(enabledTime, 0); assertEq(disabledTime, 0); - assertEq( - mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), - false - ); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), false); mapWithTimeDataContract.enable(alice); vm.expectRevert(MapWithTimeData.AlreadyEnabled.selector); mapWithTimeDataContract.enable(alice); - (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes( - 0 - ); + (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes(0); assertEq(key, alice); assertEq(enabledTime, blockTimestamp); assertEq(disabledTime, 0); @@ -68,10 +59,7 @@ contract DefaultOperatorRewardsTest is Test { assertEq(enabledTime, blockTimestamp); assertEq(disabledTime, 0); - assertEq( - mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), - true - ); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), true); blockTimestamp = blockTimestamp + 1; vm.warp(blockTimestamp); @@ -81,9 +69,7 @@ contract DefaultOperatorRewardsTest is Test { vm.expectRevert(MapWithTimeData.NotEnabled.selector); mapWithTimeDataContract.disable(alice); - (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes( - 0 - ); + (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes(0); assertEq(key, alice); assertEq(enabledTime, blockTimestamp - 1); assertEq(disabledTime, blockTimestamp); @@ -92,40 +78,17 @@ contract DefaultOperatorRewardsTest is Test { assertEq(enabledTime, blockTimestamp - 1); assertEq(disabledTime, blockTimestamp); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp - 2) - ), - false - ); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp - 1) - ), - true - ); - assertEq( - mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), - true - ); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp + 1) - ), - false - ); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp - 2)), false); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp - 1)), true); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), true); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp + 1)), false); blockTimestamp = blockTimestamp + 1; vm.warp(blockTimestamp); mapWithTimeDataContract.enable(alice); - (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes( - 0 - ); + (key, enabledTime, disabledTime) = mapWithTimeDataContract.atWithTimes(0); assertEq(key, alice); assertEq(enabledTime, blockTimestamp); assertEq(disabledTime, 0); @@ -134,30 +97,9 @@ contract DefaultOperatorRewardsTest is Test { assertEq(enabledTime, blockTimestamp); assertEq(disabledTime, 0); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp - 2) - ), - false - ); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp - 1) - ), - false - ); - assertEq( - mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), - true - ); - assertEq( - mapWithTimeDataContract.wasActiveAt( - alice, - uint48(blockTimestamp + 1) - ), - true - ); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp - 2)), false); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp - 1)), false); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp)), true); + assertEq(mapWithTimeDataContract.wasActiveAt(alice, uint48(blockTimestamp + 1)), true); } } diff --git a/test/mocks/MapWithTimeDataContract.sol b/test/mocks/MapWithTimeDataContract.sol index 19f6ce5..c449951 100644 --- a/test/mocks/MapWithTimeDataContract.sol +++ b/test/mocks/MapWithTimeDataContract.sol @@ -23,31 +23,17 @@ contract MapWithTimeDataContract { elements.enable(addr); } - function atWithTimes( - uint256 idx - ) - public - view - returns (address key, uint48 enabledTime, uint48 disabledTime) - { + function atWithTimes(uint256 idx) public view returns (address key, uint48 enabledTime, uint48 disabledTime) { return elements.atWithTimes(idx); } - function getTimes( - address addr - ) public view returns (uint48 enabledTime, uint48 disabledTime) { + function getTimes(address addr) public view returns (uint48 enabledTime, uint48 disabledTime) { return elements.getTimes(addr); } - function wasActiveAt( - address addr, - uint48 timestamp - ) public view returns (bool) { + function wasActiveAt(address addr, uint48 timestamp) public view returns (bool) { (uint48 enabledTime, uint48 disabledTime) = getTimes(addr); - return - enabledTime != 0 && - enabledTime <= timestamp && - (disabledTime == 0 || disabledTime >= timestamp); + return enabledTime != 0 && enabledTime <= timestamp && (disabledTime == 0 || disabledTime >= timestamp); } }