node/test: Use `Arbitrary` for `SignedRefs`

Ensure the test code does not rely on `SignedRefs` construction, but
rather the `Arbitrary` construction.
This commit is contained in:
Fintan Halpenny 2026-03-03 15:21:35 +00:00 committed by Lorenz Leutgeb
parent f7ff4d8f4e
commit 39a58ded05
2 changed files with 15 additions and 22 deletions

View File

@ -8,6 +8,7 @@ use std::str::FromStr;
use log::*;
use radicle::crypto;
use radicle::git::Oid;
use radicle::identity::Visibility;
use radicle::node::address::Store as _;
use radicle::node::device::Device;
@ -15,7 +16,8 @@ use radicle::node::Database;
use radicle::node::UserAgent;
use radicle::node::{address, Alias, ConnectOptions};
use radicle::rad;
use radicle::storage::refs::{RefsAt, SignedRefsAt, IDENTITY_ROOT};
use radicle::storage::refs;
use radicle::storage::refs::{RefsAt, SignedRefsAt};
use radicle::storage::{ReadRepository, RemoteRepository};
use radicle::Storage;
@ -360,17 +362,10 @@ where
ann.into().signed(self.signer()).into()
}
pub fn signed_refs_at<R: ReadRepository>(
&self,
mut refs: Refs,
at: radicle::git::Oid,
repo: &R,
) -> SignedRefsAt {
refs.insert(IDENTITY_ROOT.to_ref_string(), repo.identity_root().unwrap());
SignedRefsAt {
sigrefs: refs.signed(self.signer()).unwrap().verified(repo).unwrap(),
at,
}
pub fn signed_refs_at(&self, root: Oid) -> SignedRefsAt {
arbitrary::with_gen(8, |g| {
refs::arbitrary::signed_refs_at(g, root, self.signer())
})
}
pub fn connect_from(&mut self, peer: &Self) {

View File

@ -8,6 +8,7 @@ use std::sync::Arc;
use std::sync::LazyLock;
use std::time;
use radicle::storage::ReadRepository;
use test_log::test;
use radicle::cob;
@ -909,20 +910,19 @@ fn test_refs_announcement_followed() {
let node_id = alice.id;
let repo = alice.storage_mut().repo_mut(&rid);
let root = repo.identity_root().unwrap();
let sigrefs_at = bob.signed_refs_at(root);
repo.remotes.insert(
node_id,
bob.signed_refs_at(arbitrary::gen::<Refs>(8), arbitrary::oid(), repo),
);
repo.remotes.insert(node_id, sigrefs_at);
// Generate some refs for Bob under their own node_id.
let sigrefs = bob.signed_refs_at(arbitrary::gen::<Refs>(8), arbitrary::oid(), repo);
let sigrefs_at = bob.signed_refs_at(root);
let node_id = bob.id;
bob.init();
bob.storage_mut()
.repo_mut(&rid)
.remotes
.insert(node_id, sigrefs);
.insert(node_id, sigrefs_at);
// Alice uses Scope::Followed, and did not track Bob yet.
alice.connect_to(&bob);
@ -1582,10 +1582,8 @@ fn test_queued_fetch_from_ann_same_rid() {
// Finish the 1st fetch.
// Ensure the ref is in the storage and cache.
let repo = alice.storage_mut().repo_mut(&rid);
repo.remotes.insert(
carol.id(),
carol.signed_refs_at(arbitrary::gen::<Refs>(1), oid, repo),
);
let sigrefs_at = carol.signed_refs_at(repo.identity_root().unwrap());
repo.remotes.insert(carol.id(), sigrefs_at);
alice
.database_mut()
.refs_mut()