Skip to content

Commit aa7e514

Browse files
committed
add unit tests
1 parent 05f5cf6 commit aa7e514

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/PoolManager.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,12 @@ contract PoolManager is Auth {
430430
return liquidityPool;
431431
}
432432

433-
function updateLiquidityPool(uint64 poolId, bytes16 trancheId, address currency, address liquidityPool) public auth {
433+
function updateLiquidityPool(uint64 poolId, bytes16 trancheId, address currency, address liquidityPool)
434+
public
435+
auth
436+
{
434437
require(pools[poolId].createdAt != 0, "PoolManager/pool-does-not-exist");
438+
require(isAllowedAsInvestmentCurrency(poolId, currency), "PoolManager/currency-not-supported");
435439
Tranche storage tranche = pools[poolId].tranches[trancheId];
436440
require(tranche.token != address(0), "PoolManager/tranche-does-not-exist");
437441
tranche.liquidityPools[currency] = liquidityPool;

test/PoolManager.t.sol

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,49 @@ contract PoolManagerTest is TestSetup {
862862
vm.expectRevert(bytes("PoolManager/tranche-does-not-exist"));
863863
centrifugeChain.updateTrancheTokenPrice(poolId, trancheId, currencyId, price, uint64(block.timestamp));
864864
}
865+
866+
function testUpdateLiquidityPool() public {
867+
address lPool_ = deploySimplePool();
868+
LiquidityPool lPool = LiquidityPool(lPool_);
869+
address newLiquidityPool = makeAddr("newLiquidityPool");
870+
poolManager.updateLiquidityPool(lPool.poolId(), lPool.trancheId(), address(erc20), newLiquidityPool);
871+
assertEq(poolManager.getLiquidityPool(lPool.poolId(), lPool.trancheId(), address(erc20)), newLiquidityPool);
872+
}
873+
874+
function testUpdateLiquidityPoolFailsForNonExistentPool() public {
875+
address lPool_ = deploySimplePool();
876+
LiquidityPool lPool = LiquidityPool(lPool_);
877+
address newLiquidityPool = makeAddr("newLiquidityPool");
878+
uint64 poolId = lPool.poolId();
879+
bytes16 trancheId = lPool.trancheId();
880+
address currency = lPool.asset();
881+
vm.expectRevert(bytes("PoolManager/pool-does-not-exist"));
882+
poolManager.updateLiquidityPool(poolId+1, trancheId, currency, address(newLiquidityPool));
883+
}
884+
885+
function testUpdateLiquidityPoolFailsForNonExistentTranche() public {
886+
address lPool_ = deploySimplePool();
887+
LiquidityPool lPool = LiquidityPool(lPool_);
888+
address newLiquidityPool = makeAddr("newLiquidityPool");
889+
uint64 poolId = lPool.poolId();
890+
bytes16 trancheId = lPool.trancheId();
891+
address currency = lPool.asset();
892+
vm.expectRevert(bytes("PoolManager/tranche-does-not-exist"));
893+
poolManager.updateLiquidityPool(poolId, bytes16(0), currency, address(newLiquidityPool));
894+
}
895+
896+
function testUpdateLiquidityPoolFailsForNonExistentCurrency() public {
897+
address lPool_ = deploySimplePool();
898+
LiquidityPool lPool = LiquidityPool(lPool_);
899+
address newLiquidityPool = makeAddr("newLiquidityPool");
900+
uint64 poolId = lPool.poolId();
901+
bytes16 trancheId = lPool.trancheId();
902+
address currency = lPool.asset();
903+
vm.expectRevert(bytes("PoolManager/currency-not-supported"));
904+
poolManager.updateLiquidityPool(poolId, trancheId, makeAddr("wrong currency"), address(newLiquidityPool));
905+
}
906+
907+
865908
// helpers
866909
function hasDuplicates(bytes16[4] calldata array) internal pure returns (bool) {
867910
uint256 length = array.length;

test/migrations/migrationContracts/MigratedLiquidityPool.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ contract MigratedLiquidityPool is LiquidityPool {
1111
address share_,
1212
address escrow_,
1313
address investmentManager_
14-
) LiquidityPool(poolId_, trancheId_, asset_, share_, escrow_, investmentManager_) {
15-
}
14+
) LiquidityPool(poolId_, trancheId_, asset_, share_, escrow_, investmentManager_) {}
1615
}

0 commit comments

Comments
 (0)