Skip to content

Commit db4e2b1

Browse files
authored
Refine regex for max block count extraction and add test
Updated regex to capture maximum block count from error messages more accurately - namely update to Nodies provider. Added a new test case for extracting this specific error response.
1 parent fb9718e commit db4e2b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

node/src/blockchain/blockchain_bridge.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ impl BlockchainBridge {
507507

508508
pub fn extract_max_block_count(error: BlockchainError) -> Option<u64> {
509509
let regex_result =
510-
Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range )(?P<max_block_count>\d+).*")
511-
.expect("Invalid regex");
510+
Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range |maximum allowed is )(?P<max_block_count>\d+).*")
511+
.expect("Invalid regex");
512512
let max_block_count = match error {
513513
BlockchainError::QueryFailed(msg) => match regex_result.captures(msg.as_str()) {
514514
Some(captures) => match captures.name("max_block_count") {
@@ -2201,6 +2201,15 @@ mod tests {
22012201
assert_eq!(Some(100000), max_block_count);
22022202
}
22032203

2204+
#[test]
2205+
fn extract_max_block_range_for_nodies_error_response_v2() {
2206+
let result = BlockchainError::QueryFailed("RPC error: Error { code: ServerError(-32001), message: \"Block range too large: maximum allowed is 20000 blocks\", data: None }".to_string());
2207+
2208+
let max_block_count = BlockchainBridge::extract_max_block_count(result);
2209+
2210+
assert_eq!(Some(20000), max_block_count);
2211+
}
2212+
22042213
#[test]
22052214
fn extract_max_block_range_for_expected_batch_got_single_error_response() {
22062215
let result = BlockchainError::QueryFailed(

0 commit comments

Comments
 (0)