Create a single DepositRequest for testing with valid ED25519 and BLS signatures This function creates a test deposit request with all required fields, including cryptographically valid signatures that can be verified against the deposit message. # Arguments `index` - The deposit index value used for generating deterministic keys and in the signature `amount` - The deposit amount in gwei `domain
(
index: u64,
amount: u64,
domain: Digest,
private_key: Option<PrivateKey>,
withdrawal_credentials: Option<[u8; 32]>,
)
| 451 | |
| 452 | /// Extracts the validator id from a metric string. |
| 453 | /// |
| 454 | /// # Arguments |
| 455 | /// * `metric` - The metric name to parse from |
| 456 | /// |
| 457 | /// # Returns |
| 458 | /// * `Some(String)` if the validator id is contained in the string |
| 459 | /// * `None` if the validator if doesn't exist |
| 460 | /// ``` |
| 461 | pub fn extract_validator_id(metric: &str) -> Option<String> { |
| 462 | // Metric format is: validator_{pubkey}_{component}_{metric_name} |
| 463 | // We need to extract validator_{pubkey} |
| 464 | let prefix = "validator_"; |
| 465 | |
| 466 | if !metric.starts_with(prefix) { |
| 467 | return None; |
| 468 | } |
| 469 | |
| 470 | // Find the position after "validator_" |
| 471 | let start = prefix.len(); |
| 472 | |
| 473 | // Find the next underscore after "validator_" |
| 474 | let remaining = &metric[start..]; |
| 475 | let end_offset = remaining.find('_')?; |
| 476 | |
| 477 | // Extract from beginning to the second underscore (start + end_offset) |
| 478 | Some(metric[..start + end_offset].to_string()) |
| 479 | } |
| 480 | |
| 481 | /// Create a single DepositRequest for testing with valid ED25519 and BLS signatures |
| 482 | /// |
| 483 | /// This function creates a test deposit request with all required fields, including |
| 484 | /// cryptographically valid signatures that can be verified against the deposit message. |
| 485 | /// |
| 486 | /// # Arguments |
| 487 | /// * `index` - The deposit index value used for generating deterministic keys and in the signature |
| 488 | /// * `amount` - The deposit amount in gwei |
| 489 | /// * `domain` - The domain value used in the signature |
| 490 | /// * `private_key` - Optional ED25519 private key to use; if None, generates deterministic key from index |
| 491 | /// * `withdrawal_credentials` - Optional withdrawal credentials; if None, generates Eth1 format credentials |
| 492 | /// |
| 493 | /// # Returns |
| 494 | /// * `(DepositRequest, PrivateKey, bls12381::PrivateKey)` - A tuple containing: |
| 495 | /// - `DepositRequest` - A complete deposit request with valid signatures |
| 496 | /// - `PrivateKey` - The ED25519 private key used to sign the request |
| 497 | /// - `bls12381::PrivateKey` - The BLS private key used to sign the request |
| 498 | pub fn create_deposit_request( |
| 499 | index: u64, |
| 500 | amount: u64, |
| 501 | domain: Digest, |
| 502 | private_key: Option<PrivateKey>, |
| 503 | consensus_key: Option<bls12381::PrivateKey>, |
| 504 | withdrawal_credentials: Option<[u8; 32]>, |
| 505 | ) -> (DepositRequest, PrivateKey, bls12381::PrivateKey) { |
| 506 | let withdrawal_credentials = if let Some(withdrawal_credentials) = withdrawal_credentials { |
| 507 | withdrawal_credentials |
| 508 | } else { |
| 509 | // Create valid Eth1 withdrawal credentials: 0x01 + 11 zero bytes + 20-byte address |
| 510 | let mut withdrawal_credentials = [0u8; 32]; |