From da55923cd3df0603734bb98549460312151ee186 Mon Sep 17 00:00:00 2001 From: barak manos <> Date: Thu, 6 Jun 2024 18:50:39 +0300 Subject: [PATCH] Fix tests --- .../tests/test_042_TestBancorV3ModeTwoHop.py | 14 +++++++------- .../tests/test_043_TestEmptyCarbonOrders.py | 8 ++++---- fastlane_bot/tests/test_050_TestBancorV2.py | 12 ++++++------ .../test_060_TestRoutehandlerCarbonPrecision.py | 12 ++---------- fastlane_bot/tests/test_061_TestWETHConversion.py | 12 ++++++------ 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/fastlane_bot/tests/test_042_TestBancorV3ModeTwoHop.py b/fastlane_bot/tests/test_042_TestBancorV3ModeTwoHop.py index 3ff1fcdc0..38c5bdc59 100644 --- a/fastlane_bot/tests/test_042_TestBancorV3ModeTwoHop.py +++ b/fastlane_bot/tests/test_042_TestBancorV3ModeTwoHop.py @@ -162,19 +162,19 @@ def test_test_trade_merge(): # Convert the trade instructions ordered_trade_instructions_objects = bot._convert_trade_instructions(ordered_scaled_dcts) tx_route_handler = TxRouteHandler(trade_instructions=ordered_trade_instructions_objects) - agg_trade_instructions = ( + trade_instructions = ( tx_route_handler.aggregate_carbon_trades(ordered_trade_instructions_objects) if any(trade.is_carbon for trade in ordered_trade_instructions_objects) else ordered_trade_instructions_objects ) # Calculate the trade instructions - calculated_trade_instructions = tx_route_handler.calculate_trade_outputs(agg_trade_instructions) - assert len(calculated_trade_instructions) == 3 + tx_route_handler.calculate_trade_outputs(trade_instructions) + assert len(trade_instructions) == 3 # Aggregate multiple Bancor V3 trades into a single trade - calculated_trade_instructions = tx_route_handler.aggregate_bancor_v3_trades(calculated_trade_instructions) - assert len(calculated_trade_instructions) == 2 - assert calculated_trade_instructions[0].tknin != "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C" - assert calculated_trade_instructions[0].tknout != "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C" + tx_route_handler.aggregate_bancor_v3_trades(trade_instructions) + assert len(trade_instructions) == 2 + assert trade_instructions[0].tknin != "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C" + assert trade_instructions[0].tknout != "0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C" # ------------------------------------------------------------ diff --git a/fastlane_bot/tests/test_043_TestEmptyCarbonOrders.py b/fastlane_bot/tests/test_043_TestEmptyCarbonOrders.py index c5d281b5b..27f7247dd 100644 --- a/fastlane_bot/tests/test_043_TestEmptyCarbonOrders.py +++ b/fastlane_bot/tests/test_043_TestEmptyCarbonOrders.py @@ -201,22 +201,22 @@ def test_test_empty_carbon_orders_removed(): ordered_trade_instructions_objects = bot._convert_trade_instructions(ordered_scaled_dcts, ) # print(f"ordered_trade_instructions_objects: {ordered_trade_instructions_objects}") tx_route_handler = TxRouteHandler(trade_instructions=ordered_trade_instructions_objects) - agg_trade_instructions = ( + trade_instructions = ( tx_route_handler.aggregate_carbon_trades(ordered_trade_instructions_objects) if any(trade.is_carbon for trade in ordered_trade_instructions_objects) else ordered_trade_instructions_objects ) # Calculate the trade instructions - calculated_trade_instructions = tx_route_handler.calculate_trade_outputs(agg_trade_instructions) + tx_route_handler.calculate_trade_outputs(trade_instructions) - encoded_trade_instructions = tx_route_handler.custom_data_encoder(calculated_trade_instructions) + tx_route_handler.custom_data_encoder(trade_instructions) deadline = bot._get_deadline(1) # Get the route struct route_struct = [ asdict(rs) - for rs in tx_route_handler.get_route_structs(encoded_trade_instructions, deadline) + for rs in tx_route_handler.get_route_structs(trade_instructions, deadline) ] for route in route_struct: if route["platformId"] == 6: diff --git a/fastlane_bot/tests/test_050_TestBancorV2.py b/fastlane_bot/tests/test_050_TestBancorV2.py index c3a846bf8..77ace902b 100644 --- a/fastlane_bot/tests/test_050_TestBancorV2.py +++ b/fastlane_bot/tests/test_050_TestBancorV2.py @@ -201,30 +201,30 @@ def test_test_expected_output_bancorv2(): tx_route_handler = TxRouteHandler(trade_instructions=ordered_trade_instructions_objects) # Aggregate the carbon trades - agg_trade_instructions = ( + trade_instructions = ( tx_route_handler.aggregate_carbon_trades(ordered_trade_instructions_objects) if any(trade.is_carbon for trade in ordered_trade_instructions_objects) else ordered_trade_instructions_objects ) # Calculate the trade instructions - calculated_trade_instructions = tx_route_handler.calculate_trade_outputs(agg_trade_instructions) + tx_route_handler.calculate_trade_outputs(trade_instructions) # Aggregate multiple Bancor V3 trades into a single trade - calculated_trade_instructions = tx_route_handler.aggregate_bancor_v3_trades(calculated_trade_instructions) + tx_route_handler.aggregate_bancor_v3_trades(trade_instructions) # Get the flashloan token - fl_token = calculated_trade_instructions[0].tknin_address + fl_token = trade_instructions[0].tknin_address # If the flashloan token is WETH, then use ETH if fl_token == C.network.WETH_ADDRESS: fl_token = C.network.ETH_ADDRESS # Get the flashloan amount and token address - flashloan_amount = int(calculated_trade_instructions[0].amtin_wei) + flashloan_amount = int(trade_instructions[0].amtin_wei) # Encode the trade instructions - encoded_trade_instructions = tx_route_handler.custom_data_encoder(calculated_trade_instructions) + encoded_trade_instructions = tx_route_handler.custom_data_encoder(trade_instructions) # Get the deadline deadline = bot._get_deadline(1) diff --git a/fastlane_bot/tests/test_060_TestRoutehandlerCarbonPrecision.py b/fastlane_bot/tests/test_060_TestRoutehandlerCarbonPrecision.py index c03470c9d..c80f24d9a 100644 --- a/fastlane_bot/tests/test_060_TestRoutehandlerCarbonPrecision.py +++ b/fastlane_bot/tests/test_060_TestRoutehandlerCarbonPrecision.py @@ -174,11 +174,6 @@ def calculate_trade_outputs(tx_route_handler: TxRouteHandler, trade_instructions ---------- trade_instructions: List[Dict[str, Any]] The trade instructions. - - Returns - ------- - List[Dict[str, Any]] - The trade outputs. """ next_amount_in = trade_instructions[0].amtin @@ -329,9 +324,6 @@ def calculate_trade_outputs(tx_route_handler: TxRouteHandler, trade_instructions next_amount_in = amount_out - return trade_instructions - - arb_finder = bot.get_arb_finder("multi_pairwise_all", flashloan_tokens=flashloan_tokens, CCm=CCm) for arb_opp in arb_finder.find_arb_opps(): @@ -351,11 +343,11 @@ def calculate_trade_outputs(tx_route_handler: TxRouteHandler, trade_instructions tx_route_handler = TxRouteHandler(trade_instructions=ordered_trade_instructions_objects) # Aggregate the carbon trades - agg_trade_instructions = ( + trade_instructions = ( tx_route_handler.aggregate_carbon_trades(ordered_trade_instructions_objects) if any(trade.is_carbon for trade in ordered_trade_instructions_objects) else ordered_trade_instructions_objects ) # Calculate the trade instructions - calculate_trade_outputs(tx_route_handler=tx_route_handler,trade_instructions=agg_trade_instructions) + calculate_trade_outputs(tx_route_handler, trade_instructions) diff --git a/fastlane_bot/tests/test_061_TestWETHConversion.py b/fastlane_bot/tests/test_061_TestWETHConversion.py index 083a6e12e..58214597f 100644 --- a/fastlane_bot/tests/test_061_TestWETHConversion.py +++ b/fastlane_bot/tests/test_061_TestWETHConversion.py @@ -194,20 +194,20 @@ def test_wrap_unwrap_original(): tx_route_handler = TxRouteHandler(trade_instructions=ordered_trade_instructions_objects) # Aggregate the carbon trades - agg_trade_instructions = ( + trade_instructions = ( tx_route_handler.aggregate_carbon_trades(ordered_trade_instructions_objects) if any(trade.is_carbon for trade in ordered_trade_instructions_objects) else ordered_trade_instructions_objects ) # Calculate the trade instructions - calculated_trade_instructions = tx_route_handler.calculate_trade_outputs(trade_instructions=agg_trade_instructions) + tx_route_handler.calculate_trade_outputs(trade_instructions) # Aggregate multiple Bancor V3 trades into a single trade - calculated_trade_instructions = tx_route_handler.aggregate_bancor_v3_trades(calculated_trade_instructions) - flashloan_struct = tx_route_handler.generate_flashloan_struct(trade_instructions_objects=calculated_trade_instructions) + tx_route_handler.aggregate_bancor_v3_trades(trade_instructions) + flashloan_struct = tx_route_handler.generate_flashloan_struct(trade_instructions) - split_trades = split_carbon_trades(cfg, calculated_trade_instructions) + split_trades = split_carbon_trades(cfg, trade_instructions) # Encode the trade instructions encoded_trade_instructions = tx_route_handler.custom_data_encoder( @@ -226,7 +226,7 @@ def test_wrap_unwrap_original(): ] # Check if the result is None - wrap_route_struct = add_wrap_or_unwrap_trades_to_route(cfg, flashloan_struct, route_struct, calculated_trade_instructions) + wrap_route_struct = add_wrap_or_unwrap_trades_to_route(cfg, flashloan_struct, route_struct, trade_instructions) assert flashloan_struct[0]["sourceTokens"][0] == wrap_route_struct[0]["sourceToken"] assert flashloan_struct[0]["sourceTokens"][0] == wrap_route_struct[-1]["targetToken"]