Refactor im-online and print more debug info. (#4771)

* Initial version.

* Fix tests.

* Refactor using StorageValueRef.

* Add tests and apply review suggestions.

* Bump runtime.

Co-authored-by: Gavin Wood <github@gavwood.com>
This commit is contained in:
Tomasz Drwięga
2020-01-31 19:59:49 +01:00
committed by GitHub
parent a36a170c15
commit 2f9315cc02
5 changed files with 353 additions and 157 deletions
+11 -2
View File
@@ -210,7 +210,11 @@ fn should_generate_heartbeats() {
// when
UintAuthorityId::set_all_keys(vec![0, 1, 2]);
ImOnline::offchain(2);
ImOnline::send_heartbeats(2)
.unwrap()
// make sure to consume the iterator and check there are no errors.
.collect::<Result<Vec<_>, _>>().unwrap();
// then
let transaction = state.write().transactions.pop().unwrap();
@@ -315,7 +319,12 @@ fn should_not_send_a_report_if_already_online() {
// when
UintAuthorityId::set_all_keys(vec![0]); // all authorities use pallet_session key 0
ImOnline::offchain(4);
// we expect error, since the authority is already online.
let mut res = ImOnline::send_heartbeats(4).unwrap();
assert_eq!(res.next().unwrap().unwrap(), ());
assert_eq!(res.next().unwrap().unwrap_err(), OffchainErr::AlreadyOnline(1));
assert_eq!(res.next().unwrap().unwrap_err(), OffchainErr::AlreadyOnline(2));
assert_eq!(res.next(), None);
// then
let transaction = pool_state.write().transactions.pop().unwrap();