fix tests

This commit is contained in:
Francisco Gindre 2020-12-14 18:55:51 -03:00
parent ce67fa7636
commit aad4710608
3 changed files with 36 additions and 6 deletions

View File

@ -0,0 +1,30 @@
//
// ZcashSDK+extensions.swift
// ZcashLightClientKit
//
// Created by Francisco Gindre on 12/8/20.
//
import Foundation
/**
Ideally this extension shouldn't exist. Fees should be calculated from inputs and outputs. "Perfect is the enemy of good"
*/
public extension ZcashSDK {
/**
Returns the default fee at the time of that blockheight.
*/
func defaultFee(for height: BlockHeight) -> Int64 {
guard height >= feeChangeHeight else { return 10_000 }
return 1_000
}
/**
Estimated height where wallets are supposed to change the fee
*/
private var feeChangeHeight: BlockHeight {
ZcashSDK.isMainnet ? 1_046_400 : 1_028_500
}
}

View File

@ -11,7 +11,7 @@ import Foundation
public class ZcashSDK {
/**
Miner's fee in zatoshi.
DEPRECATED. Miner's fee in zatoshi.
*/
public static let MINERS_FEE_ZATOSHI: BlockHeight = 10_000

View File

@ -354,7 +354,7 @@ class AdvancedReOrgTests: XCTestCase {
8. stage sentTx and otherTx at sentTxheight
*/
try coordinator.stageBlockCreate(height: sentTxHeight, count: 20, nonce: 5)
try coordinator.stageTransaction(url: FakeChainBuilder.someOtherTxUrl, at: receivedTxHeight)
try coordinator.stageTransaction(url: FakeChainBuilder.someOtherTxUrl, at: sentTxHeight)
try coordinator.stageTransaction(sentTx, at: sentTxHeight)
/*
@ -370,7 +370,7 @@ class AdvancedReOrgTests: XCTestCase {
*/
let pMinedHeight = s.pendingTransactions.first?.minedHeight
XCTAssertEqual(pMinedHeight, sentTxHeight)
XCTAssertEqual(initialTotalBalance - sendAmount - Int64(ZcashSDK.MINERS_FEE_ZATOSHI), s.initializer.getBalance())
XCTAssertEqual(initialTotalBalance - sendAmount - Int64(1000), s.initializer.getBalance()) // fee change on this branch
afterReOrgExpectation.fulfill()
}, error: self.handleError)
@ -396,7 +396,7 @@ class AdvancedReOrgTests: XCTestCase {
wait(for: [lastSyncExpectation], timeout: 5)
XCTAssertEqual(coordinator.synchronizer.pendingTransactions.count, 0)
XCTAssertEqual(initialTotalBalance - Int64(pendingTx.value) - Int64(ZcashSDK.MINERS_FEE_ZATOSHI), coordinator.synchronizer.initializer.getVerifiedBalance())
XCTAssertEqual(initialTotalBalance - Int64(pendingTx.value) - Int64(1000), coordinator.synchronizer.initializer.getVerifiedBalance())
XCTAssertEqual(coordinator.synchronizer.initializer.getBalance(), coordinator.synchronizer.initializer.getVerifiedBalance())
}
@ -860,8 +860,8 @@ class AdvancedReOrgTests: XCTestCase {
return txId == newlyPendingTx.rawTransactionId
}), "Sent Tx is not on sent transactions")
XCTAssertEqual(initialTotalBalance - Int64(newlyPendingTx.value) - Int64(ZcashSDK.MINERS_FEE_ZATOSHI), coordinator.synchronizer.initializer.getBalance())
XCTAssertEqual(initialTotalBalance - Int64(newlyPendingTx.value) - Int64(ZcashSDK.MINERS_FEE_ZATOSHI), coordinator.synchronizer.initializer.getVerifiedBalance())
XCTAssertEqual(initialTotalBalance - Int64(newlyPendingTx.value) - Int64(1000), coordinator.synchronizer.initializer.getBalance())
XCTAssertEqual(initialTotalBalance - Int64(newlyPendingTx.value) - Int64(1000), coordinator.synchronizer.initializer.getVerifiedBalance())
}