Skip to content

Commit

Permalink
Adjust to move to trait
Browse files Browse the repository at this point in the history
  • Loading branch information
xla committed Jun 30, 2020
1 parent 511fc99 commit a452244
Showing 1 changed file with 63 additions and 15 deletions.
78 changes: 63 additions & 15 deletions light-node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ pub trait Rpc {

pub use self::rpc_impl_Rpc::gen_client::Client;

pub struct Server {
handle: Handle,
pub struct Server<H>
where
H: Handle,
{
handle: H,
}

impl Server {
pub fn new(handle: Handle) -> Self {
impl<H> Server<H>
where
H: Handle,
{
pub fn new(handle: H) -> Self {
Self { handle }
}
}

impl Rpc for Server {
impl<H> Rpc for Server<H>
where
H: Handle + Send + Sync + 'static,
{
fn state(&self) -> FutureResult<Option<LightBlock>, Error> {
future::result(self.handle.latest_trusted())
}
Expand All @@ -53,11 +62,15 @@ mod test {
use jsonrpc_core_client::transports::local;
use pretty_assertions::assert_eq;

use tendermint_light_client::errors::Error;
use tendermint_light_client::supervisor::Handle;
use tendermint_light_client::types::{Height, LightBlock};

use super::{Client, Rpc as _, Server};

#[tokio::test]
async fn state() {
let server = Server::new();
let server = Server::new(MockHandle {});
let fut = {
let mut io = IoHandler::new();
io.extend_with(server.to_delegate());
Expand All @@ -66,19 +79,19 @@ mod test {
};
let (res, _) = fut.compat().await.unwrap();

assert_eq!(
res,
super::State {
header: "".to_string(),
commit: "".to_string(),
validator_set: "".to_string(),
}
);
// assert_eq!(
// res,
// super::State {
// header: "".to_string(),
// commit: "".to_string(),
// validator_set: "".to_string(),
// }
// );
}

#[tokio::test]
async fn status() {
let server = Server::new();
let server = Server::new(MockHandle {});
let fut = {
let mut io = IoHandler::new();
io.extend_with(server.to_delegate());
Expand All @@ -89,4 +102,39 @@ mod test {

assert_eq!(res, super::Status { latest_height: 12 });
}

struct MockHandle;

impl Handle for MockHandle {
fn latest_trusted(&mut self) -> Result<Option<LightBlock>, Error> {
todo!()
}

fn verify_to_highest(&mut self) -> Result<LightBlock, Error> {
todo!()
}

fn verify_to_target(&mut self, height: Height) -> Result<LightBlock, Error> {
todo!()
}

fn verify_to_highest_async(
&mut self,
callback: impl FnOnce(Result<LightBlock, Error>) -> () + Send + 'static,
) {
todo!()
}

fn verify_to_target_async(
&mut self,
height: Height,
callback: impl FnOnce(Result<LightBlock, Error>) -> () + Send + 'static,
) {
todo!()
}

fn terminate(&mut self) {
todo!()
}
}
}

0 comments on commit a452244

Please sign in to comment.