Received Notes and Sent Notes repository + tests (#31)
This commit is contained in:
parent
2a80d705aa
commit
908d8ac823
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// NotesRepositoryTests.swift
|
||||
// ZcashLightClientKit-Unit-Tests
|
||||
//
|
||||
// Created by Francisco Gindre on 11/18/19.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
class NotesRepositoryTests: XCTestCase {
|
||||
|
||||
var sentNotesRepository: SentNotesRepository!
|
||||
var receivedNotesRepository: ReceivedNoteRepository!
|
||||
override func setUp() {
|
||||
sentNotesRepository = TestDbBuilder.sentNotesRepository()
|
||||
receivedNotesRepository = TestDbBuilder.receivedNotesRepository()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
sentNotesRepository = nil
|
||||
receivedNotesRepository = nil
|
||||
}
|
||||
|
||||
func testSentCount() {
|
||||
var count: Int?
|
||||
XCTAssertNoThrow(try { count = try sentNotesRepository.count() }())
|
||||
XCTAssertEqual(count, 0)
|
||||
}
|
||||
|
||||
func testReceivedCount() {
|
||||
var count: Int?
|
||||
XCTAssertNoThrow(try { count = try receivedNotesRepository.count() }())
|
||||
XCTAssertEqual(count, 27)
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// NotesDao.swift
|
||||
// ZcashLightClientKit
|
||||
//
|
||||
// Created by Francisco Gindre on 11/18/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SQLite
|
||||
|
||||
struct ReceivedNote: ReceivedNoteEntity {
|
||||
var id: Int
|
||||
var spent: Int?
|
||||
var diverifier: Data
|
||||
var rcm: Data
|
||||
var nf: Data
|
||||
var isChange: Bool
|
||||
var transactionId: Int
|
||||
var outputIndex: Int
|
||||
var account: Int
|
||||
var address: String
|
||||
var value: Int
|
||||
var memo: Data?
|
||||
}
|
||||
|
||||
class ReceivedNotesSQLDAO: ReceivedNoteRepository {
|
||||
var dbProvider: ConnectionProvider
|
||||
|
||||
let table = Table("received_notes")
|
||||
|
||||
init(dbProvider: ConnectionProvider) {
|
||||
self.dbProvider = dbProvider
|
||||
}
|
||||
|
||||
func count() throws -> Int {
|
||||
try dbProvider.connection().scalar(table.count)
|
||||
}
|
||||
}
|
||||
|
||||
struct SentNote: SentNoteEntity {
|
||||
var id: Int
|
||||
var transactionId: Int
|
||||
var outputIndex: Int
|
||||
var account: Int
|
||||
var address: String
|
||||
var value: Int
|
||||
var memo: Data?
|
||||
}
|
||||
|
||||
class SentNotesSQLDAO: SentNotesRepository {
|
||||
var dbProvider: ConnectionProvider
|
||||
let table = Table("sent_notes")
|
||||
|
||||
init(dbProvider: ConnectionProvider) {
|
||||
self.dbProvider = dbProvider
|
||||
}
|
||||
|
||||
func count() throws -> Int {
|
||||
try dbProvider.connection().scalar(table.count)
|
||||
}
|
||||
}
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
protocol SentNoteEntity: Identifiable, Hashable {
|
||||
protocol SentNoteEntity: Hashable {
|
||||
var id: Int { get set }
|
||||
var transactionId: Int { get set }
|
||||
var outputIndex: Int { get set }
|
||||
var account: Int { get set }
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// NotesRepository.swift
|
||||
// ZcashLightClientKit
|
||||
//
|
||||
// Created by Francisco Gindre on 11/18/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol ReceivedNoteRepository {
|
||||
func count() throws -> Int
|
||||
}
|
||||
|
||||
protocol SentNotesRepository {
|
||||
func count() throws -> Int
|
||||
}
|
|
@ -40,6 +40,16 @@ class TestDbBuilder {
|
|||
|
||||
return TransactionSQLDAO(dbProvider: provider)
|
||||
}
|
||||
|
||||
static func sentNotesRepository() -> SentNotesRepository? {
|
||||
guard let provider = prepopulatedDataDbProvider() else { return nil }
|
||||
return SentNotesSQLDAO(dbProvider: provider)
|
||||
}
|
||||
|
||||
static func receivedNotesRepository() -> ReceivedNoteRepository? {
|
||||
guard let provider = prepopulatedDataDbProvider() else { return nil }
|
||||
return ReceivedNotesSQLDAO(dbProvider: provider)
|
||||
}
|
||||
|
||||
static func seed(db: CompactBlockRepository, with blockRange: CompactBlockRange) throws {
|
||||
|
||||
|
|
Loading…
Reference in New Issue