Skip to content

Commit

Permalink
test: check that peers existing doesn't break retrieving pending blobs
Browse files Browse the repository at this point in the history
Blobs get inserted into sled with `3u8` as their first byte.
Peers have a prefix byte of `4u8`.
However, the `get_pending_blobs` function uses an open range to query the
store, just like `get_peers` used to do.

This means we can cause a deserialization error when querying pending blobs,
simply by inserting a peer into the store. The open range query will return
the peer as a byte string and try to deserialize it into a `Blob` struct.
  • Loading branch information
black-puppydog committed Jul 22, 2024
1 parent 810b1a3 commit 1c377e3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions solar/src/storage/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,53 @@ mod test {
Ok(())
}

#[async_std::test]
async fn test_blobs_range_query_when_peers_exist() -> Result<()> {
let (keypair, kv) = initialise_keypair_and_kv()?;
kv.set_blob(
"b1",
&BlobStatus {
retrieved: false,
users: ["u2".to_string()].to_vec(),
},
)?;

assert_eq!(kv.get_peers().await?.len(), 0);

assert_eq!(kv.get_pending_blobs().unwrap(), vec!["b1".to_string()]);

println!("Inserting a new message and thus peer");
let msg_content = TypedMessage::Post {
text: "A solar flare is an intense localized eruption of electromagnetic radiation."
.to_string(),
mentions: None,
};
// Passing None as the last message since we start from an empty feed
let msg = MessageValue::sign(None, &keypair, json!(msg_content))?;
let _ = kv.append_feed(msg).await?;

// now that we have added a message, we should have one peer,
// which is the keypair we used to sign the message.
let peers = kv.get_peers().await?;
assert_eq!(peers.len(), 1);

println!("Inserting a second blob");
kv.set_blob(
"b2",
&BlobStatus {
retrieved: false,
users: ["u7".to_string()].to_vec(),
},
)?;

assert_eq!(
kv.get_pending_blobs()?,
vec!["b1".to_string(), "b2".to_string()]
);

Ok(())
}

#[test]
fn test_blobs() -> Result<()> {
let kv = open_temporary_kv()?;
Expand Down

0 comments on commit 1c377e3

Please sign in to comment.