From 030c0e4baf5106ff1eba6a82de5decb36461b0bc Mon Sep 17 00:00:00 2001 From: Boyu Yang Date: Tue, 9 Jan 2024 07:49:07 +0800 Subject: [PATCH] fix: refresh last state even no proved state, again --- src/protocols/light_client/peers.rs | 1 + src/tests/protocols/light_client/mod.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/protocols/light_client/peers.rs b/src/protocols/light_client/peers.rs index 86b3674..314bf68 100644 --- a/src/protocols/light_client/peers.rs +++ b/src/protocols/light_client/peers.rs @@ -910,6 +910,7 @@ impl PeerState { let new_state = Self::RequestFirstLastState { when_sent }; Ok(new_state) } + Self::OnlyHasLastState { .. } => Ok(self), Self::Ready { last_state, prove_state, diff --git a/src/tests/protocols/light_client/mod.rs b/src/tests/protocols/light_client/mod.rs index 5b41df5..623ad99 100644 --- a/src/tests/protocols/light_client/mod.rs +++ b/src/tests/protocols/light_client/mod.rs @@ -304,7 +304,20 @@ async fn refresh_all_peers() { protocol.notify(nc.context(), REFRESH_PEERS_TOKEN).await; - // TODO FIXME A request `GetLastState` should be sent. - assert!(nc.sent_messages().borrow().is_empty()); + let content = packed::GetLastState::new_builder() + .subscribe(true.pack()) + .build(); + let get_last_state_message = packed::LightClientMessage::new_builder() + .set(content) + .build() + .as_bytes(); + assert_eq!( + nc.sent_messages().borrow().clone(), + vec![( + SupportProtocols::LightClient.protocol_id(), + peer_index, + get_last_state_message + )] + ); } }