DMTests.swift (5137B)
1 // 2 // DMTests.swift 3 // damusTests 4 // 5 // Created by William Casarin on 2023-01-14. 6 // 7 8 import XCTest 9 @testable import damus 10 11 final class DMTests: XCTestCase { 12 13 var alice: Keypair { 14 let sec = hex_decode_privkey("494c680d20f202807a116a6915815bd76a27d62802e7585806f6a2e034cb5cdb")! 15 let pk = hex_decode_pubkey("22d925632551a3299022e98de7f9c1087f79a21209f3413ec24ec219b08bd1e4")! 16 return Keypair(pubkey: pk, privkey: sec) 17 } 18 19 var bob: Keypair { 20 let sec = hex_decode_privkey("aa8920b05b4bd5c79fce46868ed5ebc82bdb91b211850b14541bfbd13953cfef")! 21 let pk = hex_decode_pubkey("5a9a277dca94260688ecf7d63053de8c121b7f01f609d7f84a1eb9cff64e4606")! 22 return Keypair(pubkey: pk, privkey: sec) 23 } 24 25 var charlie: Keypair { 26 let sec = hex_decode_privkey("4c79130952c9c3b017dad62f37f285853a9c53f2a1184d94594f5b860f30b5a5")! 27 let pk = hex_decode_pubkey("51c0d263fbfc4bf850805dccf9a29125071e6fed9619bff3efa9a6b5bbcc54a7")! 28 return Keypair(pubkey: pk, privkey: sec) 29 } 30 31 var dave: Keypair { 32 let sec = hex_decode_privkey("630ffd518084334cbb9ecb20d9532ce0658b8123f4ba565c236d0cea9a4a2cfe")! 33 let pk = hex_decode_pubkey("b42e44b555013239a0d5dcdb09ebde0857cd8a5a57efbba5a2b6ac78833cb9f0")! 34 return Keypair(pubkey: pk, privkey: sec) 35 } 36 37 var fiatjaf: Keypair { 38 let sec = hex_decode_privkey("5426893eab32191ec17a83a583d5c8f85adaabcab0fa56af277ea0b61f575599")! 39 let pub = hex_decode_pubkey("e27258d7be6d84038967334bfd0954f05801b1bcd85b2afa4c03cfd16ae4b0ad")! 40 return Keypair(pubkey: pub, privkey: sec) 41 } 42 43 /* 44 func testDMSortOrder() throws { 45 let notif = NewEventsBits() 46 let pubkey = hex_decode_pubkey("3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681")! 47 let model = DirectMessagesModel(our_pubkey: pubkey) 48 49 let now = UInt32(Date().timeIntervalSince1970) 50 51 let alice_to_bob = create_dm("hi bob", to_pk: bob.pubkey, tags: [bob.pubkey.tag], keypair: alice, created_at: now)! 52 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [alice_to_bob]) 53 54 XCTAssertEqual(model.dms.count, 1) 55 XCTAssertEqual(model.dms[0].pubkey, bob.pubkey) 56 57 let bob_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: bob, created_at: now + 1)! 58 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice]) 59 60 XCTAssertEqual(model.dms.count, 1) 61 XCTAssertEqual(model.dms[0].pubkey, bob.pubkey) 62 63 let alice_to_bob_2 = create_dm("hi bob", to_pk: bob.pubkey, tags: [bob.pubkey.tag], keypair: alice, created_at: now + 2)! 64 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [alice_to_bob_2]) 65 66 XCTAssertEqual(model.dms.count, 1) 67 XCTAssertEqual(model.dms[0].pubkey, bob.pubkey) 68 69 let fiatjaf_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: fiatjaf, created_at: now+5)! 70 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [fiatjaf_to_alice]) 71 72 XCTAssertEqual(model.dms.count, 2) 73 XCTAssertEqual(model.dms[0].pubkey, fiatjaf.pubkey) 74 75 let dave_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: dave, created_at: now + 10)! 76 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [dave_to_alice]) 77 78 XCTAssertEqual(model.dms.count, 3) 79 XCTAssertEqual(model.dms[0].pubkey, dave.pubkey) 80 81 let bob_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: bob, created_at: now + 15)! 82 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice_2]) 83 84 XCTAssertEqual(model.dms.count, 3) 85 XCTAssertEqual(model.dms[0].pubkey, bob.pubkey) 86 87 let charlie_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: charlie, created_at: now + 20)! 88 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [charlie_to_alice]) 89 90 XCTAssertEqual(model.dms.count, 4) 91 XCTAssertEqual(model.dms[0].pubkey, charlie.pubkey) 92 93 let bob_to_alice_3 = create_dm("hi alice 3", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: bob, created_at: now + 25)! 94 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice_3]) 95 96 XCTAssertEqual(model.dms.count, 4) 97 XCTAssertEqual(model.dms[0].pubkey, bob.pubkey) 98 99 let charlie_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [alice.pubkey.tag], keypair: charlie, created_at: now + 30)! 100 handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [charlie_to_alice_2]) 101 102 XCTAssertEqual(model.dms.count, 4) 103 XCTAssertEqual(model.dms[0].pubkey, charlie.pubkey) 104 } 105 */ 106 107 }