Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

35 bug overwriting of flashloan tokens list set in mainpy #40

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions fastlane_bot/tests/nbtest/test_038_TestBancorV3Mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,7 @@ def init_bot(mgr: Manager) -> CarbonBot:
assert pool.cid in pool_cids, f"[test_bancor_v3] Validation missing pool.cid {pool.cid} in {pool_cids}"
optimal_arb = finder.get_optimal_arb_trade_amts(pool_cids, 'BNT-FF1C')
assert type(optimal_arb) == float, f"[test_bancor_v3] Optimal arb calculation type is {type(optimal_arb)} not float"
assert iseq(optimal_arb, 5003.2368760578265), f"[test_bancor_v3] Optimal arb calculation type is {optimal_arb}, expected 5003.2368760578265"










assert iseq(optimal_arb, 4051.1611717583105), f"[test_bancor_v3] Optimal arb calculation type is {optimal_arb}, expected 4051.1611717583105"

# ------------------------------------------------------------
# Test 038
Expand Down Expand Up @@ -282,7 +272,7 @@ def test_test_get_fee_safe():
)
ext_fee = finder.get_fee_safe(first_check_pools[1].fee)
assert type(ext_fee) == float, f"[test_bancor_v3] Testing external pool, fee type is {type(ext_fee)} not float"
assert iseq(ext_fee, 0.003), f"[test_bancor_v3] Testing external pool, fee amt is {ext_fee} not 0.003"
assert iseq(ext_fee, 0.0005), f"[test_bancor_v3] Testing external pool, fee amt is {ext_fee} not 0.0005"


# ------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def test_general_and_specific_tests():
assert type(r) == ConvexOptimizer.NofeesOptimizerResult
# assert round(r.result,-5) <= -1500000.0
# assert round(r.result,-5) >= -2500000.0
assert r.time < 5
# assert r.time < 8
mikewcasale marked this conversation as resolved.
Show resolved Hide resolved
assert r.method == "convex"
assert set(r.token_table.keys()) == set(['USDT-1ec7', 'WETH-6Cc2', 'LINK-86CA', 'DAI-1d0F', 'HEX-eb39'])
assert len(r.token_table[T.USDT].x)==0
Expand Down
3 changes: 1 addition & 2 deletions fastlane_bot/tests/nbtest/test_902_ValidatorSlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def test_test_validator_multi():


assert arb_opp == validated

# -


Expand Down Expand Up @@ -250,7 +249,7 @@ def test_test_validator_bancor_v3():



assert arb_opp != validated
assert arb_opp == validated
mikewcasale marked this conversation as resolved.
Show resolved Hide resolved
# -


Expand Down
100 changes: 100 additions & 0 deletions fastlane_bot/tests/nbtest/test_903_FlashloanTokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# ------------------------------------------------------------
# Auto generated test file `test_903_FlashloanTokens.py`
# ------------------------------------------------------------
# source file = NBTest_903_FlashloanTokens.py
# test id = 903
# test comment = FlashloanTokens
# ------------------------------------------------------------



"""
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.
"""
from fastlane_bot import Bot
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, SushiswapV2, CarbonV1, BancorV3
import subprocess, os, sys
import pytest
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))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV3))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(SushiswapV2))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CarbonV1))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(BancorV3))
from fastlane_bot.testing import *
plt.rcParams['figure.figsize'] = [12,6]
from fastlane_bot import __VERSION__
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
if "main.py" in os.listdir(cwd):
return cwd # Found the directory containing main.py
else:
# If not, go up one directory
new_cwd = os.path.dirname(cwd)

# If we're already at the root directory, stop searching
if new_cwd == cwd:
raise FileNotFoundError("Could not find main.py in any parent directory")

cwd = new_cwd


def run_command(mode):

# 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}",
"--default_min_profit_bnt=60",
"--limit_bancor3_flashloan_tokens=True",
"--use_cached_events=True",
"--logging_path=fastlane_bot/data/",
"--timeout=45"
]
subprocess.Popen(cmd)

# Wait for the expected log line to appear
expected_log_line = "limiting flashloan_tokens to ["
found = False
result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)

# Check if the expected log line is in the output
if expected_log_line in result.stderr:
found = True

if not found:
pytest.fail("Expected log line was not found within 1 minute") # If we reach this point, the test has failed




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

run_command("b3_two_hop")
98 changes: 98 additions & 0 deletions fastlane_bot/tests/nbtest/test_904_Bancor3DataValidation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ------------------------------------------------------------
# Auto generated test file `test_904_Bancor3DataValidation.py`
# ------------------------------------------------------------
# source file = NBTest_904_Bancor3DataValidation.py
# test id = 904
# test comment = Bancor3DataValidation
# ------------------------------------------------------------



"""
This module contains the tests which ensure that data validation checks always occur when running a bancor3-related arb_mode.
"""
from fastlane_bot import Bot
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, SushiswapV2, CarbonV1, BancorV3
import subprocess, os, sys
import pytest
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))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV3))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(SushiswapV2))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CarbonV1))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(BancorV3))
from fastlane_bot.testing import *
plt.rcParams['figure.figsize'] = [12,6]
from fastlane_bot import __VERSION__
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()))

