Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barak manos committed Jun 6, 2024
1 parent 704deee commit da55923
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
14 changes: 7 additions & 7 deletions fastlane_bot/tests/test_042_TestBancorV3ModeTwoHop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


# ------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions fastlane_bot/tests/test_043_TestEmptyCarbonOrders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions fastlane_bot/tests/test_050_TestBancorV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 2 additions & 10 deletions fastlane_bot/tests/test_060_TestRoutehandlerCarbonPrecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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)
12 changes: 6 additions & 6 deletions fastlane_bot/tests/test_061_TestWETHConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"]
Expand Down

0 comments on commit da55923

Please sign in to comment.