Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixing RPC Filter conversion to EthFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Drwięga committed Oct 6, 2016
1 parent 6c1b2fb commit f2ccc06
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ethcore/src/types/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use client::BlockID;
use log_entry::LogEntry;

/// Blockchain Filter.
#[derive(Binary)]
#[derive(Binary, Debug, PartialEq)]
pub struct Filter {
/// Blockchain will be searched from this block.
pub from_block: BlockID,
Expand Down
41 changes: 39 additions & 2 deletions rpc/src/v1/types/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ impl Into<EthFilter> for Filter {
VariadicValue::Null => None,
VariadicValue::Single(t) => Some(vec![t.into()]),
VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
}).filter_map(|m| m).collect()).into_iter();
vec![iter.next(), iter.next(), iter.next(), iter.next()]
}).collect()).into_iter();

vec![
iter.next().unwrap_or(None),
iter.next().unwrap_or(None),
iter.next().unwrap_or(None),
iter.next().unwrap_or(None)
]
},
limit: self.limit,
}
Expand Down Expand Up @@ -121,6 +127,8 @@ mod tests {
use util::hash::*;
use super::*;
use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID;

#[test]
fn topic_deserialization() {
Expand Down Expand Up @@ -148,4 +156,33 @@ mod tests {
limit: None,
});
}

#[test]
fn filter_conversion() {
let filter = Filter {
from_block: Some(BlockNumber::Earliest),
to_block: Some(BlockNumber::Latest),
address: Some(VariadicValue::Multiple(vec![])),
topics: Some(vec![
VariadicValue::Null,
VariadicValue::Single("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()),
VariadicValue::Null,
]),
limit: None,
};

let eth_filter: EthFilter = filter.into();
assert_eq!(eth_filter, EthFilter {
from_block: BlockID::Earliest,
to_block: BlockID::Latest,
address: Some(vec![]),
topics: vec![
None,
Some(vec!["000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()]),
None,
None,
],
limit: None,
});
}
}

0 comments on commit f2ccc06

Please sign in to comment.