Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AStox committed Nov 11, 2023
1 parent 05f5cf6 commit aa7e514
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 43 additions & 0 deletions test/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions test/migrations/migrationContracts/MigratedLiquidityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {}
}

0 comments on commit aa7e514

Please sign in to comment.