From e51a7e47aece3b9df82f74881fe253d4293e1ca0 Mon Sep 17 00:00:00 2001 From: Ian Lucas Date: Thu, 17 Oct 2024 03:19:32 -0400 Subject: [PATCH] Refactor MTVTests to improve multiple deposit testing --- .../token/ERC1155/MultiTokenVaultTest.t.sol | 38 +++---- .../token/ERC1155/RedeemOptimizerTest.t.sol | 32 +++--- .../LiquidContinuousMultiTokenVaultTest.t.sol | 22 ++-- ...tParamArray.t.sol => IMTVTestParams.t.sol} | 4 +- .../ERC1155/IMultiTokenVaultTestBase.t.sol | 103 +++++++++--------- ...uidContinuousMultiTokenVaultTestBase.t.sol | 6 +- 6 files changed, 102 insertions(+), 103 deletions(-) rename packages/contracts/test/test/token/ERC1155/{IMTVTestParamArray.t.sol => IMTVTestParams.t.sol} (96%) diff --git a/packages/contracts/test/src/token/ERC1155/MultiTokenVaultTest.t.sol b/packages/contracts/test/src/token/ERC1155/MultiTokenVaultTest.t.sol index b9369c89a..d67775c46 100644 --- a/packages/contracts/test/src/token/ERC1155/MultiTokenVaultTest.t.sol +++ b/packages/contracts/test/src/token/ERC1155/MultiTokenVaultTest.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.20; import { IMultiTokenVault } from "@credbull/token/ERC1155/IMultiTokenVault.sol"; import { MultiTokenVault } from "@credbull/token/ERC1155/MultiTokenVault.sol"; import { IMultiTokenVaultTestBase } from "@test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol"; -import { IMTVTestParamArray } from "@test/test/token/ERC1155/IMTVTestParamArray.t.sol"; +import { IMTVTestParams } from "@test/test/token/ERC1155/IMTVTestParams.t.sol"; import { MultiTokenVaultDailyPeriods } from "@test/test/token/ERC1155/MultiTokenVaultDailyPeriods.t.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; @@ -70,7 +70,7 @@ contract MultiTokenVaultTest is IMultiTokenVaultTestBase { MultiTokenVault vault = _createMultiTokenVault(_asset, assetToSharesRatio, 10); - testVaultAtPeriod(_charlie, vault, _testParams1); + testVaultAtOffsets(_charlie, vault, _testParams1); } function test__MultiTokenVaulTest__RedeemBeforeDepositPeriodReverts() public { @@ -188,21 +188,15 @@ contract MultiTokenVaultTest is IMultiTokenVaultTestBase { uint256 assetToSharesRatio = 2; uint256 redeemPeriod = 2001; - IMTVTestParamArray testParamsArray = new IMTVTestParamArray(); - testParamsArray.addTestParam( - TestParam({ principal: 1001 * _scale, depositPeriod: 1, redeemPeriod: redeemPeriod }) - ); - testParamsArray.addTestParam( - TestParam({ principal: 2002 * _scale, depositPeriod: 202, redeemPeriod: redeemPeriod }) - ); - testParamsArray.addTestParam( - TestParam({ principal: 3003 * _scale, depositPeriod: 303, redeemPeriod: redeemPeriod }) - ); + IMTVTestParams testParamss = new IMTVTestParams(); + testParamss.add(TestParam({ principal: 1001 * _scale, depositPeriod: 1, redeemPeriod: redeemPeriod })); + testParamss.add(TestParam({ principal: 2002 * _scale, depositPeriod: 202, redeemPeriod: redeemPeriod })); + testParamss.add(TestParam({ principal: 3003 * _scale, depositPeriod: 303, redeemPeriod: redeemPeriod })); IMultiTokenVault vault = _createMultiTokenVault(_asset, assetToSharesRatio, 10); - uint256[] memory shares = _testDepositOnly(_alice, vault, testParamsArray.all()); - uint256[] memory depositPeriods = testParamsArray.depositPeriods(); + uint256[] memory shares = _testDepositOnly(_alice, vault, testParamss); + uint256[] memory depositPeriods = testParamss.depositPeriods(); // ------------------------ batch convert to assets ------------------------ uint256[] memory assets = vault.convertToAssetsForDepositPeriodBatch(shares, depositPeriods, redeemPeriod); @@ -225,7 +219,7 @@ contract MultiTokenVaultTest is IMultiTokenVaultTestBase { ); // ------------------------ batch approvalForAll safeBatchTransferFrom balance ------------------------ - uint256[] memory aliceBalances = _testBalanceOfBatch(_alice, vault, testParamsArray, assetToSharesRatio); + uint256[] memory aliceBalances = _testBalanceOfBatch(_alice, vault, testParamss, assetToSharesRatio); // have alice approve bob for all vm.prank(_alice); @@ -235,22 +229,22 @@ contract MultiTokenVaultTest is IMultiTokenVaultTestBase { vm.prank(_bob); vault.safeBatchTransferFrom(_alice, _charlie, depositPeriods, aliceBalances, ""); - _testBalanceOfBatch(_charlie, vault, testParamsArray, assetToSharesRatio); // verify bob + _testBalanceOfBatch(_charlie, vault, testParamss, assetToSharesRatio); // verify bob } function _testBalanceOfBatch( address account, IMultiTokenVault vault, - IMTVTestParamArray testParamsArray, + IMTVTestParams testParams, uint256 assetToSharesRatio ) internal view returns (uint256[] memory balances_) { - address[] memory accounts = testParamsArray.accountArray(account); - uint256[] memory balances = vault.balanceOfBatch(accounts, testParamsArray.depositPeriods()); + address[] memory accounts = testParams.accountArray(account); + uint256[] memory balances = vault.balanceOfBatch(accounts, testParams.depositPeriods()); assertEq(3, balances.length, "balances size incorrect"); - assertEq(testParamsArray.get(0).principal / assetToSharesRatio, balances[0], "balance mismatch period 0"); - assertEq(testParamsArray.get(1).principal / assetToSharesRatio, balances[1], "balance mismatch period 1"); - assertEq(testParamsArray.get(2).principal / assetToSharesRatio, balances[2], "balance mismatch period 2"); + assertEq(testParams.get(0).principal / assetToSharesRatio, balances[0], "balance mismatch period 0"); + assertEq(testParams.get(1).principal / assetToSharesRatio, balances[1], "balance mismatch period 1"); + assertEq(testParams.get(2).principal / assetToSharesRatio, balances[2], "balance mismatch period 2"); return balances; } diff --git a/packages/contracts/test/src/token/ERC1155/RedeemOptimizerTest.t.sol b/packages/contracts/test/src/token/ERC1155/RedeemOptimizerTest.t.sol index 3c18e8eb3..f8a08f84d 100644 --- a/packages/contracts/test/src/token/ERC1155/RedeemOptimizerTest.t.sol +++ b/packages/contracts/test/src/token/ERC1155/RedeemOptimizerTest.t.sol @@ -6,21 +6,21 @@ import { RedeemOptimizerFIFO } from "@credbull/token/ERC1155/RedeemOptimizerFIFO import { IMultiTokenVault } from "@credbull/token/ERC1155/IMultiTokenVault.sol"; import { MultiTokenVaultTest } from "@test/src/token/ERC1155/MultiTokenVaultTest.t.sol"; -import { IMTVTestParamArray } from "@test/test/token/ERC1155/IMTVTestParamArray.t.sol"; +import { IMTVTestParams } from "@test/test/token/ERC1155/IMTVTestParams.t.sol"; contract RedeemOptimizerTest is MultiTokenVaultTest { address private _owner = makeAddr("owner"); address private _alice = makeAddr("alice"); - IMTVTestParamArray private testParamsArr; + IMTVTestParams private testParams; function setUp() public override { super.setUp(); - testParamsArr = new IMTVTestParamArray(); - testParamsArr.addTestParam(_testParams1); - testParamsArr.addTestParam(_testParams2); - testParamsArr.addTestParam(_testParams3); + testParams = new IMTVTestParams(); + testParams.add(_testParams1); + testParams.add(_testParams2); + testParams.add(_testParams3); } function test__RedeemOptimizerTest__RedeemAllShares() public { @@ -31,7 +31,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { IRedeemOptimizer redeemOptimizer = new RedeemOptimizerFIFO(IRedeemOptimizer.OptimizerBasis.Shares, multiTokenVault.currentPeriodsElapsed()); - uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParamsArr.all()); + uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParams); uint256 totalDepositShares = depositShares[0] + depositShares[1] + depositShares[2]; // warp vault ahead to redeemPeriod @@ -42,7 +42,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { (uint256[] memory redeemDepositPeriods, uint256[] memory sharesAtPeriods) = redeemOptimizer.optimize(multiTokenVault, _alice, totalDepositShares, 0, redeemPeriod); // optimize using share basis. assets not used - assertEq(testParamsArr.depositPeriods(), redeemDepositPeriods, "optimizeRedeem - depositPeriods not correct"); + assertEq(testParams.depositPeriods(), redeemDepositPeriods, "optimizeRedeem - depositPeriods not correct"); assertEq(depositShares, sharesAtPeriods, "optimizeRedeem - shares not correct"); } @@ -56,9 +56,9 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { IRedeemOptimizer.OptimizerBasis.AssetsWithReturns, multiTokenVault.currentPeriodsElapsed() ); - uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParamsArr.all()); + uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParams); uint256[] memory depositAssets = multiTokenVault.convertToAssetsForDepositPeriodBatch( - depositShares, testParamsArr.depositPeriods(), redeemPeriod + depositShares, testParams.depositPeriods(), redeemPeriod ); assertEq(depositShares.length, depositAssets.length, "mismatch in convertToAssets"); uint256 totalAssets = depositAssets[0] + depositAssets[1] + depositAssets[2]; @@ -70,7 +70,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { (uint256[] memory withdrawDepositPeriods, uint256[] memory sharesAtPeriods) = redeemOptimizer.optimize(multiTokenVault, _alice, 0, totalAssets, redeemPeriod); // optimize using asset basis. shares not used - assertEq(testParamsArr.depositPeriods(), withdrawDepositPeriods, "optimizeRedeem - depositPeriods not correct"); + assertEq(testParams.depositPeriods(), withdrawDepositPeriods, "optimizeRedeem - depositPeriods not correct"); assertEq(depositShares, sharesAtPeriods, "optimizeRedeem - shares not correct"); } @@ -83,7 +83,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { IRedeemOptimizer redeemOptimizer = new RedeemOptimizerFIFO( IRedeemOptimizer.OptimizerBasis.AssetsWithReturns, multiTokenVault.currentPeriodsElapsed() ); - uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParamsArr.all()); + uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParams); uint256 sharesToWithdraw = depositShares[0] + depositShares[1] + depositShares[2] - residualShareAmount; @@ -101,7 +101,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { "optimizeRedeem partial - wrong shares period 2" ); // reduced by 1 share - assertEq(testParamsArr.depositPeriods(), redeemDepositPeriods, "optimizeRedeem - depositPeriods not correct"); + assertEq(testParams.depositPeriods(), redeemDepositPeriods, "optimizeRedeem - depositPeriods not correct"); } function test__RedeemOptimizerTest__PartialWithdraw() public { @@ -114,9 +114,9 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { IRedeemOptimizer.OptimizerBasis.AssetsWithReturns, multiTokenVault.currentPeriodsElapsed() ); - uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParamsArr.all()); + uint256[] memory depositShares = _testDepositOnly(_alice, multiTokenVault, testParams); uint256[] memory depositAssets = multiTokenVault.convertToAssetsForDepositPeriodBatch( - depositShares, testParamsArr.depositPeriods(), redeemPeriod + depositShares, testParams.depositPeriods(), redeemPeriod ); uint256 residualAssetAmount = multiTokenVault.convertToAssetsForDepositPeriod( @@ -145,7 +145,7 @@ contract RedeemOptimizerTest is MultiTokenVaultTest { ); assertEq( - testParamsArr.depositPeriods().length, + testParams.depositPeriods().length, actualAssetsAtPeriods.length, "convertToAssetsForDepositPeriods partial - length incorrect" ); diff --git a/packages/contracts/test/src/yield/LiquidContinuousMultiTokenVaultTest.t.sol b/packages/contracts/test/src/yield/LiquidContinuousMultiTokenVaultTest.t.sol index 5d465d04c..d5a8b6a3d 100644 --- a/packages/contracts/test/src/yield/LiquidContinuousMultiTokenVaultTest.t.sol +++ b/packages/contracts/test/src/yield/LiquidContinuousMultiTokenVaultTest.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.20; import { LiquidContinuousMultiTokenVault } from "@credbull/yield/LiquidContinuousMultiTokenVault.sol"; import { LiquidContinuousMultiTokenVaultTestBase } from "@test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol"; import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol"; -import { IMTVTestParamArray } from "@test/test/token/ERC1155/IMTVTestParamArray.t.sol"; +import { IMTVTestParams } from "@test/test/token/ERC1155/IMTVTestParams.t.sol"; contract LiquidContinuousMultiTokenVaultTest is LiquidContinuousMultiTokenVaultTestBase { function test__RequestRedeemTest__RedeemAtTenor() public { @@ -115,26 +115,26 @@ contract LiquidContinuousMultiTokenVaultTest is LiquidContinuousMultiTokenVaultT } function test__LiquidContinuousVaultTest__RedeemMultiPeriodsAllShares() public { - IMTVTestParamArray depositTestParams = new IMTVTestParamArray(); + IMTVTestParams depositTestParams = new IMTVTestParams(); // run in some deposits uint256 baseDepositAmount = 100 * _scale; for (uint256 i = 0; i <= 10; ++i) { - depositTestParams.addTestParam( + depositTestParams.add( TestParam({ principal: (baseDepositAmount * i) + 1 * _scale, depositPeriod: i, redeemPeriod: 1000 }) ); } - _testDepositOnly(alice, _liquidVault, depositTestParams.all()); + _testDepositOnly(alice, _liquidVault, depositTestParams); // ------------ requestRedeem #1 ----------- uint256 redeemPeriod1 = 31; - IMTVTestParamArray redeemParams1 = _split(depositTestParams, 0, 2); + IMTVTestParams redeemParams1 = _split(depositTestParams, 0, 2); _testRequestRedeemMultiDeposit(alice, _liquidVault, redeemParams1, 31); // ------------ requestRedeem #2 ------------ uint256 redeemPeriod2 = 41; - IMTVTestParamArray redeemParams2 = _split(depositTestParams, 3, 4); + IMTVTestParams redeemParams2 = _split(depositTestParams, 3, 4); _testRequestRedeemMultiDeposit(alice, _liquidVault, redeemParams2, 41); // ------------ redeems ------------ @@ -146,24 +146,24 @@ contract LiquidContinuousMultiTokenVaultTest is LiquidContinuousMultiTokenVaultT } function test__LiquidContinuousVaultTest__RedeemMultiPeriodsPartialShares() public { - IMTVTestParamArray depositTestParams = new IMTVTestParamArray(); + IMTVTestParams depositTestParams = new IMTVTestParams(); // run in some deposits uint256 baseDepositAmount = 100 * _scale; for (uint256 i = 0; i <= 10; ++i) { - depositTestParams.addTestParam( + depositTestParams.add( TestParam({ principal: (baseDepositAmount * i) + 1 * _scale, depositPeriod: i, redeemPeriod: 1000 }) ); } - _testDepositOnly(alice, _liquidVault, depositTestParams.all()); + _testDepositOnly(alice, _liquidVault, depositTestParams); uint256 partialShares = 1 * _scale; // ------------ requestRedeem #1 ------------ uint256 redeemPeriod1 = 30; - IMTVTestParamArray redeemParams1 = _split(depositTestParams, 0, 2); + IMTVTestParams redeemParams1 = _split(depositTestParams, 0, 2); redeemParams1.set(2, partialShares); _testRequestRedeemMultiDeposit(alice, _liquidVault, redeemParams1, redeemPeriod1); @@ -171,7 +171,7 @@ contract LiquidContinuousMultiTokenVaultTest is LiquidContinuousMultiTokenVaultT // ------------ requestRedeem #2 ------------ uint256 redeemPeriod2 = 50; - IMTVTestParamArray redeemParams2 = _split(depositTestParams, 2, 4); + IMTVTestParams redeemParams2 = _split(depositTestParams, 2, 4); redeemParams2.set(0, depositTestParams.get(2).principal - partialShares); redeemParams2.set(2, partialShares); diff --git a/packages/contracts/test/test/token/ERC1155/IMTVTestParamArray.t.sol b/packages/contracts/test/test/token/ERC1155/IMTVTestParams.t.sol similarity index 96% rename from packages/contracts/test/test/token/ERC1155/IMTVTestParamArray.t.sol rename to packages/contracts/test/test/token/ERC1155/IMTVTestParams.t.sol index 56b7607b6..2f407805c 100644 --- a/packages/contracts/test/test/token/ERC1155/IMTVTestParamArray.t.sol +++ b/packages/contracts/test/test/token/ERC1155/IMTVTestParams.t.sol @@ -3,11 +3,11 @@ pragma solidity ^0.8.20; import { IMultiTokenVaultTestBase } from "@test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol"; -contract IMTVTestParamArray { +contract IMTVTestParams { IMultiTokenVaultTestBase.TestParam[] private _all; // Function to add testParams to the array - function addTestParam(IMultiTokenVaultTestBase.TestParam memory testParam) public { + function add(IMultiTokenVaultTestBase.TestParam memory testParam) public { _all.push(testParam); } diff --git a/packages/contracts/test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol b/packages/contracts/test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol index 8550c1893..f4e70b50b 100644 --- a/packages/contracts/test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol +++ b/packages/contracts/test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol @@ -6,7 +6,7 @@ import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { Timer } from "@credbull/timelock/Timer.sol"; -import { IMTVTestParamArray } from "@test/test/token/ERC1155/IMTVTestParamArray.t.sol"; +import { IMTVTestParams } from "@test/test/token/ERC1155/IMTVTestParams.t.sol"; import { Test } from "forge-std/Test.sol"; @@ -19,29 +19,42 @@ abstract contract IMultiTokenVaultTestBase is Test { uint256 redeemPeriod; } - /// @dev test Vault at specified redeemPeriod and other "interesting" redeem periods - function testVaultAtOffsets(address account, IMultiTokenVault vault, TestParam memory testParam) internal { - IMTVTestParamArray testParamsArr = new IMTVTestParamArray(); - testParamsArr.initUsingOffsets(testParam); - testVaultAtAllPeriods(account, vault, testParamsArr.all()); - } - - /// @dev test Vault at specified redeemPeriod and other "interesting" redeem periods - function testVaultAtAllPeriods(address account, IMultiTokenVault vault, TestParam[] memory testParams) internal { - for (uint256 i = 0; i < testParams.length; i++) { - IMultiTokenVaultTestBase.TestParam memory testParam = testParams[i]; - testVaultAtPeriod(account, vault, testParam); // Test using the test params + /// @dev test the vault at the given test parameters + function testVault(address account, IMultiTokenVault vault, IMTVTestParams testParams) + internal + returns (uint256[] memory sharesAtPeriods_, uint256[] memory assetsAtPeriods_) + { + // previews okay to test individually. don't update vault state. + for (uint256 i = 0; i < testParams.length(); i++) { + TestParam memory testParam = testParams.get(i); + _testConvertToAssetAndSharesAtPeriod(vault, testParam); // previews only, account agnostic + _testPreviewDepositAndPreviewRedeem(vault, testParam); // previews only, account agnostic } + + // capture vault state before warping around + uint256 prevVaultPeriodsElapsed = vault.currentPeriodsElapsed(); + + // ------------------- deposits ------------------- + // NB - test all of the deposits BEFORE redeems. verifies no side-effects from deposits when redeeming. + uint256[] memory sharesAtPeriods = _testDepositOnly(account, vault, testParams); + + // ------------------- redeems ------------------- + // NB - test all of the redeems AFTER deposits. verifies no side-effects from deposits when redeeming. + uint256[] memory assetsAtPeriods = _testRedeemOnly(account, vault, testParams, sharesAtPeriods); + + _warpToPeriod(vault, prevVaultPeriodsElapsed); // restore previous period state + + return (sharesAtPeriods, assetsAtPeriods); } - /// @dev test the vault at the given test parameters - function testVaultAtPeriod(address account, IMultiTokenVault vault, TestParam memory testParam) + /// @dev test Vault at specified redeemPeriod and other "interesting" redeem periods + function testVaultAtOffsets(address account, IMultiTokenVault vault, TestParam memory testParam) internal - returns (uint256 sharesAtPeriod, uint256 assetsAtPeriod) + returns (uint256[] memory sharesAtPeriods_, uint256[] memory assetsAtPeriods_) { - _testConvertToAssetAndSharesAtPeriod(vault, testParam); // previews only, account agnostic - _testPreviewDepositAndPreviewRedeem(vault, testParam); // previews only, account agnostic - return _testDepositAndRedeemAtPeriod(account, vault, testParam); // actual deposits/redeems + IMTVTestParams testParams = new IMTVTestParams(); + testParams.initUsingOffsets(testParam); + return testVault(account, vault, testParams); } /// @dev verify convertToAssets and convertToShares. These are a "preview" and do NOT update vault assets or shares. @@ -115,38 +128,16 @@ abstract contract IMultiTokenVaultTestBase is Test { return (actualSharesAtPeriod, actualAssetsAtPeriod); } - /// @dev verify deposit and redeem. These update vault assets and shares. - function _testDepositAndRedeemAtPeriod(address account, IMultiTokenVault vault, TestParam memory testParam) - internal - virtual - returns (uint256 actualSharesAtPeriod_, uint256 actualAssetsAtPeriod_) - { - // capture state before for validations - uint256 prevVaultPeriodsElapsed = vault.currentPeriodsElapsed(); - - // ------------------- deposit ------------------- - uint256 actualSharesAtPeriod = _testDepositOnly(account, vault, testParam); - - // ------------------- redeem ------------------- - uint256 actualAssetsAtPeriod = _testRedeemOnly(account, vault, testParam, actualSharesAtPeriod); - - _warpToPeriod(vault, prevVaultPeriodsElapsed); // restore previous period state - - return (actualSharesAtPeriod, actualAssetsAtPeriod); - } - /// @dev verify deposit. updates vault assets and shares. - function _testDepositOnly(address account, IMultiTokenVault vault, TestParam[] memory testParams) + function _testDepositOnly(address account, IMultiTokenVault vault, IMTVTestParams testParams) internal virtual returns (uint256[] memory sharesAtPeriod_) { - uint256[] memory sharesAtPeriod = new uint256[](testParams.length); - - for (uint256 i = 0; i < testParams.length; i++) { - sharesAtPeriod[i] = _testDepositOnly(account, vault, testParams[i]); + uint256[] memory sharesAtPeriod = new uint256[](testParams.length()); + for (uint256 i = 0; i < testParams.length(); i++) { + sharesAtPeriod[i] = _testDepositOnly(account, vault, testParams.get(i)); } - return sharesAtPeriod; } @@ -192,6 +183,20 @@ abstract contract IMultiTokenVaultTestBase is Test { return actualSharesAtPeriod; } + /// @dev verify redeem. updates vault assets and shares. + function _testRedeemOnly( + address account, + IMultiTokenVault vault, + IMTVTestParams testParams, + uint256[] memory sharesAtPeriods + ) internal virtual returns (uint256[] memory assetsAtPeriods_) { + uint256[] memory assetsAtPeriods = new uint256[](testParams.length()); + for (uint256 i = 0; i < testParams.length(); i++) { + assetsAtPeriods[i] = _testRedeemOnly(account, vault, testParams.get(i), sharesAtPeriods[i]); + } + return assetsAtPeriods; + } + /// @dev verify redeem. updates vault assets and shares. function _testRedeemOnly( address account, @@ -295,13 +300,13 @@ abstract contract IMultiTokenVaultTestBase is Test { return TestParam({ principal: principal, depositPeriod: depositPeriod, redeemPeriod: redeemPeriod }); } - function _split(IMTVTestParamArray origTestParams, uint256 from, uint256 to) + function _split(IMTVTestParams origTestParams, uint256 from, uint256 to) public - returns (IMTVTestParamArray newTestParams_) + returns (IMTVTestParams newTestParams_) { - IMTVTestParamArray newTestParams = new IMTVTestParamArray(); + IMTVTestParams newTestParams = new IMTVTestParams(); for (uint256 i = from; i <= to; i++) { - newTestParams.addTestParam(origTestParams.get(i)); + newTestParams.add(origTestParams.get(i)); } return newTestParams; } diff --git a/packages/contracts/test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol b/packages/contracts/test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol index a677d6db1..2b80591a6 100644 --- a/packages/contracts/test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol +++ b/packages/contracts/test/test/yield/LiquidContinuousMultiTokenVaultTestBase.t.sol @@ -12,7 +12,7 @@ import { Timer } from "@credbull/timelock/Timer.sol"; import { DeployLiquidMultiTokenVault } from "@script/DeployLiquidMultiTokenVault.s.sol"; import { IMultiTokenVaultTestBase } from "@test/test/token/ERC1155/IMultiTokenVaultTestBase.t.sol"; import { SimpleUSDC } from "@test/test/token/SimpleUSDC.t.sol"; -import { IMTVTestParamArray } from "@test/test/token/ERC1155/IMTVTestParamArray.t.sol"; +import { IMTVTestParams } from "@test/test/token/ERC1155/IMTVTestParams.t.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -128,7 +128,7 @@ abstract contract LiquidContinuousMultiTokenVaultTestBase is IMultiTokenVaultTes function _testRequestRedeemMultiDeposit( address account, LiquidContinuousMultiTokenVault liquidVault, - IMTVTestParamArray depositTestParams, + IMTVTestParams depositTestParams, uint256 redeemPeriod // we are testing multiple deposits into one redeemPeriod ) internal virtual { _warpToPeriod(_liquidVault, redeemPeriod - liquidVault.noticePeriod()); @@ -150,7 +150,7 @@ abstract contract LiquidContinuousMultiTokenVaultTestBase is IMultiTokenVaultTes function _testRedeemMultiDeposit( address account, LiquidContinuousMultiTokenVault liquidVault, - IMTVTestParamArray depositTestParams, + IMTVTestParams depositTestParams, uint256 redeemPeriod // we are testing multiple deposits into one redeemPeriod ) internal virtual { _warpToPeriod(_liquidVault, redeemPeriod);