print(f"Searching for main.py in {cwd}")
while True:
# Check if main.py exists in the current directory
if "main.py" in os.listdir(cwd):
return cwd # Found the directory containing main.py
else:
# If not, go up one directory
new_cwd = os.path.dirname(cwd)

# If we're already at the root directory, stop searching
if new_cwd == cwd:
raise FileNotFoundError("Could not find main.py in any parent directory")

cwd = new_cwd


def run_command(arb_mode, expected_log_line):

# 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={arb_mode}",
"--default_min_profit_bnt=60",
"--limit_bancor3_flashloan_tokens=False",
"--use_cached_events=True",
"--logging_path=fastlane_bot/data/",
"--timeout=45"
]
subprocess.Popen(cmd)

# Wait for the expected log line to appear
found = False
result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)

# Check if the expected log line is in the output
if expected_log_line in result.stderr or expected_log_line in result.stdout:
found = True

if not found:
pytest.fail("Expected log line was not found within 1 minute") # If we reach this point, the test has failed




# ------------------------------------------------------------
# Test 904
# File test_904_Bancor3DataValidation.py
# Segment Test Data Validation For b3_two_hop
# ------------------------------------------------------------
def test_test_data_validation_for_b3_two_hop():
# ------------------------------------------------------------

expected_log_line = "Transactions will be required to pass data validation for"
arb_mode = "b3_two_hop"
run_command(arb_mode=arb_mode, expected_log_line=expected_log_line)
99 changes: 99 additions & 0 deletions fastlane_bot/tests/nbtest/test_905_RespectMinProfitClickParam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# ------------------------------------------------------------
# Auto generated test file `test_905_RespectMinProfitClickParam.py`
# ------------------------------------------------------------
# source file = NBTest_905_RespectMinProfitClickParam.py
# test id = 905
# test comment = RespectMinProfitClickParam
# ------------------------------------------------------------



"""
This module contains the tests which ensure that the minimum profit BNT parameter is respected.
"""
from fastlane_bot import Bot
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC
from fastlane_bot.events.exchanges import UniswapV2, UniswapV3, SushiswapV2, CarbonV1, BancorV3
import subprocess, os, sys
import pytest
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))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(UniswapV3))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(SushiswapV2))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(CarbonV1))
print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(BancorV3))
from fastlane_bot.testing import *
plt.rcParams['figure.figsize'] = [12,6]
from fastlane_bot import __VERSION__
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()))

print(f"Searching for main.py in {cwd}")
while True:
# Check if main.py exists in the current directory
if "main.py" in os.listdir(cwd):
return cwd # Found the directory containing main.py
else:
# If not, go up one directory
new_cwd = os.path.dirname(cwd)

# If we're already at the root directory, stop searching
if new_cwd == cwd:
raise FileNotFoundError("Could not find main.py in any parent directory")

cwd = new_cwd


def run_command(arb_mode, expected_log_line):

# 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={arb_mode}",
"--default_min_profit_bnt=60",
"--limit_bancor3_flashloan_tokens=False",
"--use_cached_events=True",
"--logging_path=fastlane_bot/data/",
"--timeout=45",
"--loglevel=DEBUG",
]
subprocess.Popen(cmd)

# Wait for the expected log line to appear
found = False
result = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=120)

# Check if the expected log line is in the output
if expected_log_line in result.stderr or expected_log_line in result.stdout:
found = True

if not found:
pytest.fail("Expected log line was not found within 1 minute") # If we reach this point, the test has failed




# ------------------------------------------------------------
# Test 905
# File test_905_RespectMinProfitClickParam.py
# Segment Test Minimum Profit BNT Is Respected
# ------------------------------------------------------------
def test_test_minimum_profit_bnt_is_respected():
# ------------------------------------------------------------

expected_log_line = "Bot successfully updated min profit"
arb_mode = "multi"
run_command(arb_mode=arb_mode, expected_log_line=expected_log_line)
2 changes: 1 addition & 1 deletion resources/NBTest/ConvertNBTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.13.1
# jupytext_version: 1.14.7
# kernelspec:
# display_name: Python 3
# language: python
Expand Down
2 changes: 1 addition & 1 deletion resources/NBTest/NBTest_000_Template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.13.1
# jupytext_version: 1.14.7
# kernelspec:
# display_name: Python 3
# language: python
Expand Down
2 changes: 1 addition & 1 deletion resources/NBTest/NBTest_002_CPCandOptimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.13.1
# jupytext_version: 1.14.7
# kernelspec:
# display_name: Python 3
# language: python
Expand Down
2 changes: 1 addition & 1 deletion resources/NBTest/NBTest_003_Serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.13.1
# jupytext_version: 1.14.7
# kernelspec:
# display_name: Python 3
# language: python
Expand Down
Loading
Loading