[RPC] Move runtime version from chain to state (#1243)

* Move runtimeVersion to state, add rudimentary test for subscription.

* Bump to latest jsonrpc.
This commit is contained in:
Tomasz Drwięga
2018-12-10 18:46:39 +00:00
committed by Robert Habermeier
parent 6299b42a4d
commit d28fda3d84
6 changed files with 121 additions and 104 deletions
+36
View File
@@ -178,3 +178,39 @@ fn should_query_storage() {
});
assert_eq!(result.unwrap(), expected);
}
#[test]
fn should_return_runtime_version() {
let core = ::tokio::runtime::Runtime::new().unwrap();
let client = Arc::new(test_client::new());
let api = State::new(client.clone(), Subscriptions::new(core.executor()));
assert_matches!(
api.runtime_version(None.into()),
Ok(ref ver) if ver == &runtime::VERSION
);
}
#[test]
fn should_notify_on_runtime_version_initially() {
let mut core = ::tokio::runtime::Runtime::new().unwrap();
let (subscriber, id, transport) = pubsub::Subscriber::new_test("test");
{
let client = Arc::new(test_client::new());
let api = State::new(client.clone(), Subscriptions::new(core.executor()));
api.subscribe_runtime_version(Default::default(), subscriber);
// assert id assigned
assert_eq!(core.block_on(id), Ok(Ok(SubscriptionId::Number(1))));
}
// assert initial version sent.
let (notification, next) = core.block_on(transport.into_future()).unwrap();
assert!(notification.is_some());
// no more notifications on this channel
assert_eq!(core.block_on(next.into_future()).unwrap().0, None);
}