mirror of
https://github.com/corda/corda.git
synced 2025-01-04 12:14:17 +00:00
Minor: small cleanup in TwoPartyTradeProtocolTests, by using ServiceHub to record the fake transactions
This commit is contained in:
parent
70210f3ef9
commit
964f2b502e
@ -5,6 +5,7 @@ import contracts.Cash
|
|||||||
import core.*
|
import core.*
|
||||||
import core.crypto.SecureHash
|
import core.crypto.SecureHash
|
||||||
import core.messaging.MessagingService
|
import core.messaging.MessagingService
|
||||||
|
import core.utilities.RecordingMap
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.security.KeyPair
|
import java.security.KeyPair
|
||||||
import java.security.PrivateKey
|
import java.security.PrivateKey
|
||||||
@ -176,12 +177,21 @@ interface ServiceHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this for storing transactions to StorageService and WalletService
|
* Given a list of [SignedTransaction]s, writes them to the local storage for validated transactions and then
|
||||||
|
* sends them to the wallet for further processing.
|
||||||
*
|
*
|
||||||
* TODO Need to come up with a way for preventing transactions being written other than by this method
|
* TODO: Need to come up with a way for preventing transactions being written other than by this method
|
||||||
|
*
|
||||||
|
* @param txs The transactions to record
|
||||||
|
* @param skipRecordingMap This is used in unit testing and can be ignored most of the time.
|
||||||
*/
|
*/
|
||||||
fun recordTransactions(txs: List<SignedTransaction>) {
|
fun recordTransactions(txs: List<SignedTransaction>, skipRecordingMap: Boolean = false) {
|
||||||
storageService.validatedTransactions.putAll(txs.groupBy { it.id }.mapValues { it.value.first() })
|
val txns: Map<SecureHash, SignedTransaction> = txs.groupBy { it.id }.mapValues { it.value.first() }
|
||||||
|
val txStorage = storageService.validatedTransactions
|
||||||
|
if (txStorage is RecordingMap && skipRecordingMap)
|
||||||
|
txStorage.putAllUnrecorded(txns)
|
||||||
|
else
|
||||||
|
txStorage.putAll(txns)
|
||||||
walletService.notifyAll(txs.map { it.tx })
|
walletService.notifyAll(txs.map { it.tx })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,20 +356,9 @@ class TwoPartyTradeProtocolTests : TestWithInMemoryNetwork() {
|
|||||||
private fun TransactionGroupDSL<ContractState>.insertFakeTransactions(wtxToSign: List<WireTransaction>,
|
private fun TransactionGroupDSL<ContractState>.insertFakeTransactions(wtxToSign: List<WireTransaction>,
|
||||||
services: ServiceHub,
|
services: ServiceHub,
|
||||||
vararg extraKeys: KeyPair): Map<SecureHash, SignedTransaction> {
|
vararg extraKeys: KeyPair): Map<SecureHash, SignedTransaction> {
|
||||||
val txStorage = services.storageService.validatedTransactions
|
val signed: List<SignedTransaction> = signAll(wtxToSign, *extraKeys)
|
||||||
val signed = signAll(wtxToSign, *extraKeys).associateBy { it.id }
|
services.recordTransactions(signed, skipRecordingMap = true)
|
||||||
if (txStorage is RecordingMap) {
|
return signed.associateBy { it.id }
|
||||||
txStorage.putAllUnrecorded(signed)
|
|
||||||
} else
|
|
||||||
txStorage.putAll(signed)
|
|
||||||
|
|
||||||
try {
|
|
||||||
services.walletService.notifyAll(signed.map { it.value.tx })
|
|
||||||
} catch(e: Throwable) {
|
|
||||||
// TODO: Remove this hack once all the tests are converted to use MockNode.
|
|
||||||
}
|
|
||||||
|
|
||||||
return signed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TransactionGroupDSL<ContractState>.fillUpForBuyer(withError: Boolean, bobKey: PublicKey = BOB): Pair<Wallet, List<WireTransaction>> {
|
private fun TransactionGroupDSL<ContractState>.fillUpForBuyer(withError: Boolean, bobKey: PublicKey = BOB): Pair<Wallet, List<WireTransaction>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user