test: repair stale test fixtures across identity, mesh, update, wallet, fips
Several tests had drifted from the current production behavior: - identity_manager: create() already auto-provisions a Nostr key, so the explicit create_nostr_key() call failed with "already exists". Rewrite the test to assert on record.nostr_npub from create() directly. - mesh/protocol: test_build_app_start read the app name from frame[4..] but the v2 layout is [0:marker][1-2:len][3:cmd][4:version][5..:name]. test_identity_broadcast_roundtrip expected input DID = output DID but the v2 decoder derives DID from the ed25519 pubkey, so the roundtrip compares against did_key_from_pubkey_hex(&pub) now. - mesh/bitcoin_relay: test_build_block_header_announcement asserted sig.is_some(), but the builder intentionally emits an unsigned envelope to fit the 160-byte LoRa limit; assert sig.is_none(). Also widen placeholder hashes to the required 64 hex chars (32 bytes). - update: load_mirrors() now merges default mirrors post-migration, so the roundtrip test must assert the custom mirror survives alongside the defaults rather than strict equality. - wallet/cashu: test_proof_c_as_pubkey used hex that is not on the curve; replace with the secp256k1 generator point G so parsing succeeds. - fips: test_status_reports_no_key_pre_onboarding asserted npub.is_none(), which fails on dev boxes where the fips daemon is already running. Keep the !key_present assertion and drop the npub one.
This commit is contained in:
@@ -701,9 +701,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_build_app_start() -> Result<()> {
|
||||
// Frame layout: [0: '>'][1-2: len LE][3: CMD][4: VERSION][5..: padded name]
|
||||
let frame = build_app_start("Archipelago");
|
||||
assert_eq!(frame[3], CMD_APP_START);
|
||||
let name = &frame[4..];
|
||||
assert_eq!(frame[4], PROTOCOL_VERSION);
|
||||
let name = &frame[5..];
|
||||
assert_eq!(
|
||||
std::str::from_utf8(name)
|
||||
.map_err(|e| anyhow::anyhow!("invalid UTF-8 in app name: {}", e))?,
|
||||
@@ -753,15 +755,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_identity_broadcast_roundtrip() -> Result<()> {
|
||||
let did = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK";
|
||||
// The v2 encoding drops the DID and the decoder reconstructs it
|
||||
// deterministically from the ed25519 pubkey, so the roundtripped
|
||||
// DID won't equal an arbitrary input DID. Derive what the decoder
|
||||
// will produce and assert against that.
|
||||
let ed_pub = "a".repeat(64);
|
||||
let x25519_pub = "b".repeat(64);
|
||||
let expected_did = crate::identity::did_key_from_pubkey_hex(&ed_pub)
|
||||
.map_err(|e| anyhow::anyhow!("derive did: {}", e))?;
|
||||
|
||||
let encoded = encode_identity_broadcast(did, &ed_pub, &x25519_pub);
|
||||
let encoded = encode_identity_broadcast(&expected_did, &ed_pub, &x25519_pub);
|
||||
|
||||
let (parsed_did, parsed_ed, parsed_x) = parse_identity_broadcast(&encoded)
|
||||
.ok_or_else(|| anyhow::anyhow!("failed to parse identity broadcast"))?;
|
||||
assert_eq!(parsed_did, did);
|
||||
assert_eq!(parsed_did, expected_did);
|
||||
assert_eq!(parsed_ed, ed_pub);
|
||||
assert_eq!(parsed_x, x25519_pub);
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user