Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Apr 5, 2024
1 parent 3a6dcdc commit 6d9824f
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 139 deletions.
18 changes: 17 additions & 1 deletion damus/Models/EventRef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,23 @@ func interp_event_refs_with_mentions(tags: Tags) -> [EventRef] {
return replies
}

func interpret_event_refs(blocks: BlocksSequence, tags: Tags) -> [EventRef] {
func interpret_event_refs(tags: Tags) -> [EventRef] {
if tags.count == 0 {
return []
}

/// build a set of indices for each event mention
//let mention_indices = build_mention_indices(blocks, type: .e)

/// simpler case with no mentions
//if mention_indices.count == 0 {
//return interp_event_refs_without_mentions_ndb(References<NoteRef>(tags: tags))
//}

return interp_event_refs_with_mentions(tags: tags)
}

func ndb_interpret_event_refs(tags: Tags) -> [EventRef] {
if tags.count == 0 {
return []
}
Expand Down
4 changes: 4 additions & 0 deletions damus/Models/Mentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extension UnsafePointer<UInt8> {
struct MentionRef: TagKeys, TagConvertible, Equatable, Hashable {
let nip19: Bech32Object

static func pubkey(_ pubkey: Pubkey) -> MentionRef {
self.init(nip19: .npub(pubkey))
}

static func note(_ note_id: NoteId) -> MentionRef {
return self.init(nip19: .note(note_id))
}
Expand Down
10 changes: 10 additions & 0 deletions damus/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct NostrPost {
}
}

/// This should only be used in tests, we don't use this anymore directly
func parse_note_content(content: NoteContent) -> Blocks?
{
switch content {
case .note(let note):
return parse_post_blocks(content: note.content)
case .content(let content, _):
return parse_post_blocks(content: content)
}
}

/// Return a list of tags
func parse_post_blocks(content: String) -> Blocks? {
Expand Down
6 changes: 2 additions & 4 deletions damus/Views/DMChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ struct DMChatView: View, KeyboardReadable {

func send_message() {
let tags = [["p", pubkey.hex()]]
let post_blocks = parse_post_blocks(content: dms.draft)?.blocks
guard let content = post_blocks?.map({ pb in pb.asString }).joined(separator: "") else {
// TODO: handle these errors somehow?
print("error creating dm")
guard let post_blocks = parse_post_blocks(content: dms.draft)?.blocks else {
return
}
let content = post_blocks.map({ pb in pb.asString }).joined(separator: "")

guard let dm = create_dm(content, to_pk: pubkey, tags: tags, keypair: damus_state.keypair) else {
print("error creating dm")
Expand Down
30 changes: 15 additions & 15 deletions damusTests/Bech32ObjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Bech32ObjectTests: XCTestCase {
func testTLVParsing_NeventHasRelaysNoAuthorNoKind_ValidContent() throws {
let content = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5nxnepm"
let expectedNoteIDHex = "b9f5441e45ca39179320e0031cfb18e34078673dcc3d3e3a3b3a981760aa5696"
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"]
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"].compactMap(RelayURL.init)
guard let noteid = hex_decode_noteid(expectedNoteIDHex) else {
XCTFail("Parsing note ID failed")
return
Expand All @@ -34,7 +34,7 @@ class Bech32ObjectTests: XCTestCase {
func testTLVParsing_NeventHasRelaysNoAuthorHasKind_ValidContent() throws {
let content = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5qvzqqqqqqyjyqz7d"
let expectedNoteIDHex = "b9f5441e45ca39179320e0031cfb18e34078673dcc3d3e3a3b3a981760aa5696"
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"]
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"].compactMap(RelayURL.init)
guard let noteid = hex_decode_noteid(expectedNoteIDHex) else {
XCTFail("Parsing note ID failed")
return
Expand All @@ -53,7 +53,7 @@ class Bech32ObjectTests: XCTestCase {
let content = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5qgsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8grqsqqqqqpw4032x"

let expectedNoteIDHex = "b9f5441e45ca39179320e0031cfb18e34078673dcc3d3e3a3b3a981760aa5696"
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"]
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"].compactMap(RelayURL.init)
guard let noteid = hex_decode_noteid(expectedNoteIDHex) else {
XCTFail("Parsing note ID failed")
return
Expand All @@ -78,8 +78,8 @@ class Bech32ObjectTests: XCTestCase {
XCTFail()
return
}
let relays = ["wss://r.x.com", "wss://djbas.sadkb.com"]
let relays = ["wss://r.x.com", "wss://djbas.sadkb.com"].compactMap(RelayURL.init)

let expectedObject = Bech32Object.nprofile(NProfile(author: Pubkey(author.data), relays: relays))
guard let actualObject = Bech32Object.parse(content) else {
XCTFail("Invalid Object")
Expand All @@ -106,7 +106,7 @@ class Bech32ObjectTests: XCTestCase {
XCTFail("Can't decode npub")
return
}
let relays = ["wss://relay.nostr.band"]
let relays = ["wss://relay.nostr.band"].compactMap(RelayURL.init)
let identifier = "1700730909108"
let kind: UInt32 = 30023

Expand All @@ -122,8 +122,8 @@ class Bech32ObjectTests: XCTestCase {
return
}

let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"]
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"].compactMap(RelayURL.init)

let expectedEncoding = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5nxnepm"

let actualEncoding = Bech32Object.encode(.nevent(NEvent(noteid: noteid, relays: relays)))
Expand All @@ -140,8 +140,8 @@ class Bech32ObjectTests: XCTestCase {
let relays = [
"wss://nostr-relay.untethr.me",
"wss://nostr-pub.wellorder.net"
]
].compactMap(RelayURL.init)

let expectedEncoding = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5qvzqqqqqqyjyqz7d"

let actualEncoding = Bech32Object.encode(.nevent(NEvent(noteid: noteid, relays: relays, kind: 1)))
Expand All @@ -159,8 +159,8 @@ class Bech32ObjectTests: XCTestCase {
return
}

let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"]
let relays = ["wss://nostr-relay.untethr.me", "wss://nostr-pub.wellorder.net"].compactMap(RelayURL.init)

let expectedEncoding = "nevent1qqstna2yrezu5wghjvswqqculvvwxsrcvu7uc0f78gan4xqhvz49d9spr3mhxue69uhkummnw3ez6un9d3shjtn4de6x2argwghx6egpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5qgsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8grqsqqqqqpw4032x"

let actualEncoding = Bech32Object.encode(.nevent(NEvent(noteid: noteid, relays: relays, author: Pubkey(author.data), kind: 1)))
Expand All @@ -177,8 +177,8 @@ class Bech32ObjectTests: XCTestCase {
let relays = [
"wss://r.x.com",
"wss://djbas.sadkb.com"
]
].compactMap(RelayURL.init)

let expectedEncoding = "nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p"

let actualEncoding = Bech32Object.encode(.nprofile(NProfile(author: Pubkey(author.data), relays: relays)))
Expand All @@ -202,7 +202,7 @@ class Bech32ObjectTests: XCTestCase {
return
}

let relays = ["wss://relay.nostr.band"]
let relays = ["wss://relay.nostr.band"].compactMap(RelayURL.init)
let identifier = "1700730909108"
let kind: UInt32 = 30023

Expand Down
Loading

0 comments on commit 6d9824f

Please sign in to comment.