diff --git a/test/unit/goodDollar/BancorExchangeProvider.t.sol b/test/unit/goodDollar/BancorExchangeProvider.t.sol index 48ddf25c..b5f410c7 100644 --- a/test/unit/goodDollar/BancorExchangeProvider.t.sol +++ b/test/unit/goodDollar/BancorExchangeProvider.t.sol @@ -452,6 +452,29 @@ contract BancorExchangeProviderTest_getAmountIn is BancorExchangeProviderTest { }); } + function test_getAmountIn_whenTokenInIsTokenAndReserveBalanceIsZero_shouldRevert() public { + IBancorExchangeProvider.PoolExchange memory poolExchangeTemp = IBancorExchangeProvider.PoolExchange({ + reserveAsset: address(reserveToken), + tokenAddress: address(token), + tokenSupply: 300_000 * 1e18, + reserveBalance: 60_000 * 1e18, + reserveRatio: 1e8 * 0.2, + exitContribution: 0 + }); + bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchangeTemp); + + vm.prank(brokerAddress); + bancorExchangeProvider.swapOut(exchangeId, address(token), address(reserveToken), 60_000 * 1e18); + + vm.expectRevert("ERR_INVALID_SUPPLY"); + bancorExchangeProvider.getAmountIn({ + exchangeId: exchangeId, + tokenIn: address(token), + tokenOut: address(reserveToken), + amountOut: 1e18 + }); + } + function test_getAmountIn_whenTokenInIsTokenAndAmountOutLargerThanReserveBalance_shouldRevert() public { bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1); vm.expectRevert("ERR_INVALID_AMOUNT"); @@ -520,6 +543,29 @@ contract BancorExchangeProviderTest_getAmountIn is BancorExchangeProviderTest { }); } + function test_getAmountIn_whenTokenInIsReserveAssetAndReserveBalanceIsZero_shouldRevert() public { + IBancorExchangeProvider.PoolExchange memory poolExchangeTemp = IBancorExchangeProvider.PoolExchange({ + reserveAsset: address(reserveToken), + tokenAddress: address(token), + tokenSupply: 300_000 * 1e18, + reserveBalance: 60_000 * 1e18, + reserveRatio: 1e8 * 0.2, + exitContribution: 0 + }); + bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchangeTemp); + + vm.prank(brokerAddress); + bancorExchangeProvider.swapOut(exchangeId, address(token), address(reserveToken), 60_000 * 1e18); + + vm.expectRevert("ERR_INVALID_SUPPLY"); + bancorExchangeProvider.getAmountIn({ + exchangeId: exchangeId, + tokenIn: address(reserveToken), + tokenOut: address(token), + amountOut: 1e18 + }); + } + function test_getAmountIn_whenTokenInIsReserveAssetAndAmountOutIsZero_shouldReturnZero() public { bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1); uint256 amountIn = bancorExchangeProvider.getAmountIn({ @@ -972,6 +1018,29 @@ contract BancorExchangeProviderTest_getAmountOut is BancorExchangeProviderTest { }); } + function test_getAmountOut_whenTokenInIsReserveAssetAndReserveBalanceIsZero_shouldRevert() public { + IBancorExchangeProvider.PoolExchange memory poolExchangeTemp = IBancorExchangeProvider.PoolExchange({ + reserveAsset: address(reserveToken), + tokenAddress: address(token), + tokenSupply: 300_000 * 1e18, + reserveBalance: 60_000 * 1e18, + reserveRatio: 1e8 * 0.2, + exitContribution: 0 + }); + bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchangeTemp); + + vm.prank(brokerAddress); + bancorExchangeProvider.swapOut(exchangeId, address(token), address(reserveToken), 60_000 * 1e18); + + vm.expectRevert("ERR_INVALID_SUPPLY"); + bancorExchangeProvider.getAmountOut({ + exchangeId: exchangeId, + tokenIn: address(reserveToken), + tokenOut: address(token), + amountIn: 1e18 + }); + } + function test_getAmountOut_whenTokenInIsReserveAssetAndAmountInIsZero_shouldReturnZero() public { bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1); uint256 amountOut = bancorExchangeProvider.getAmountOut({ @@ -1011,6 +1080,29 @@ contract BancorExchangeProviderTest_getAmountOut is BancorExchangeProviderTest { }); } + function test_getAmountOut_whenTokenInIsTokenAndReserveBalanceIsZero_shouldRevert() public { + IBancorExchangeProvider.PoolExchange memory poolExchangeTemp = IBancorExchangeProvider.PoolExchange({ + reserveAsset: address(reserveToken), + tokenAddress: address(token), + tokenSupply: 300_000 * 1e18, + reserveBalance: 60_000 * 1e18, + reserveRatio: 1e8 * 0.2, + exitContribution: 0 + }); + bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchangeTemp); + + vm.prank(brokerAddress); + bancorExchangeProvider.swapOut(exchangeId, address(token), address(reserveToken), 60_000 * 1e18); + + vm.expectRevert("ERR_INVALID_SUPPLY"); + bancorExchangeProvider.getAmountOut({ + exchangeId: exchangeId, + tokenIn: address(token), + tokenOut: address(reserveToken), + amountIn: 1e18 + }); + } + function test_getAmountOut_whenTokenInIsTokenAndAmountLargerSupply_shouldRevert() public { bytes32 exchangeId = bancorExchangeProvider.createExchange(poolExchange1); vm.expectRevert("ERR_INVALID_AMOUNT");