Skip to content

Commit

Permalink
add test for expired and closed bundle (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Jul 3, 2024
1 parent f87b2b7 commit 31e59c2
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/TestBundle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Amount, AmountLib} from "../contracts/type/Amount.sol";
import {BasicPoolAuthorization} from "../contracts/pool/BasicPoolAuthorization.sol";
import {Fee, FeeLib} from "../contracts/type/Fee.sol";
import {IBundle} from "../contracts/instance/module/IBundle.sol";
import {IBundleService} from "../contracts/pool/IBundleService.sol";
import {IComponents} from "../contracts/instance/module/IComponents.sol";
import {IKeyValueStore} from "../contracts/shared/IKeyValueStore.sol";
import {ILifecycle} from "../contracts/shared/ILifecycle.sol";
Expand Down Expand Up @@ -143,6 +144,77 @@ contract TestBundle is GifTest {
pool.stake(bundleNftId, stakeAmount);
}

/// @dev test staking of an existing bundle
function test_Bundle_stakeBundle_bundleExpired() public {
// GIVEN
initialStakingFee = FeeLib.percentageFee(4);
_prepareProduct(false);

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

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

Seconds lifetime = SecondsLib.toSeconds(604800);
bundleNftId = pool.createBundle(
FeeLib.zero(),
1000,
lifetime,
""
);
uint256 createdAt = vm.getBlockTimestamp();

Amount stakeAmount = AmountLib.toAmount(1000);

// fast forward time to after bundle expiration
skip(lifetime.toInt() + 1000);

// THEN - revert
vm.expectRevert(abi.encodeWithSelector(IBundleService.ErrorBundleServiceBundleNotOpen.selector,
bundleNftId,
ACTIVE(),
createdAt + lifetime.toInt()
));

// WHEN - bundle is expired
pool.stake(bundleNftId, stakeAmount);
}

/// @dev test staking of an existing bundle
function test_Bundle_stakeBundle_bundleClosed() public {
// GIVEN
initialStakingFee = FeeLib.percentageFee(4);
_prepareProduct(false);

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

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

Seconds lifetime = SecondsLib.toSeconds(604800);
bundleNftId = pool.createBundle(
FeeLib.zero(),
1000,
lifetime,
""
);
uint256 createdAt = vm.getBlockTimestamp();

Amount stakeAmount = AmountLib.toAmount(1000);

pool.close(bundleNftId);

// THEN - revert
vm.expectRevert(abi.encodeWithSelector(IBundleService.ErrorBundleServiceBundleNotOpen.selector,
bundleNftId,
CLOSED(),
createdAt + lifetime.toInt()
));

// WHEN - bundle is expired
pool.stake(bundleNftId, stakeAmount);
}

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

0 comments on commit 31e59c2

Please sign in to comment.