fix: Skip simulation if skip_simulation = True
This is why we weren't getting BAL510 for `test_erc4626_linear_pool_creation` in python - simulation was being skipped, though not skipped in the rust porting. The simulation is skipped here since no liquidity has been added in more than 100k blocks.
This commit is contained in:
@@ -336,22 +336,53 @@ fn validate_state(
|
||||
decoder_context,
|
||||
);
|
||||
|
||||
// Filter out components that have skip_simulation = true (match Python behavior)
|
||||
let simulation_component_ids: std::collections::HashSet<String> = expected_components
|
||||
.iter()
|
||||
.filter(|c| !c.skip_simulation)
|
||||
.map(|c| c.base.id.clone())
|
||||
.collect();
|
||||
|
||||
info!("Components to simulate: {}", simulation_component_ids.len());
|
||||
for id in &simulation_component_ids {
|
||||
info!(" Simulating component: {}", id);
|
||||
}
|
||||
|
||||
if simulation_component_ids.is_empty() {
|
||||
info!("No components to simulate, skipping simulation validation");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Mock a stream message, with only a Snapshot and no deltas
|
||||
let mut states: HashMap<String, ComponentWithState> = HashMap::new();
|
||||
for (id, component) in components_by_id {
|
||||
let component_id = &id.clone();
|
||||
for (id, component) in &components_by_id {
|
||||
let component_id = id;
|
||||
|
||||
// Only include components that should be simulated
|
||||
if !simulation_component_ids.contains(component_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let state = protocol_states_by_id
|
||||
.get(component_id)
|
||||
.wrap_err("Failed to get state for component")?
|
||||
.wrap_err("Failed to get state for component"
|
||||
)?
|
||||
.clone();
|
||||
let component_with_state =
|
||||
ComponentWithState { state, component, component_tvl: None, entrypoints: vec![] }; // TODO
|
||||
|
||||
let component_with_state = ComponentWithState {
|
||||
state,
|
||||
component: component.clone(),
|
||||
component_tvl: None,
|
||||
entrypoints: vec![],
|
||||
}; // TODO
|
||||
states.insert(component_id.clone(), component_with_state);
|
||||
}
|
||||
// Convert vm_storages to a HashMap - match Python behavior exactly
|
||||
let vm_storage: HashMap<Bytes, ResponseAccount> = vm_storages
|
||||
.into_iter()
|
||||
.map(|x| (x.address.clone(), x))
|
||||
.collect();
|
||||
|
||||
let snapshot = Snapshot { states, vm_storage };
|
||||
|
||||
let bytes = [0u8; 32];
|
||||
@@ -414,6 +445,8 @@ fn validate_state(
|
||||
// We then retrieve the amount out for 0.1%, 1% and 10%.
|
||||
let percentages = [0.001, 0.01, 0.1];
|
||||
// Get limits for this token pair
|
||||
// TODO do this again, but reverse the order of the tokens to get the opposite swap
|
||||
// direction
|
||||
let (max_input, max_output) = state
|
||||
.get_limits(tokens[0].address.clone(), tokens[1].address.clone())
|
||||
.into_diagnostic()
|
||||
|
||||
Reference in New Issue
Block a user