feat(testing): Test multiple amounts.

This commit is contained in:
kayibal
2024-10-23 12:50:44 +01:00
parent 163296bceb
commit 378c1c2786

View File

@@ -148,7 +148,8 @@ class TestRunner:
comp_id = expected_component.id.lower() comp_id = expected_component.id.lower()
if comp_id not in components_by_id: if comp_id not in components_by_id:
return TestResult.Failed( return TestResult.Failed(
f"'{comp_id}' not found in protocol components." f"'{comp_id}' not found in protocol components. "
f"Available components: {set(components_by_id.keys())}"
) )
diff = ProtocolComponentExpectation( diff = ProtocolComponentExpectation(
@@ -265,32 +266,33 @@ class TestRunner:
if not pool_state.balances: if not pool_state.balances:
raise ValueError(f"Missing balances for pool {pool_id}") raise ValueError(f"Missing balances for pool {pool_id}")
for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2): for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2):
# Try to sell 0.1% of the protocol balance for prctg in ["0.001", "0.01", "0.1"]:
sell_amount = Decimal("0.001") * pool_state.balances[sell_token.address] # Try to sell 0.1% of the protocol balance
try: sell_amount = Decimal(prctg) * pool_state.balances[sell_token.address]
amount_out, gas_used, _ = pool_state.get_amount_out( try:
sell_token, sell_amount, buy_token amount_out, gas_used, _ = pool_state.get_amount_out(
) sell_token, sell_amount, buy_token
print(
f"Amount out for {pool_id}: {sell_amount} {sell_token} -> {amount_out} {buy_token} - "
f"Gas used: {gas_used}"
)
except Exception as e:
print(
f"Error simulating get_amount_out for {pool_id}: {sell_token} -> {buy_token}. "
f"Error: {e}"
)
if pool_id not in failed_simulations:
failed_simulations[pool_id] = []
failed_simulations[pool_id].append(
SimulationFailure(
pool_id=pool_id,
sell_token=str(sell_token),
buy_token=str(buy_token),
error=str(e),
) )
) print(
continue f"Amount out for {pool_id}: {sell_amount} {sell_token} -> {amount_out} {buy_token} - "
f"Gas used: {gas_used}"
)
except Exception as e:
print(
f"Error simulating get_amount_out for {pool_id}: {sell_token} -> {buy_token} at block {block_number}. "
f"Error: {e}"
)
if pool_id not in failed_simulations:
failed_simulations[pool_id] = []
failed_simulations[pool_id].append(
SimulationFailure(
pool_id=pool_id,
sell_token=str(sell_token),
buy_token=str(buy_token),
error=str(e),
)
)
continue
return failed_simulations return failed_simulations
@staticmethod @staticmethod