From aa7e514465d44328ce85e05b68c1656a76c3ff9a Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Sat, 11 Nov 2023 16:24:45 -0500 Subject: [PATCH] add unit tests --- src/PoolManager.sol | 6 ++- test/PoolManager.t.sol | 43 +++++++++++++++++++ .../MigratedLiquidityPool.sol | 3 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/PoolManager.sol b/src/PoolManager.sol index 80bb5cdf..8d87ff23 100644 --- a/src/PoolManager.sol +++ b/src/PoolManager.sol @@ -430,8 +430,12 @@ contract PoolManager is Auth { return liquidityPool; } - function updateLiquidityPool(uint64 poolId, bytes16 trancheId, address currency, address liquidityPool) public auth { + function updateLiquidityPool(uint64 poolId, bytes16 trancheId, address currency, address liquidityPool) + public + auth + { require(pools[poolId].createdAt != 0, "PoolManager/pool-does-not-exist"); + require(isAllowedAsInvestmentCurrency(poolId, currency), "PoolManager/currency-not-supported"); Tranche storage tranche = pools[poolId].tranches[trancheId]; require(tranche.token != address(0), "PoolManager/tranche-does-not-exist"); tranche.liquidityPools[currency] = liquidityPool; diff --git a/test/PoolManager.t.sol b/test/PoolManager.t.sol index 96bde22d..f1ad5605 100644 --- a/test/PoolManager.t.sol +++ b/test/PoolManager.t.sol @@ -862,6 +862,49 @@ contract PoolManagerTest is TestSetup { vm.expectRevert(bytes("PoolManager/tranche-does-not-exist")); centrifugeChain.updateTrancheTokenPrice(poolId, trancheId, currencyId, price, uint64(block.timestamp)); } + + function testUpdateLiquidityPool() public { + address lPool_ = deploySimplePool(); + LiquidityPool lPool = LiquidityPool(lPool_); + address newLiquidityPool = makeAddr("newLiquidityPool"); + poolManager.updateLiquidityPool(lPool.poolId(), lPool.trancheId(), address(erc20), newLiquidityPool); + assertEq(poolManager.getLiquidityPool(lPool.poolId(), lPool.trancheId(), address(erc20)), newLiquidityPool); + } + + function testUpdateLiquidityPoolFailsForNonExistentPool() public { + address lPool_ = deploySimplePool(); + LiquidityPool lPool = LiquidityPool(lPool_); + address newLiquidityPool = makeAddr("newLiquidityPool"); + uint64 poolId = lPool.poolId(); + bytes16 trancheId = lPool.trancheId(); + address currency = lPool.asset(); + vm.expectRevert(bytes("PoolManager/pool-does-not-exist")); + poolManager.updateLiquidityPool(poolId+1, trancheId, currency, address(newLiquidityPool)); + } + + function testUpdateLiquidityPoolFailsForNonExistentTranche() public { + address lPool_ = deploySimplePool(); + LiquidityPool lPool = LiquidityPool(lPool_); + address newLiquidityPool = makeAddr("newLiquidityPool"); + uint64 poolId = lPool.poolId(); + bytes16 trancheId = lPool.trancheId(); + address currency = lPool.asset(); + vm.expectRevert(bytes("PoolManager/tranche-does-not-exist")); + poolManager.updateLiquidityPool(poolId, bytes16(0), currency, address(newLiquidityPool)); + } + + function testUpdateLiquidityPoolFailsForNonExistentCurrency() public { + address lPool_ = deploySimplePool(); + LiquidityPool lPool = LiquidityPool(lPool_); + address newLiquidityPool = makeAddr("newLiquidityPool"); + uint64 poolId = lPool.poolId(); + bytes16 trancheId = lPool.trancheId(); + address currency = lPool.asset(); + vm.expectRevert(bytes("PoolManager/currency-not-supported")); + poolManager.updateLiquidityPool(poolId, trancheId, makeAddr("wrong currency"), address(newLiquidityPool)); + } + + // helpers function hasDuplicates(bytes16[4] calldata array) internal pure returns (bool) { uint256 length = array.length; diff --git a/test/migrations/migrationContracts/MigratedLiquidityPool.sol b/test/migrations/migrationContracts/MigratedLiquidityPool.sol index bf3b8646..40019a70 100644 --- a/test/migrations/migrationContracts/MigratedLiquidityPool.sol +++ b/test/migrations/migrationContracts/MigratedLiquidityPool.sol @@ -11,6 +11,5 @@ contract MigratedLiquidityPool is LiquidityPool { address share_, address escrow_, address investmentManager_ - ) LiquidityPool(poolId_, trancheId_, asset_, share_, escrow_, investmentManager_) { - } + ) LiquidityPool(poolId_, trancheId_, asset_, share_, escrow_, investmentManager_) {} }