Fix test compilation issues
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -70,14 +70,15 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
*/
|
||||
|
||||
func testAuthIntegrationRelayDamusIo() {
|
||||
@MainActor
|
||||
func testAuthIntegrationRelayDamusIo() async {
|
||||
// Create relay pool and connect to `wss://relay.damus.io`
|
||||
let relay_url = RelayURL("wss://relay.damus.io")!
|
||||
var received_messages: [String] = []
|
||||
var sent_messages: [String] = []
|
||||
let keypair: Keypair = generate_new_keypair().to_keypair()
|
||||
let pool = RelayPool(ndb: Ndb.test, keypair: keypair)
|
||||
pool.message_received_function = { obj in
|
||||
await pool.set_message_received_function({ obj in
|
||||
let str = obj.0
|
||||
let descriptor = obj.1
|
||||
|
||||
@@ -86,8 +87,8 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
|
||||
received_messages.append(str)
|
||||
}
|
||||
pool.message_sent_function = { obj in
|
||||
})
|
||||
await pool.set_message_sent_function({ obj in
|
||||
let str = obj.0
|
||||
let relay = obj.1
|
||||
|
||||
@@ -96,10 +97,10 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
|
||||
sent_messages.append(str)
|
||||
}
|
||||
})
|
||||
XCTAssertEqual(pool.relays.count, 0)
|
||||
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .readWrite)
|
||||
try! pool.add_relay(relay_descriptor)
|
||||
try! await pool.add_relay(relay_descriptor)
|
||||
XCTAssertEqual(pool.relays.count, 1)
|
||||
let connection_expectation = XCTestExpectation(description: "Waiting for connection")
|
||||
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
|
||||
@@ -114,14 +115,15 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
XCTAssertEqual(received_messages.count, 0)
|
||||
}
|
||||
|
||||
func testAuthIntegrationNostrWine() {
|
||||
@MainActor
|
||||
func testAuthIntegrationNostrWine() async {
|
||||
// Create relay pool and connect to `wss://nostr.wine`
|
||||
let relay_url = RelayURL("wss://nostr.wine")!
|
||||
var received_messages: [String] = []
|
||||
var sent_messages: [String] = []
|
||||
let keypair: Keypair = generate_new_keypair().to_keypair()
|
||||
let pool = RelayPool(ndb: Ndb.test, keypair: keypair)
|
||||
pool.message_received_function = { obj in
|
||||
await pool.set_message_received_function({ obj in
|
||||
let str = obj.0
|
||||
let descriptor = obj.1
|
||||
|
||||
@@ -130,8 +132,8 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
|
||||
received_messages.append(str)
|
||||
}
|
||||
pool.message_sent_function = { obj in
|
||||
})
|
||||
await pool.set_message_sent_function({ obj in
|
||||
let str = obj.0
|
||||
let relay = obj.1
|
||||
|
||||
@@ -140,10 +142,10 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
|
||||
sent_messages.append(str)
|
||||
}
|
||||
})
|
||||
XCTAssertEqual(pool.relays.count, 0)
|
||||
let relay_descriptor = RelayPool.RelayDescriptor.init(url: relay_url, info: .readWrite)
|
||||
try! pool.add_relay(relay_descriptor)
|
||||
try! await pool.add_relay(relay_descriptor)
|
||||
XCTAssertEqual(pool.relays.count, 1)
|
||||
let connection_expectation = XCTestExpectation(description: "Waiting for connection")
|
||||
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
|
||||
@@ -162,7 +164,7 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
let subscribe = NostrSubscribe(filters: [
|
||||
NostrFilter(kinds: [.dm])
|
||||
], sub_id: uuid)
|
||||
pool.send(NostrRequest.subscribe(subscribe))
|
||||
await pool.send(NostrRequest.subscribe(subscribe))
|
||||
// Wait for AUTH message to have been received & sent
|
||||
let msg_expectation = XCTestExpectation(description: "Waiting for messages")
|
||||
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
|
||||
@@ -186,3 +188,13 @@ final class AuthIntegrationTests: XCTestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension RelayPool {
|
||||
func set_message_received_function(_ newFunction: (((String, RelayDescriptor)) -> Void)?) {
|
||||
self.message_received_function = newFunction
|
||||
}
|
||||
|
||||
func set_message_sent_function(_ newFunction: (((String, Relay)) -> Void)? = nil) {
|
||||
self.message_sent_function = newFunction
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ final class MutingTests: XCTestCase {
|
||||
}
|
||||
|
||||
await test_damus_state.mutelist_manager.set_mutelist(mutelist)
|
||||
test_damus_state.nostrNetwork.postbox.send(mutelist)
|
||||
await test_damus_state.nostrNetwork.postbox.send(mutelist)
|
||||
|
||||
let spammy_note_muted = await test_damus_state.mutelist_manager.is_event_muted(spammy_test_note)
|
||||
XCTAssert(spammy_note_muted)
|
||||
|
||||
@@ -147,7 +147,7 @@ final class NIP10Tests: XCTestCase {
|
||||
XCTAssertEqual(tr.is_reply_to_root, true)
|
||||
}
|
||||
|
||||
func test_marker_reply() {
|
||||
func test_marker_reply() async {
|
||||
let note_json = """
|
||||
{
|
||||
"pubkey": "5b0183ab6c3e322bf4d41c6b3aef98562a144847b7499543727c5539a114563e",
|
||||
@@ -181,7 +181,7 @@ final class NIP10Tests: XCTestCase {
|
||||
let pk = Pubkey(hex: "5b0183ab6c3e322bf4d41c6b3aef98562a144847b7499543727c5539a114563e")!
|
||||
//let last_reply_hex = "1bb940ce0ba0d4a3b2a589355d908498dcd7452f941cf520072218f7e6ede75e"
|
||||
let note = decode_nostr_event_json(json: note_json)!
|
||||
let reply = build_post(state: test_damus_state, post: .init(string: "hello"), action: .replying_to(note), uploadedMedias: [], pubkeys: [pk] + note.referenced_pubkeys.map({pk in pk}))
|
||||
let reply = await build_post(state: test_damus_state, post: .init(string: "hello"), action: .replying_to(note), uploadedMedias: [], pubkeys: [pk] + note.referenced_pubkeys.map({pk in pk}))
|
||||
let root_hex = "00152d2945459fb394fed2ea95af879c903c4ec42d96327a739fa27c023f20e0"
|
||||
|
||||
XCTAssertEqual(reply.tags,
|
||||
|
||||
@@ -15,8 +15,6 @@ class NostrNetworkManagerTests: XCTestCase {
|
||||
override func setUpWithError() throws {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
damusState = generate_test_damus_state(mock_profile_info: nil)
|
||||
try! damusState?.nostrNetwork.userRelayList.set(userRelayList: NIP65.RelayList())
|
||||
damusState?.nostrNetwork.connect()
|
||||
|
||||
let notesJSONL = getTestNotesJSONL()
|
||||
|
||||
@@ -59,9 +57,10 @@ class NostrNetworkManagerTests: XCTestCase {
|
||||
gotAtLeastExpectedCount.fulfill()
|
||||
}
|
||||
case .eose:
|
||||
continue
|
||||
case .ndbEose:
|
||||
// End of stream, break out of the loop
|
||||
endOfStream.fulfill()
|
||||
case .ndbEose:
|
||||
continue
|
||||
case .networkEose:
|
||||
continue
|
||||
@@ -83,7 +82,10 @@ class NostrNetworkManagerTests: XCTestCase {
|
||||
/// ```
|
||||
/// nak req --kind 1 ws://localhost:10547 | wc -l
|
||||
/// ```
|
||||
func testNdbSubscription() {
|
||||
func testNdbSubscription() async {
|
||||
try! await damusState?.nostrNetwork.userRelayList.set(userRelayList: NIP65.RelayList())
|
||||
await damusState?.nostrNetwork.connect()
|
||||
|
||||
ensureSubscribeGetsAllExpectedNotes(filter: NostrFilter(kinds: [.text]), expectedCount: 57)
|
||||
ensureSubscribeGetsAllExpectedNotes(filter: NostrFilter(authors: [Pubkey(hex: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245")!]), expectedCount: 22)
|
||||
ensureSubscribeGetsAllExpectedNotes(filter: NostrFilter(kinds: [.boost], referenced_ids: [NoteId(hex: "64b26d0a587f5f894470e1e4783756b4d8ba971226de975ee30ac1b69970d5a1")!]), expectedCount: 5)
|
||||
|
||||
@@ -15,8 +15,6 @@ final class ThreadModelTests: XCTestCase {
|
||||
override func setUpWithError() throws {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
damusState = generate_test_damus_state(mock_profile_info: nil)
|
||||
try! damusState?.nostrNetwork.userRelayList.set(userRelayList: NIP65.RelayList())
|
||||
damusState?.nostrNetwork.connect()
|
||||
|
||||
let notesJSONL = getTestNotesJSONL()
|
||||
|
||||
@@ -40,7 +38,10 @@ final class ThreadModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
/// Tests loading up a thread and checking if the repost count loads as expected.
|
||||
func testActionBarModel() throws {
|
||||
func testActionBarModel() async throws {
|
||||
try! await damusState?.nostrNetwork.userRelayList.set(userRelayList: NIP65.RelayList())
|
||||
await damusState?.nostrNetwork.connect()
|
||||
|
||||
let testNoteJson = """
|
||||
{"content":"https://smartflowsocial.s3.us-east-1.amazonaws.com/clients/cm7kdrwdk0000qyu6fwtd96ui/0cab65a9-0142-48e3-abd7-94d20e30d3b2.jpg\n\n","pubkey":"71ecabd8b6b33548e075ff01b31568ffda19d0ac2788067d99328c6de4885975","tags":[["t","meme"],["t","memes"],["t","memestr"],["t","plebchain"]],"created_at":1755694800,"id":"64b26d0a587f5f894470e1e4783756b4d8ba971226de975ee30ac1b69970d5a1","kind":1,"sig":"c000794da8c4f7549b546630b16ed17f6edc0af0269b8c46ce14f5b1937431e7575b78351bc152007ebab5720028e5fe4b738f99e8887f273d35dd2217d1cc3d"}
|
||||
"""
|
||||
@@ -52,7 +53,7 @@ final class ThreadModelTests: XCTestCase {
|
||||
let actionBarModel = make_actionbar_model(ev: note.id, damus: damusState!)
|
||||
while true {
|
||||
try await Task.sleep(nanoseconds: 500_000_000)
|
||||
actionBarModel.update(damus: damusState!, evid: note.id)
|
||||
await actionBarModel.update(damus: damusState!, evid: note.id)
|
||||
if actionBarModel.boosts >= 5 {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -171,13 +171,13 @@ final class PostViewTests: XCTestCase {
|
||||
nonAlphaNumerics.forEach { testAddingStringAfterLink(str: $0)}
|
||||
}
|
||||
|
||||
func testQuoteRepost() {
|
||||
let post = build_post(state: test_damus_state, post: .init(), action: .quoting(test_note), uploadedMedias: [], pubkeys: [])
|
||||
func testQuoteRepost() async {
|
||||
let post = await build_post(state: test_damus_state, post: .init(), action: .quoting(test_note), uploadedMedias: [], pubkeys: [])
|
||||
|
||||
XCTAssertEqual(post.tags, [["q", test_note.id.hex(), "", jack_keypair.pubkey.hex()], ["p", jack_keypair.pubkey.hex()]])
|
||||
}
|
||||
|
||||
func testBuildPostRecognizesStringsAsNpubs() throws {
|
||||
func testBuildPostRecognizesStringsAsNpubs() async throws {
|
||||
// given
|
||||
let expectedLink = "nostr:\(test_pubkey.npub)"
|
||||
let content = NSMutableAttributedString(string: "@test", attributes: [
|
||||
@@ -185,7 +185,7 @@ final class PostViewTests: XCTestCase {
|
||||
])
|
||||
|
||||
// when
|
||||
let post = build_post(
|
||||
let post = await build_post(
|
||||
state: test_damus_state,
|
||||
post: content,
|
||||
action: .posting(.user(test_pubkey)),
|
||||
@@ -197,7 +197,7 @@ final class PostViewTests: XCTestCase {
|
||||
XCTAssertEqual(post.content, expectedLink)
|
||||
}
|
||||
|
||||
func testBuildPostRecognizesUrlsAsNpubs() throws {
|
||||
func testBuildPostRecognizesUrlsAsNpubs() async throws {
|
||||
// given
|
||||
guard let npubUrl = URL(string: "damus:nostr:\(test_pubkey.npub)") else {
|
||||
return XCTFail("Could not create URL")
|
||||
@@ -207,7 +207,7 @@ final class PostViewTests: XCTestCase {
|
||||
])
|
||||
|
||||
// when
|
||||
let post = build_post(
|
||||
let post = await build_post(
|
||||
state: test_damus_state,
|
||||
post: content,
|
||||
action: .posting(.user(test_pubkey)),
|
||||
|
||||
@@ -86,7 +86,7 @@ class ReplyTests: XCTestCase {
|
||||
// XCTAssertEqual(post_blocks.count, 1)
|
||||
// }
|
||||
|
||||
func testNewlineMentions() throws {
|
||||
func testNewlineMentions() async throws {
|
||||
let bech32_pk = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s"
|
||||
let pk = bech32_pubkey_decode(bech32_pk)!
|
||||
|
||||
@@ -96,7 +96,7 @@ class ReplyTests: XCTestCase {
|
||||
post.append(user_tag_attr_string(profile: profile, pubkey: pk))
|
||||
post.append(.init(string: "\n"))
|
||||
|
||||
let post_note = build_post(state: test_damus_state, post: post, action: .posting(.none), uploadedMedias: [], pubkeys: [pk])
|
||||
let post_note = await build_post(state: test_damus_state, post: post, action: .posting(.none), uploadedMedias: [], pubkeys: [pk])
|
||||
|
||||
let expected_render = "nostr:\(pk.npub)\nnostr:\(pk.npub)"
|
||||
XCTAssertEqual(post_note.content, expected_render)
|
||||
|
||||
@@ -79,7 +79,8 @@ final class WalletConnectTests: XCTestCase {
|
||||
XCTAssertEqual(url_2.relay.url.absoluteString, relay_2)
|
||||
}
|
||||
|
||||
func testNWCEphemeralRelay() {
|
||||
@MainActor
|
||||
func testNWCEphemeralRelay() async {
|
||||
let sec = "8ba3a6b3b57d0f4211bb1ea4d8d1e351a367e9b4ea694746e0a4a452b2bc4d37"
|
||||
let pk = "89446b900c70d62438dcf66756405eea6225ad94dc61f3856f62f9699111a9a6"
|
||||
let nwc = WalletConnectURL(str: "nostrwalletconnect://\(pk)?relay=ws://127.0.0.1&secret=\(sec)&lud16=jb55@jb55.com")!
|
||||
@@ -87,7 +88,7 @@ final class WalletConnectTests: XCTestCase {
|
||||
let pool = RelayPool(ndb: .empty)
|
||||
let box = PostBox(pool: pool)
|
||||
|
||||
WalletConnect.pay(url: nwc, pool: pool, post: box, invoice: "invoice", zap_request: nil)
|
||||
await WalletConnect.pay(url: nwc, pool: pool, post: box, invoice: "invoice", zap_request: nil)
|
||||
|
||||
XCTAssertEqual(pool.our_descriptors.count, 0)
|
||||
XCTAssertEqual(pool.all_descriptors.count, 1)
|
||||
|
||||
Reference in New Issue
Block a user