Fixes issue 136 - expiry height -1 on pending transactions (#139)
This commit is contained in:
parent
f8f8be30a4
commit
3f130ebebf
|
@ -45,11 +45,14 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
|||
guard let self = self else { return }
|
||||
do {
|
||||
let encodedTransaction = try self.encoder.createTransaction(spendingKey: spendingKey, zatoshi: pendingTransaction.value, to: pendingTransaction.toAddress, memo: pendingTransaction.memo?.asZcashTransactionMemo(), from: pendingTransaction.accountIndex)
|
||||
let transaction = try self.encoder.expandEncodedTransaction(encodedTransaction)
|
||||
|
||||
var pending = pendingTransaction
|
||||
pending.encodeAttempts = pending.encodeAttempts + 1
|
||||
pending.raw = encodedTransaction.raw
|
||||
pending.rawTransactionId = encodedTransaction.transactionId
|
||||
|
||||
pending.expiryHeight = transaction.expiryHeight ?? BlockHeight.empty()
|
||||
pending.minedHeight = transaction.minedHeight ?? BlockHeight.empty()
|
||||
try self.repository.update(pending)
|
||||
result(.success(pending))
|
||||
} catch StorageError.updateFailed {
|
||||
|
|
|
@ -14,6 +14,7 @@ public enum TransactionEncoderError: Error {
|
|||
case NotEncoded(transactionId: Int)
|
||||
case missingParams
|
||||
case spendingKeyWrongNetwork
|
||||
case couldNotExpand(txId: Data)
|
||||
}
|
||||
|
||||
protocol TransactionEncoder {
|
||||
|
@ -51,4 +52,11 @@ protocol TransactionEncoder {
|
|||
*/
|
||||
func createTransaction(spendingKey: String, zatoshi: Int, to: String, memo: String?, from accountIndex: Int, result: @escaping TransactionEncoderResultBlock)
|
||||
|
||||
/**
|
||||
Fetch the Transaction Entity from the encoded representation
|
||||
- Parameter encodedTransaction: The encoded transaction to expand
|
||||
- Returns: a TransactionEntity based on the given Encoded Transaction
|
||||
- Throws: a TransactionEncoderError
|
||||
*/
|
||||
func expandEncodedTransaction(_ encodedTransaction: EncodedTransaction) throws -> TransactionEntity
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|||
|
||||
var rustBackend: ZcashRustBackendWelding.Type
|
||||
var repository: TransactionRepository
|
||||
// var initializer: Initializer
|
||||
var queue: DispatchQueue
|
||||
private var outputParamsURL: URL
|
||||
private var spendParamsURL: URL
|
||||
|
@ -92,4 +91,17 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|||
|
||||
return readableSpend && readableOutput // Todo: change this to something that makes sense
|
||||
}
|
||||
|
||||
/**
|
||||
Fetch the Transaction Entity from the encoded representation
|
||||
- Parameter encodedTransaction: The encoded transaction to expand
|
||||
- Returns: a TransactionEntity based on the given Encoded Transaction
|
||||
- Throws: a TransactionEncoderError
|
||||
*/
|
||||
func expandEncodedTransaction(_ encodedTransaction: EncodedTransaction) throws -> TransactionEntity {
|
||||
guard let t = try? repository.findBy(rawId: encodedTransaction.transactionId) else {
|
||||
throw TransactionEncoderError.couldNotExpand(txId: encodedTransaction.transactionId)
|
||||
}
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
|
|
@ -545,40 +545,43 @@ class BalanceTests: XCTestCase {
|
|||
let expiryHeight = pendingTransaction.expiryHeight
|
||||
let blockCount = abs(self.defaultLatestHeight - expiryHeight)
|
||||
try coordinator.stageBlockCreate(height: self.defaultLatestHeight + 1, count: blockCount)
|
||||
try coordinator.applyStaged(blockheight: expiryHeight)
|
||||
try coordinator.applyStaged(blockheight: expiryHeight + 1)
|
||||
|
||||
sleep(2)
|
||||
try coordinator.sync(completion: { (synchronizer) in
|
||||
expirationSyncExpectation.fulfill()
|
||||
}, error: self.handleError)
|
||||
|
||||
wait(for: [expirationSyncExpectation], timeout: 5)
|
||||
|
||||
/*
|
||||
Verified Balance is equal to verified balance previously shown before sending the expired transaction
|
||||
*/
|
||||
XCTAssertEqual(synchronizer.initializer.getVerifiedBalance(), previousVerifiedBalance)
|
||||
XCTAssertEqual(coordinator.synchronizer.initializer.getVerifiedBalance(), previousVerifiedBalance)
|
||||
|
||||
/*
|
||||
Total Balance is equal to total balance previously shown before sending the expired transaction
|
||||
*/
|
||||
XCTAssertEqual(synchronizer.initializer.getBalance(), previousTotalBalance)
|
||||
XCTAssertEqual(coordinator.synchronizer.initializer.getBalance(), previousTotalBalance)
|
||||
|
||||
let pendingRepo = PendingTransactionSQLDAO(dbProvider: SimpleConnectionProvider(path: synchronizer.initializer.pendingDbURL.absoluteString))
|
||||
let pendingRepo = PendingTransactionSQLDAO(dbProvider: SimpleConnectionProvider(path: coordinator.synchronizer.initializer.pendingDbURL.absoluteString))
|
||||
|
||||
guard let expiredPending = try? pendingRepo.find(by: pendingTransaction.id!),
|
||||
let id = expiredPending.id,
|
||||
let sentExpired = try? synchronizer.allSentTransactions().first(where: { $0.id == id}) else {
|
||||
XCTFail("expired transaction not found")
|
||||
let id = expiredPending.id else {
|
||||
XCTFail("pending transaction not found")
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
there no sent transaction displayed
|
||||
*/
|
||||
|
||||
XCTAssertNil( try coordinator.synchronizer.allSentTransactions().first(where: { $0.id == id}))
|
||||
/*
|
||||
There’s a pending transaction that has expired
|
||||
*/
|
||||
XCTAssertEqual(expiredPending.minedHeight, -1)
|
||||
XCTAssertEqual(sentExpired.expiryHeight,expiryHeight)
|
||||
XCTAssertEqual(Int64(sentExpired.value), self.sendAmount)
|
||||
|
||||
expirationSyncExpectation.fulfill()
|
||||
}, error: self.handleError)
|
||||
|
||||
wait(for: [expirationSyncExpectation], timeout: 10)
|
||||
}
|
||||
|
||||
func handleError(_ error: Error?) {
|
||||
|
|
Loading…
Reference in New Issue