Merge pull request #93 from propeller-heads/ah/test-multiple-amounts

feat(testing): Test multiple amounts.
This commit is contained in:
Alan Höng
2024-10-23 13:11:32 +01:00
committed by GitHub
2 changed files with 34 additions and 29 deletions

View File

@@ -74,9 +74,12 @@ interface ISwapAdapter is ISwapAdapterTypes {
/// @param poolId The ID of the trading pool.
/// @param sellToken The token being sold.
/// @param buyToken The token being bought.
/// @return limits An array of size two indicating the limit amount for the sell
/// token (maximum the pool is willing to buy in sell token) as well as the limit
/// amount of the buy token (maximum the pool is willing to sell in buy token).
/// @return limits An array of size two indicating the limit amount for the
/// sell
/// token (maximum the pool is willing to buy in sell token) as well as
/// the limit
/// amount of the buy token (maximum the pool is willing to sell in buy
/// token).
function getLimits(bytes32 poolId, address sellToken, address buyToken)
external
returns (uint256[] memory limits);

View File

@@ -148,7 +148,8 @@ class TestRunner:
comp_id = expected_component.id.lower()
if comp_id not in components_by_id:
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(
@@ -265,32 +266,33 @@ class TestRunner:
if not pool_state.balances:
raise ValueError(f"Missing balances for pool {pool_id}")
for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2):
# Try to sell 0.1% of the protocol balance
sell_amount = Decimal("0.001") * pool_state.balances[sell_token.address]
try:
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),
for prctg in ["0.001", "0.01", "0.1"]:
# Try to sell 0.1% of the protocol balance
sell_amount = Decimal(prctg) * pool_state.balances[sell_token.address]
try:
amount_out, gas_used, _ = pool_state.get_amount_out(
sell_token, sell_amount, buy_token
)
)
continue
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} 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
@staticmethod