Skip to content

Commit

Permalink
add testcase for lifetime is zero (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Jul 3, 2024
1 parent 048dfa1 commit 1e176b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contracts/pool/BundleService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ contract BundleService is
revert ErrorBundleServiceBundleNotOpen(bundleNftId, bundleState, bundleInfo.expiredAt);
}

if (lifetimeExtension.eqz()) {
revert ErrorBundleServiceExtensionLifetimeIsZero();
}

bundleInfo.expiredAt = bundleInfo.expiredAt.addSeconds(lifetimeExtension);
instance.getInstanceStore().updateBundle(bundleNftId, bundleInfo, KEEP_STATE());

Expand Down
3 changes: 2 additions & 1 deletion contracts/pool/IBundleService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ interface IBundleService is IService {

error ErrorBundleServicePolicyNotCloseable(NftId policyNftId);

// error ErrorBundleServiceBundleNotActive(NftId distributorNftId);
error ErrorBundleServiceFeesWithdrawAmountExceedsLimit(Amount amount, Amount limit);
error ErrorBundleServiceFeesWithdrawAmountIsZero();
error ErrorBundleServiceWalletAllowanceTooSmall(address wallet, address tokenHandler, uint256 allowance, uint256 amount);

error ErrorBundleServiceUnstakeAmountExceedsLimit(Amount amount, Amount limit);

error ErrorBundleServiceExtensionLifetimeIsZero();

event LogBundleServiceFeesWithdrawn(NftId bundleNftId, address recipient, address tokenAddress, Amount amount);
event LogBundleServiceBundleExtended(NftId bundleNftId, Seconds lifetimeExtension, Timestamp extendedExpiredAt);

Expand Down
26 changes: 25 additions & 1 deletion test/TestBundle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ contract TestBundle is GifTest {
pool.extend(bundleNftId, lifetime);
}

/// @dev test extension of an expired bundle
/// @dev test extension of a closed bundle
function test_Bundle_extend_bundleClosed() public {
// GIVEN
_prepareProduct(false);
Expand Down Expand Up @@ -532,6 +532,30 @@ contract TestBundle is GifTest {
pool.extend(bundleNftId, lifetime);
}

/// @dev test extension with lifetime is zero
function test_Bundle_extend_lifetimeIsZero() public {
// GIVEN
_prepareProduct(false);

IComponents.ComponentInfo memory poolComponentInfo = instanceReader.getComponentInfo(poolNftId);

vm.startPrank(investor);
token.approve(address(pool.getTokenHandler()), 1000);

Seconds lifetime = SecondsLib.toSeconds(0);
bundleNftId = pool.createBundle(
FeeLib.zero(),
1000,
lifetime,
""
);
// THEN - expect a revert
vm.expectRevert(abi.encodeWithSelector(IBundleService.ErrorBundleServiceExtensionLifetimeIsZero.selector));

// WHEN - bundle is extended
pool.extend(bundleNftId, lifetime);
}

function _fundInvestor(uint256 amount) internal {
vm.startPrank(registryOwner);
token.transfer(investor, amount);
Expand Down

0 comments on commit 1e176b6

Please sign in to comment.