test(relay): fix test_draft_rejected_p_tag — use third-party pubkey in p tag

EventBuilder silently drops p tags whose value equals the signer's own
pubkey (NIP self-tagging suppression, enabled by default). The test was
using owner.public_key().to_hex() as the p tag value, so the tag was
stripped before signing and the event arrived at the relay with no p tag
at all — the validator always saw a clean envelope and the rejection was
never exercised.

Fix: generate a separate Keys pair for the p tag value so it survives
EventBuilder's self-tag filter and reaches the relay's validator.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-07-14 00:21:25 -04:00
committed by Will Pfleger
co-authored by Will Pfleger
parent 6fcb8a723d
commit edd16089db
@@ -733,6 +733,11 @@ async fn test_draft_rejected_k_tag_out_of_range() {
async fn test_draft_rejected_p_tag() {
let client = http_client();
let owner = Keys::generate();
// Use a different pubkey for the `p` tag — EventBuilder silently strips
// `p` tags that match the signer's own key (NIP self-tagging rule), so
// testing with owner.public_key() would produce an event with NO `p` tag
// and the rejection would never be exercised.
let other = Keys::generate();
let ch_id = create_open_channel(&owner).await;
let d = uuid::Uuid::new_v4().to_string();
let event = EventBuilder::new(Kind::Custom(KIND_DRAFT), fake_nip44_v2())
@@ -740,7 +745,7 @@ async fn test_draft_rejected_p_tag() {
Tag::parse(["d", &d]).unwrap(),
Tag::parse(["k", "9"]).unwrap(),
Tag::parse(["h", &ch_id]).unwrap(),
Tag::parse(["p", &owner.public_key().to_hex()]).unwrap(),
Tag::parse(["p", &other.public_key().to_hex()]).unwrap(),
])
.sign_with_keys(&owner)
.unwrap();