From 31e59c2ec42e1dce9f3653fdea3f547c4bcbb6f0 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Wed, 3 Jul 2024 13:52:58 +0000 Subject: [PATCH] add test for expired and closed bundle (#418) --- test/TestBundle.t.sol | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/TestBundle.t.sol b/test/TestBundle.t.sol index 7c2080bc0..66dfd30ef 100644 --- a/test/TestBundle.t.sol +++ b/test/TestBundle.t.sol @@ -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"; @@ -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);