Skip to content

Commit 4b9cdb7

Browse files
test(coverage): improvements (#387)
* test: add coverage * test: add coverage * chore: forge fmt
1 parent 59e22ce commit 4b9cdb7

File tree

5 files changed

+273
-196
lines changed

5 files changed

+273
-196
lines changed

src/BLSApkRegistry.sol

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
189189
quorumApkUpdatesLength == 0
190190
|| blockNumber < apkHistory[quorumNumber][0].updateBlockNumber
191191
) {
192-
revert(
193-
"BLSApkRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update"
194-
);
192+
revert BlockNumberBeforeFirstUpdate();
195193
}
196194

197195
// Loop backward through apkHistory until we find an entry that preceeds `blockNumber`

src/interfaces/IBLSApkRegistry.sol

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface IBLSApkRegistryErrors {
2424
error BlockNumberTooRecent();
2525
/// @notice Thrown when blocknumber and index provided is not the latest apk update.
2626
error BlockNumberNotLatest();
27+
/// @notice Thrown when the block number is before the first update.
28+
error BlockNumberBeforeFirstUpdate();
2729
}
2830

2931
interface IBLSApkRegistryTypes {

test/unit/BLSApkRegistryUnit.t.sol

+29
Original file line numberDiff line numberDiff line change
@@ -927,4 +927,33 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests {
927927
assertEq(quorumApk.Y, 0, "quorum apk not set to zero");
928928
}
929929
}
930+
931+
/**
932+
* @dev test that attempting to get APK indices for a block number before the first update reverts
933+
*/
934+
function testFuzz_quorumApkUpdates_BlockNumberBeforeFirstUpdate(
935+
uint32 blockNumber,
936+
uint8 quorumNumber
937+
) external {
938+
// Initialize quorum if not already initialized
939+
if (!initializedQuorums[quorumNumber]) {
940+
_initializeFuzzedQuorum(quorumNumber);
941+
}
942+
943+
bytes memory quorumNumbers = new bytes(1);
944+
quorumNumbers[0] = bytes1(quorumNumber);
945+
946+
// Register an operator to create first update
947+
address operator = _selectNewOperator();
948+
_registerDefaultBLSPubkey(operator);
949+
_registerOperator(operator, quorumNumbers);
950+
uint32 firstUpdateBlock = uint32(block.number);
951+
952+
// Ensure blockNumber is before first update
953+
cheats.assume(blockNumber < firstUpdateBlock);
954+
955+
// Expect revert when querying block before first update
956+
cheats.expectRevert(IBLSApkRegistryErrors.BlockNumberBeforeFirstUpdate.selector);
957+
blsApkRegistry.getApkIndicesAtBlockNumber(quorumNumbers, blockNumber);
958+
}
930959
}

0 commit comments

Comments
 (0)