Skip to content

Commit 6fcc1cd

Browse files
authored
GH-813: Correctly parse max block range error message (#531)
1 parent 25e9a4f commit 6fcc1cd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

node/src/blockchain/blockchain_bridge.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl BlockchainBridge {
456456

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

1758+
#[test]
1759+
fn extract_max_block_range_for_nodies_error_response() {
1760+
let result = BlockchainError::QueryFailed("RPC error: Error { code: InvalidParams, message: \"query exceeds max block range 100000\", data: None }".to_string());
1761+
let subject = BlockchainBridge::new(
1762+
Box::new(BlockchainInterfaceMock::default()),
1763+
Box::new(PersistentConfigurationMock::default()),
1764+
false,
1765+
);
1766+
let max_block_count = subject.extract_max_block_count(result);
1767+
1768+
assert_eq!(Some(100000), max_block_count);
1769+
}
1770+
17581771
#[test]
17591772
fn extract_max_block_range_for_expected_batch_got_single_error_response() {
17601773
let result = BlockchainError::QueryFailed(

0 commit comments

Comments
 (0)