Skip to content

Commit

Permalink
test(coverage): improvements (#387)
Browse files Browse the repository at this point in the history
* test: add coverage

* test: add coverage

* chore: forge fmt
  • Loading branch information
0xClandestine committed Feb 6, 2025
1 parent 68989a3 commit 292d340
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 196 deletions.
4 changes: 1 addition & 3 deletions src/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ contract BLSApkRegistry is BLSApkRegistryStorage {
quorumApkUpdatesLength == 0
|| blockNumber < apkHistory[quorumNumber][0].updateBlockNumber
) {
revert(
"BLSApkRegistry.getApkIndicesAtBlockNumber: blockNumber is before the first update"
);
revert BlockNumberBeforeFirstUpdate();
}

// Loop backward through apkHistory until we find an entry that preceeds `blockNumber`
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IBLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface IBLSApkRegistryErrors {
error BlockNumberTooRecent();
/// @notice Thrown when blocknumber and index provided is not the latest apk update.
error BlockNumberNotLatest();
/// @notice Thrown when the block number is before the first update.
error BlockNumberBeforeFirstUpdate();
}

interface IBLSApkRegistryTypes {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/BLSApkRegistryUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -927,4 +927,33 @@ contract BLSApkRegistryUnitTests_quorumApkUpdates is BLSApkRegistryUnitTests {
assertEq(quorumApk.Y, 0, "quorum apk not set to zero");
}
}

/**
* @dev test that attempting to get APK indices for a block number before the first update reverts
*/
function testFuzz_quorumApkUpdates_BlockNumberBeforeFirstUpdate(
uint32 blockNumber,
uint8 quorumNumber
) external {
// Initialize quorum if not already initialized
if (!initializedQuorums[quorumNumber]) {
_initializeFuzzedQuorum(quorumNumber);
}

bytes memory quorumNumbers = new bytes(1);
quorumNumbers[0] = bytes1(quorumNumber);

// Register an operator to create first update
address operator = _selectNewOperator();
_registerDefaultBLSPubkey(operator);
_registerOperator(operator, quorumNumbers);
uint32 firstUpdateBlock = uint32(block.number);

// Ensure blockNumber is before first update
cheats.assume(blockNumber < firstUpdateBlock);

// Expect revert when querying block before first update
cheats.expectRevert(IBLSApkRegistryErrors.BlockNumberBeforeFirstUpdate.selector);
blsApkRegistry.getApkIndicesAtBlockNumber(quorumNumbers, blockNumber);
}
}
Loading

0 comments on commit 292d340

Please sign in to comment.