Improve mocks generating

This commit is contained in:
Michal Fousek 2023-05-18 13:24:04 +02:00
parent 5f9a430a2f
commit 4dc8d986ef
2 changed files with 21 additions and 21 deletions

View File

@ -84,7 +84,7 @@ import Foundation
{% if method.isStatic %}Self.{% endif %}{% call methodName method %}CallsCount += 1 {% if method.isStatic %}Self.{% endif %}{% call methodName method %}CallsCount += 1
{% call methodReceivedParameters method %} {% call methodReceivedParameters method %}
{% if method.returnTypeName.isVoid %} {% if method.returnTypeName.isVoid %}
{% if method.throws %}try {% endif %}{% if method.isAsync %}await {% endif %}{% call methodClosureName method %}?({% call methodClosureCallParameters method %}) {% if method.throws %}try {% endif %}{% if method.isAsync %}await {% endif %}{% call methodClosureName method %}!({% call methodClosureCallParameters method %})
{% else %} {% else %}
if let closure = {% if method.isStatic %}Self.{% endif %}{% call methodClosureName method %} { if let closure = {% if method.isStatic %}Self.{% endif %}{% call methodClosureName method %} {
return {% if method.throws %}try {% endif %}{% if method.isAsync %}await {% endif %}closure({% call methodClosureCallParameters method %}) return {% if method.throws %}try {% endif %}{% if method.isAsync %}await {% endif %}closure({% call methodClosureCallParameters method %})

View File

@ -60,7 +60,7 @@ class BlockValidatorMock: BlockValidator {
throw error throw error
} }
validateCallsCount += 1 validateCallsCount += 1
try await validateClosure?() try await validateClosure!()
} }
} }
@ -276,7 +276,7 @@ class LightWalletServiceMock: LightWalletService {
func closeConnection() { func closeConnection() {
closeConnectionCallsCount += 1 closeConnectionCallsCount += 1
closeConnectionClosure?() closeConnectionClosure!()
} }
} }
@ -363,7 +363,7 @@ class LoggerMock: Logger {
func debug(_ message: String, file: StaticString, function: StaticString, line: Int) { func debug(_ message: String, file: StaticString, function: StaticString, line: Int) {
debugFileFunctionLineCallsCount += 1 debugFileFunctionLineCallsCount += 1
debugFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line) debugFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line)
debugFileFunctionLineClosure?(message, file, function, line) debugFileFunctionLineClosure!(message, file, function, line)
} }
// MARK: - info // MARK: - info
@ -378,7 +378,7 @@ class LoggerMock: Logger {
func info(_ message: String, file: StaticString, function: StaticString, line: Int) { func info(_ message: String, file: StaticString, function: StaticString, line: Int) {
infoFileFunctionLineCallsCount += 1 infoFileFunctionLineCallsCount += 1
infoFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line) infoFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line)
infoFileFunctionLineClosure?(message, file, function, line) infoFileFunctionLineClosure!(message, file, function, line)
} }
// MARK: - event // MARK: - event
@ -393,7 +393,7 @@ class LoggerMock: Logger {
func event(_ message: String, file: StaticString, function: StaticString, line: Int) { func event(_ message: String, file: StaticString, function: StaticString, line: Int) {
eventFileFunctionLineCallsCount += 1 eventFileFunctionLineCallsCount += 1
eventFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line) eventFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line)
eventFileFunctionLineClosure?(message, file, function, line) eventFileFunctionLineClosure!(message, file, function, line)
} }
// MARK: - warn // MARK: - warn
@ -408,7 +408,7 @@ class LoggerMock: Logger {
func warn(_ message: String, file: StaticString, function: StaticString, line: Int) { func warn(_ message: String, file: StaticString, function: StaticString, line: Int) {
warnFileFunctionLineCallsCount += 1 warnFileFunctionLineCallsCount += 1
warnFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line) warnFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line)
warnFileFunctionLineClosure?(message, file, function, line) warnFileFunctionLineClosure!(message, file, function, line)
} }
// MARK: - error // MARK: - error
@ -423,7 +423,7 @@ class LoggerMock: Logger {
func error(_ message: String, file: StaticString, function: StaticString, line: Int) { func error(_ message: String, file: StaticString, function: StaticString, line: Int) {
errorFileFunctionLineCallsCount += 1 errorFileFunctionLineCallsCount += 1
errorFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line) errorFileFunctionLineReceivedArguments = (message: message, file: file, function: function, line: line)
errorFileFunctionLineClosure?(message, file, function, line) errorFileFunctionLineClosure!(message, file, function, line)
} }
} }
@ -514,7 +514,7 @@ class SynchronizerMock: Synchronizer {
} }
startRetryCallsCount += 1 startRetryCallsCount += 1
startRetryReceivedRetry = retry startRetryReceivedRetry = retry
try await startRetryClosure?(retry) try await startRetryClosure!(retry)
} }
// MARK: - stop // MARK: - stop
@ -527,7 +527,7 @@ class SynchronizerMock: Synchronizer {
func stop() { func stop() {
stopCallsCount += 1 stopCallsCount += 1
stopClosure?() stopClosure!()
} }
// MARK: - getSaplingAddress // MARK: - getSaplingAddress
@ -954,7 +954,7 @@ class TransactionRepositoryMock: TransactionRepository {
func closeDBConnection() { func closeDBConnection() {
closeDBConnectionCallsCount += 1 closeDBConnectionCallsCount += 1
closeDBConnectionClosure?() closeDBConnectionClosure!()
} }
// MARK: - countAll // MARK: - countAll
@ -1454,7 +1454,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
decryptAndStoreTransactionTxBytesMinedHeightCallsCount += 1 decryptAndStoreTransactionTxBytesMinedHeightCallsCount += 1
decryptAndStoreTransactionTxBytesMinedHeightReceivedArguments = (txBytes: txBytes, minedHeight: minedHeight) decryptAndStoreTransactionTxBytesMinedHeightReceivedArguments = (txBytes: txBytes, minedHeight: minedHeight)
try await decryptAndStoreTransactionTxBytesMinedHeightClosure?(txBytes, minedHeight) try await decryptAndStoreTransactionTxBytesMinedHeightClosure!(txBytes, minedHeight)
} }
// MARK: - getBalance // MARK: - getBalance
@ -1696,7 +1696,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
initAccountsTableUfvksCallsCount += 1 initAccountsTableUfvksCallsCount += 1
initAccountsTableUfvksReceivedUfvks = ufvks initAccountsTableUfvksReceivedUfvks = ufvks
try await initAccountsTableUfvksClosure?(ufvks) try await initAccountsTableUfvksClosure!(ufvks)
} }
// MARK: - initDataDb // MARK: - initDataDb
@ -1754,7 +1754,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
initBlocksTableHeightHashTimeSaplingTreeCallsCount += 1 initBlocksTableHeightHashTimeSaplingTreeCallsCount += 1
initBlocksTableHeightHashTimeSaplingTreeReceivedArguments = (height: height, hash: hash, time: time, saplingTree: saplingTree) initBlocksTableHeightHashTimeSaplingTreeReceivedArguments = (height: height, hash: hash, time: time, saplingTree: saplingTree)
try await initBlocksTableHeightHashTimeSaplingTreeClosure?(height, hash, time, saplingTree) try await initBlocksTableHeightHashTimeSaplingTreeClosure!(height, hash, time, saplingTree)
} }
// MARK: - listTransparentReceivers // MARK: - listTransparentReceivers
@ -1878,7 +1878,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
validateCombinedChainLimitCallsCount += 1 validateCombinedChainLimitCallsCount += 1
validateCombinedChainLimitReceivedLimit = limit validateCombinedChainLimitReceivedLimit = limit
try await validateCombinedChainLimitClosure?(limit) try await validateCombinedChainLimitClosure!(limit)
} }
// MARK: - rewindToHeight // MARK: - rewindToHeight
@ -1903,7 +1903,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
rewindToHeightHeightCallsCount += 1 rewindToHeightHeightCallsCount += 1
rewindToHeightHeightReceivedHeight = height rewindToHeightHeightReceivedHeight = height
try await rewindToHeightHeightClosure?(height) try await rewindToHeightHeightClosure!(height)
} }
// MARK: - rewindCacheToHeight // MARK: - rewindCacheToHeight
@ -1928,7 +1928,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
rewindCacheToHeightHeightCallsCount += 1 rewindCacheToHeightHeightCallsCount += 1
rewindCacheToHeightHeightReceivedHeight = height rewindCacheToHeightHeightReceivedHeight = height
try await rewindCacheToHeightHeightClosure?(height) try await rewindCacheToHeightHeightClosure!(height)
} }
// MARK: - scanBlocks // MARK: - scanBlocks
@ -1953,7 +1953,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
scanBlocksLimitCallsCount += 1 scanBlocksLimitCallsCount += 1
scanBlocksLimitReceivedLimit = limit scanBlocksLimitReceivedLimit = limit
try await scanBlocksLimitClosure?(limit) try await scanBlocksLimitClosure!(limit)
} }
// MARK: - putUnspentTransparentOutput // MARK: - putUnspentTransparentOutput
@ -1978,7 +1978,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
putUnspentTransparentOutputTxidIndexScriptValueHeightCallsCount += 1 putUnspentTransparentOutputTxidIndexScriptValueHeightCallsCount += 1
putUnspentTransparentOutputTxidIndexScriptValueHeightReceivedArguments = (txid: txid, index: index, script: script, value: value, height: height) putUnspentTransparentOutputTxidIndexScriptValueHeightReceivedArguments = (txid: txid, index: index, script: script, value: value, height: height)
try await putUnspentTransparentOutputTxidIndexScriptValueHeightClosure?(txid, index, script, value, height) try await putUnspentTransparentOutputTxidIndexScriptValueHeightClosure!(txid, index, script, value, height)
} }
// MARK: - shieldFunds // MARK: - shieldFunds
@ -2041,7 +2041,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
throw error throw error
} }
initBlockMetadataDbCallsCount += 1 initBlockMetadataDbCallsCount += 1
try await initBlockMetadataDbClosure?() try await initBlockMetadataDbClosure!()
} }
// MARK: - writeBlocksMetadata // MARK: - writeBlocksMetadata
@ -2066,7 +2066,7 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
} }
writeBlocksMetadataBlocksCallsCount += 1 writeBlocksMetadataBlocksCallsCount += 1
writeBlocksMetadataBlocksReceivedBlocks = blocks writeBlocksMetadataBlocksReceivedBlocks = blocks
try await writeBlocksMetadataBlocksClosure?(blocks) try await writeBlocksMetadataBlocksClosure!(blocks)
} }
// MARK: - latestCachedBlockHeight // MARK: - latestCachedBlockHeight