MCPcopy Create free account
hub / github.com/cakevm/kabu / execute_test

Function execute_test

testing/backtest-runner/src/main.rs:213–803  ·  view source on GitHub ↗

Complete test execution - everything happens here for isolation

(test_path: PathBuf, args: &Commands)

Source from the content-addressed store, hash-verified

211
212// Complete test execution - everything happens here for isolation
213async fn execute_test(test_path: PathBuf, args: &Commands) -> Result<()> {
214 let test_config = TestConfig::from_file(test_path.to_string_lossy().to_string()).await?;
215
216 // Check if test is disabled
217 if test_config.settings.disabled {
218 println!("[{}] SKIPPED: Test disabled - {}", Local::now().format("%H:%M:%S.%3f"), test_path.display());
219 return Ok(());
220 }
221
222 println!("[{}] TEST STARTED: {}", Local::now().format("%H:%M:%S.%3f"), test_path.display());
223 println!("[{}] Block: {} | Timeout: {}s", Local::now().format("%H:%M:%S.%3f"), test_config.settings.block, args.timeout);
224
225 // Create a fresh Anvil instance for this test
226 let node_url = env::var("MAINNET_WS")?;
227 let client = AnvilDebugProviderFactory::from_node_on_block(node_url, test_config.settings.block).await?;
228 let priv_key = client.privkey()?.to_bytes().to_vec();
229
230 let mut mock_server: Option<MockServer> = None;
231 if test_config.modules.flashbots {
232 // Start flashbots mock server
233 mock_server = Some(MockServer::start().await);
234 mount_flashbots_mock(mock_server.as_ref().unwrap()).await;
235 }
236
237 let multicaller_address = MulticallerDeployer::new()
238 .set_code(client.clone(), address!("FCfCfcfC0AC30164AFdaB927F441F2401161F358"))
239 .await?
240 .address()
241 .ok_or_eyre("MULTICALLER_NOT_DEPLOYED")?;
242 info!("Multicaller deployed at {:?}", multicaller_address);
243
244 let multicaller_encoder = MulticallerSwapEncoder::default_with_address(multicaller_address);
245
246 let block_number = client.get_block_number().await?;
247 info!("Current block_number={}", block_number);
248
249 let block_response = client.get_block(block_number.into()).await?.unwrap();
250 let block = <BlockTy<EthPrimitives> as TryFromBlockResponse<Ethereum>>::from_block_response(block_response)?;
251 let block_header = block.header().clone();
252 info!("Current block_header={:?}", block_header);
253
254 let block_response = client.get_block(block_number.into()).await?.unwrap();
255
256 let block_header_with_txes = <BlockTy<EthPrimitives> as TryFromBlockResponse<Ethereum>>::from_block_response(block_response)?;
257
258 // Create AlloyDB connected to the forked Anvil instance
259 let alloy_db =
260 AlloyDB::new(client.clone(), BlockId::Number(BlockNumberOrTag::Number(block_number))).ok_or_eyre("Failed to create AlloyDB")?;
261 let state_db = KabuDB::new().with_ext_db(alloy_db);
262 let market_state_instance = MarketState::new(state_db);
263
264 // Add default tokens for price actor
265
266 info!("Creating blockchain and initial state");
267 // Create Blockchain instance which manages all channels
268 // Disable influxdb for test runner
269 let blockchain = Blockchain::new_with_config(1, false); // Chain ID 1 for mainnet, influxdb disabled
270

Callers 1

mainFunction · 0.85

Calls 15

mount_flashbots_mockFunction · 0.85
debug_trace_blockFunction · 0.85
privkeyMethod · 0.80
as_refMethod · 0.80
with_ext_dbMethod · 0.80
add_tokenMethod · 0.80
unwrap_or_defaultMethod · 0.80
set_eth_priceMethod · 0.80
enableMethod · 0.80
enable_web_serverMethod · 0.80
pools_configMethod · 0.80
swap_encoderMethod · 0.80

Tested by

no test coverage detected