Skip to content

Commit

Permalink
GH-813: Correctly parse max block range error message
Browse files Browse the repository at this point in the history
  • Loading branch information
masqrauder committed Sep 28, 2024
1 parent 25e9a4f commit f647f2e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl BlockchainBridge {

pub fn extract_max_block_count(&self, error: BlockchainError) -> Option<u64> {
let regex_result =
Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \()(?P<max_block_count>\d+).*")
Regex::new(r".* (max: |allowed for your plan: |is limited to |block range limit \(|exceeds max block range )(?P<max_block_count>\d+).*")
.expect("Invalid regex");
let max_block_count = match error {
BlockchainError::QueryFailed(msg) => match regex_result.captures(msg.as_str()) {
Expand Down Expand Up @@ -1755,6 +1755,19 @@ mod tests {
assert_eq!(None, max_block_count);
}

#[test]
fn extract_max_block_range_for_nodies_error_response() {
let result = BlockchainError::QueryFailed("RPC error: Error { code: InvalidParams, message: \"query exceeds max block range 100000\", data: None }".to_string());
let subject = BlockchainBridge::new(
Box::new(BlockchainInterfaceMock::default()),
Box::new(PersistentConfigurationMock::default()),
false,
);
let max_block_count = subject.extract_max_block_count(result);

assert_eq!(Some(100000), max_block_count);
}

#[test]
fn extract_max_block_range_for_expected_batch_got_single_error_response() {
let result = BlockchainError::QueryFailed(
Expand Down

0 comments on commit f647f2e

Please sign in to comment.