Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-813: Correctly parse max block range error message #531

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading