Skip to content

Commit

Permalink
fix: ignore thawing tokens on provision token check (TRST-L13)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Dec 3, 2024
1 parent 0c0d090 commit def8026
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,16 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa

/**
* @notice Checks if the provision tokens of a service provider are within the valid range.
* Note that thawing tokens are not considered in this check.
* @param _provision The provision to check.
*/
function _checkProvisionTokens(IHorizonStaking.Provision memory _provision) internal view virtual {
_checkValueInRange(_provision.tokens, minimumProvisionTokens, maximumProvisionTokens, "tokens");
_checkValueInRange(
_provision.tokens - _provision.tokensThawing,
minimumProvisionTokens,
maximumProvisionTokens,
"tokens"
);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions packages/horizon/test/data-service/DataService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ contract DataServiceTest is HorizonStakingSharedTest {
assertEq(max, dataServiceOverride.PROVISION_TOKENS_MAX());
}

function test_ProvisionTokens_WhenCheckingAValidProvision_WithThawing(uint256 tokens, uint256 tokensThaw) external useIndexer {
dataService.setProvisionTokensRange(dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
tokens = bound(tokens, dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
tokensThaw = bound(tokensThaw, tokens - dataService.PROVISION_TOKENS_MIN() + 1, tokens);

_createProvision(users.indexer, address(dataService), tokens, 0, 0);
staking.thaw(users.indexer, address(dataService), tokensThaw);
vm.expectRevert(
abi.encodeWithSelector(
ProvisionManager.ProvisionManagerInvalidValue.selector,
"tokens",
tokens - tokensThaw,
dataService.PROVISION_TOKENS_MIN(),
dataService.PROVISION_TOKENS_MAX()
)
);
dataService.checkProvisionTokens(users.indexer);
}

function test_ProvisionTokens_WhenCheckingAValidProvision(uint256 tokens) external useIndexer {
dataService.setProvisionTokensRange(dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
tokens = bound(tokens, dataService.PROVISION_TOKENS_MIN(), dataService.PROVISION_TOKENS_MAX());
Expand Down

0 comments on commit def8026

Please sign in to comment.