Skip to content

Commit

Permalink
test: Test view functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnfy-view committed Mar 22, 2024
1 parent 82ced89 commit b953871
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions test/unit/miscellaneousTests/miscellaneous.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import { UniversalHelper } from "../../utils/helpers/UniversalHelper.sol";

contract MiscellaneousTest is UniversalHelper {
function testGetPoolTokenAddresses() public view {
assertEq(address(thunderSwapPool.getPoolToken1()), address(tokenA));
assertEq(address(thunderSwapPool.getPoolToken2()), address(tokenB));
}

function testGetMinimumPoolToken1ToSupply() public view {
assertEq(thunderSwapPool.getMinimumPoolToken1ToSupply(), 1e9);
}

function testGetTotalLiquidityProviderTokenSupply()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
assertEq(thunderSwapPool.getTotalLiquidityProviderTokenSupply(), 1e18);
}

function testGetPoolToken1Reserves()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
assertEq(thunderSwapPool.getPoolToken1Reserves(), 1e18);
}

function testGetPoolToken2Reserves()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
assertEq(thunderSwapPool.getPoolToken2Reserves(), 2e18);
}

function testGetPoolToken2LiquidityToAddBasedOnPoolToken1Amount()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
uint256 poolToken1Amount = 1e18;
uint256 expectedPoolToken2AmountToDeposit = 2e18;

assertEq(
thunderSwapPool.getPoolToken2LiquidityToAddBasedOnPoolToken1Amount(poolToken1Amount),
expectedPoolToken2AmountToDeposit
);
}

function getPoolToken1LiquidityToAddBasedOnPoolToken2Amount()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
uint256 poolToken2Amount = 2e18;
uint256 expectedPoolToken1AmountToDeposit = 1e18;

assertEq(
thunderSwapPool.getPoolToken1LiquidityToAddBasedOnPoolToken2Amount(poolToken2Amount),
expectedPoolToken1AmountToDeposit
);
}

function testGetLiquidityProviderTokensToMint()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
uint256 poolToken1AmountToAddAsLiquidity = 1e18;
uint256 expectedLiquidityProviderTokensToMint = 1e18;

assertEq(
thunderSwapPool.getLiquidityProviderTokensToMint(poolToken1AmountToAddAsLiquidity),
expectedLiquidityProviderTokensToMint
);
}

function testGetInputBasedOnOuput() public view {
uint256 inputReserves = 1e18;
uint256 outputReserves = 2e18;

uint256 outputAmount = 1e18;
uint256 minimumInputAmount = 1e18;
uint256 inputAmountWithFees =
thunderSwapPool.getInputBasedOnOuput(outputAmount, inputReserves, outputReserves);
assert(inputAmountWithFees > minimumInputAmount);
}

function testGetOutputBasedOnInput() public view {
uint256 inputReserves = 1e18;
uint256 outputReserves = 2e18;

uint256 inputAmount = 1004e15;
uint256 minimumOutputAmount = 1e18;
uint256 outputAmount =
thunderSwapPool.getOutputBasedOnInput(inputAmount, inputReserves, outputReserves);
assert(outputAmount > minimumOutputAmount);
}
}

0 comments on commit b953871

Please sign in to comment.