Skip to content

Commit

Permalink
Required Proceeds fix + bash test runner (#167)
Browse files Browse the repository at this point in the history
* fix: requiredProceeds args

* bash script for test env vars

Co-authored-by: kaden <[email protected]>

---------

Co-authored-by: kaden <[email protected]>
  • Loading branch information
kinrezC and kadenzipfel authored Oct 24, 2024
1 parent 263873e commit 730ae06
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
106 changes: 106 additions & 0 deletions TestScenarios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

# Function to run tests with current environment configuration
run_test() {
echo "Running tests with configuration:"
echo "IS_TOKEN_0=${IS_TOKEN_0}"
echo "USING_ETH=${USING_ETH}"
echo "FEE=${FEE}"
echo "PROTOCOL_FEE=${PROTOCOL_FEE}"
echo "----------------------------------------"

# Export the variables
export IS_TOKEN_0
export USING_ETH
export FEE
export PROTOCOL_FEE

# Run forge test and capture exit code
forge test
local test_result=$?

echo "----------------------------------------"
if [ $test_result -eq 0 ]; then
echo "βœ… Tests passed"
else
echo "❌ Tests failed"
fi
echo "----------------------------------------"
echo ""

return $test_result
}

# Initialize with default values
IS_TOKEN_0="false"
USING_ETH="false"
FEE=0
PROTOCOL_FEE=0

# Array to track failed configurations
failed_configs=()

# Test Case 1: IS_TOKEN_0 = true
echo "πŸ” Test Case 1: IS_TOKEN_0 = true"
IS_TOKEN_0="true"
run_test || failed_configs+=("Case 1: IS_TOKEN_0=true")

# Test Case 2: IS_TOKEN_0 = false
echo "πŸ” Test Case 2: IS_TOKEN_0 = false"
IS_TOKEN_0="false"
run_test || failed_configs+=("Case 2: IS_TOKEN_0=false")

# Test Case 3: USING_ETH = true
echo "πŸ” Test Case 3: USING_ETH = true"
USING_ETH="true"
run_test || failed_configs+=("Case 3: USING_ETH=true")

# Test Case 4: IS_TOKEN_0=true and FEE=30
echo "πŸ” Test Case 4: IS_TOKEN_0=true and FEE=30"
IS_TOKEN_0="true"
USING_ETH="false"
FEE=30
run_test || failed_configs+=("Case 4: IS_TOKEN_0=true, FEE=30")

# Test Case 5: IS_TOKEN_0=false and FEE=30
echo "πŸ” Test Case 5: IS_TOKEN_0=false and FEE=30"
IS_TOKEN_0="false"
FEE=30
run_test || failed_configs+=("Case 5: IS_TOKEN_0=false, FEE=30")

# Test Case 6: USING_ETH=true, IS_TOKEN_0=false and FEE=30
echo "πŸ” Test Case 6: USING_ETH=true, IS_TOKEN_0=false and FEE=30"
USING_ETH="true"
IS_TOKEN_0="false"
FEE=30
run_test || failed_configs+=("Case 6: USING_ETH=true, IS_TOKEN_0=false and FEE=30")

# Test Case 7: IS_TOKEN_0=true, FEE=30, PROTOCOL_FEE=50
echo "πŸ” Test Case 7: IS_TOKEN_0=true, FEE=30, PROTOCOL_FEE=50"
USING_ETH="false"
IS_TOKEN_0="true"
FEE=30
PROTOCOL_FEE=50
run_test || failed_configs+=("Case 7: IS_TOKEN_0=true, FEE=30, PROTOCOL_FEE=50")

# Test Case 8: IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50
echo "πŸ” Test Case 8: IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50"
IS_TOKEN_0="false"
run_test || failed_configs+=("Case 8: IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50")

# Test Case 9: USING_ETH=true, IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50
echo "πŸ” Test Case 9: USING_ETH=true, IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50"
USING_ETH="true"
IS_TOKEN_0="false"
run_test || failed_configs+=("Case 9: USING_ETH=true, IS_TOKEN_0=false, FEE=30, PROTOCOL_FEE=50")

# Print summary
echo "================ Test Summary ================"
if [ ${#failed_configs[@]} -eq 0 ]; then
echo "βœ… All test configurations passed!"
else
echo "❌ The following configurations failed:"
for config in "${failed_configs[@]}"; do
echo " - $config"
done
fi
3 changes: 1 addition & 2 deletions src/Doppler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,9 @@ contract Doppler is BaseHook {

uint160 sqrtPriceNext = TickMath.getSqrtPriceAtTick(currentTick);
uint160 sqrtPriceLower = TickMath.getSqrtPriceAtTick(tickLower);
uint160 sqrtPriceUpper = TickMath.getSqrtPriceAtTick(tickUpper);

uint256 requiredProceeds =
totalTokensSold_ != 0 ? _computeRequiredProceeds(sqrtPriceLower, sqrtPriceUpper, totalTokensSold_) : 0;
totalTokensSold_ != 0 ? _computeRequiredProceeds(sqrtPriceLower, sqrtPriceNext, totalTokensSold_) : 0;

// Get existing positions
Position[] memory prevPositions = new Position[](2 + numPDSlugs);
Expand Down

0 comments on commit 730ae06

Please sign in to comment.