Skip to content

Commit

Permalink
Fix command-line tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barak manos committed May 29, 2024
1 parent 1650eeb commit 032eea6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 88 deletions.
43 changes: 13 additions & 30 deletions fastlane_bot/tests/test_048_RespectFlashloanTokensClickParam.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# ------------------------------------------------------------



"""
This module contains the tests which ensure that the flashloan tokens click parameters are respected.
This module contains the tests the `multi_pairwise_all` arb-mode with the `flashloan_tokens` parameter.
"""
from fastlane_bot import Bot
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, CarbonV1, BancorV3
import subprocess, os, sys
import pytest
import subprocess, os
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(Bot))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV2))
Expand All @@ -28,8 +26,6 @@
require("3.0", __VERSION__)




def find_main_py():
# Start at the directory of the current script
cwd = os.path.abspath(os.path.join(os.getcwd()))
Expand All @@ -50,37 +46,24 @@ def find_main_py():
cwd = new_cwd


def run_command(arb_mode):
# ------------------------------------------------------------
# Test 048
# File test_048_RespectFlashloanTokensClickParam.py
# Segment Test flashloan_tokens is Respected
# ------------------------------------------------------------
def test_test_multi_pairwise_all_with_flashloan_tokens():
# ------------------------------------------------------------

# Find the correct path to main.py
main_script_path = find_main_py()
print(f"Found main.py in {main_script_path}")
main_script_path = os.path.normpath(main_script_path + "/main.py")

# Run the command
cmd = [
"python",
main_script_path,
f"--arb_mode={arb_mode}",
find_main_py() + "/main.py",
f"--arb_mode=multi_pairwise_all",
"--default_min_profit_gas_token=0.001",
"--limit_bancor3_flashloan_tokens=False",
"--use_cached_events=False",
"--timeout=1",
"--loglevel=DEBUG",
"--timeout=120",
"--flashloan_tokens='0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C,0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xAa6E8127831c9DE45ae56bB1b0d4D4Da6e5665BD'",
"--blockchain=ethereum"
]

result = subprocess.run(cmd, text=True, capture_output=True, check=True)
print(result.stderr)


# ------------------------------------------------------------
# Test 048
# File test_048_RespectFlashloanTokensClickParam.py
# Segment Test flashloan_tokens is Respected
# ------------------------------------------------------------
def test_test_flashloan_tokens_is_respected():
# ------------------------------------------------------------

run_command("multi_pairwise_all")
assert result.returncode == 0
43 changes: 12 additions & 31 deletions fastlane_bot/tests/test_903_FlashloanTokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# ------------------------------------------------------------



"""
This module contains the tests which ensure the the flashloan_tokens parameter is respected when using the b3_two_hop and bancor_v3 arb modes.
This module contains the tests the `b3_two_hop` arb-mode with the `flashloan_tokens` parameter.
"""
from fastlane_bot import Bot
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, CarbonV1, BancorV3
import subprocess, os, sys
import pytest
import subprocess, os
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CPC))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(Bot))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV2))
Expand All @@ -28,15 +26,10 @@
require("3.0", __VERSION__)




def find_main_py():
# Start at the directory of the current script
cwd = os.path.abspath(os.path.join(os.getcwd()))

with open("log.txt", "w") as f:
f.write(f"Searching for main.py in {cwd}")

print(f"Searching for main.py in {cwd}")
while True:
# Check if main.py exists in the current directory
Expand All @@ -53,18 +46,18 @@ def find_main_py():
cwd = new_cwd


def run_command(mode):
# ------------------------------------------------------------
# Test 903
# File test_903_FlashloanTokens.py
# Segment Test b3_two_hop with flashloan tokens
# ------------------------------------------------------------
def test_test_b3_two_hop_with_flashloan_tokens():
# ------------------------------------------------------------

# Find the correct path to main.py
main_script_path = find_main_py()
print(f"Found main.py in {main_script_path}")
main_script_path = main_script_path + "/main.py"

# Run the command
cmd = [
"python",
main_script_path,
f"--arb_mode={mode}",
find_main_py() + "/main.py",
f"--arb_mode=b3_two_hop",
"--default_min_profit_gas_token=60",
"--limit_bancor3_flashloan_tokens=True",
"--alchemy_max_block_fetch=5",
Expand All @@ -74,16 +67,4 @@ def run_command(mode):
]

result = subprocess.run(cmd, text=True, capture_output=True, check=True)
print(result.stderr)


# ------------------------------------------------------------
# Test 903
# File test_903_FlashloanTokens.py
# Segment Test Flashloan Tokens b3_two_hop
# ------------------------------------------------------------
def test_test_flashloan_tokens_b3_two_hop():
# ------------------------------------------------------------

# + is_executing=true
run_command("b3_two_hop")
assert result.returncode == 0
38 changes: 11 additions & 27 deletions fastlane_bot/tests/test_906_TargetTokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# ------------------------------------------------------------



"""
This module contains the tests which ensure the target_tokens parameter is respected.
This module contains the tests the `b3_two_hop` arb-mode with the `target_tokens` parameter.
"""
from fastlane_bot import Bot, ConfigNetwork
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
Expand All @@ -31,9 +30,6 @@ def find_main_py():
# Start at the directory of the current script
cwd = os.path.abspath(os.path.join(os.getcwd()))

with open("log.txt", "w") as f:
f.write(f"Searching for main.py in {cwd}")

print(f"Searching for main.py in {cwd}")
while True:
# Check if main.py exists in the current directory
Expand All @@ -50,19 +46,18 @@ def find_main_py():
cwd = new_cwd


def run_command(mode):
# ------------------------------------------------------------
# Test 906
# File test_906_TargetTokens.py
# Segment Test b3_two_hop with target tokens
# ------------------------------------------------------------
def test_test_b3_two_hop_with_target_tokens():
# ------------------------------------------------------------

# Find the correct path to main.py
main_script_path = find_main_py()
print(f"Found main.py in {main_script_path}")
main_script_path = main_script_path + "/main.py"

# Run the command
cmd = [
"python",
main_script_path,
f"--arb_mode={mode}",
# "--use_cached_events=True",
find_main_py() + "/main.py",
f"--arb_mode=b3_two_hop",
"--alchemy_max_block_fetch=5",
"--logging_path=fastlane_bot/data/",
"--timeout=120",
Expand All @@ -71,15 +66,4 @@ def run_command(mode):
]

result = subprocess.run(cmd, text=True, capture_output=True, check=True)
print(result.stderr)


# ------------------------------------------------------------
# Test 906
# File test_906_TargetTokens.py
# Segment Test Flashloan Tokens b3_two_hop
# ------------------------------------------------------------
def test_test_flashloan_tokens_b3_two_hop():
# ------------------------------------------------------------

run_command("b3_two_hop")
assert result.returncode == 0

0 comments on commit 032eea6

Please sign in to comment.