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:
3
protocol-testing/Cargo.lock
generated
3
protocol-testing/Cargo.lock
generated
@@ -7823,7 +7823,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tycho-simulation"
|
name = "tycho-simulation"
|
||||||
version = "0.155.2"
|
version = "0.156.0"
|
||||||
|
source = "git+https://github.com/propeller-heads/tycho-simulation.git?tag=0.156.0#1983a787440e8ae757626d808a6e619baffc52f2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy",
|
"alloy",
|
||||||
"async-stream",
|
"async-stream",
|
||||||
|
|||||||
@@ -69,13 +69,17 @@ impl RPCProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
pub async fn get_block_header(&self, block_number: u64) -> miette::Result<Block> {
|
||||||
// async fn get_block_header(&self, _block_number: u64) {
|
let provider = ProviderBuilder::new().connect_http(self.url.clone());
|
||||||
// let provider = ProviderBuilder::new().on_http(self.url);
|
let block_id: BlockId = BlockId::from(block_number);
|
||||||
// let block_id: BlockId = BlockId::from(block_number);
|
|
||||||
//
|
provider
|
||||||
// let block = provider.get_block(block_id)
|
.get_block(block_id)
|
||||||
// }
|
.await
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("Failed to fetch block header")
|
||||||
|
.and_then(|block_opt| block_opt.ok_or_else(|| miette::miette!("Block not found")))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -122,4 +126,23 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(balance, U256::from(717250938432_u64));
|
assert_eq!(balance, U256::from(717250938432_u64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_block_header_test() {
|
||||||
|
let eth_rpc_url = env::var("RPC_URL").expect("Missing RPC_URL in environment");
|
||||||
|
|
||||||
|
let rpc_provider = RPCProvider::new(eth_rpc_url);
|
||||||
|
let block_number = 21998530;
|
||||||
|
|
||||||
|
let block_header = rpc_provider
|
||||||
|
.get_block_header(block_number)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Verify that we got a block with the correct number
|
||||||
|
assert_eq!(block_number, block_header.header.number);
|
||||||
|
|
||||||
|
// Verify that the timestamp is non-zero
|
||||||
|
assert!(block_header.header.timestamp > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,22 +336,53 @@ fn validate_state(
|
|||||||
decoder_context,
|
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
|
// Mock a stream message, with only a Snapshot and no deltas
|
||||||
let mut states: HashMap<String, ComponentWithState> = HashMap::new();
|
let mut states: HashMap<String, ComponentWithState> = HashMap::new();
|
||||||
for (id, component) in components_by_id {
|
for (id, component) in &components_by_id {
|
||||||
let component_id = &id.clone();
|
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
|
let state = protocol_states_by_id
|
||||||
.get(component_id)
|
.get(component_id)
|
||||||
.wrap_err("Failed to get state for component")?
|
.wrap_err("Failed to get state for component"
|
||||||
|
)?
|
||||||
.clone();
|
.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);
|
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
|
let vm_storage: HashMap<Bytes, ResponseAccount> = vm_storages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| (x.address.clone(), x))
|
.map(|x| (x.address.clone(), x))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let snapshot = Snapshot { states, vm_storage };
|
let snapshot = Snapshot { states, vm_storage };
|
||||||
|
|
||||||
let bytes = [0u8; 32];
|
let bytes = [0u8; 32];
|
||||||
@@ -414,6 +445,8 @@ fn validate_state(
|
|||||||
// We then retrieve the amount out for 0.1%, 1% and 10%.
|
// We then retrieve the amount out for 0.1%, 1% and 10%.
|
||||||
let percentages = [0.001, 0.01, 0.1];
|
let percentages = [0.001, 0.01, 0.1];
|
||||||
// Get limits for this token pair
|
// 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
|
let (max_input, max_output) = state
|
||||||
.get_limits(tokens[0].address.clone(), tokens[1].address.clone())
|
.get_limits(tokens[0].address.clone(), tokens[1].address.clone())
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
|
|||||||
Reference in New Issue
Block a user