Skip to content

Commit

Permalink
feat: updated tests to expect correct error
Browse files Browse the repository at this point in the history
  • Loading branch information
RyRy79261 committed Nov 26, 2024
1 parent ec3b97f commit e0895d7
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/unit/goodDollar/BancorExchangeProvider.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit e0895d7

Please sign in to comment.