Minor: small cleanup in TwoPartyTradeProtocolTests, by using ServiceHub to record the fake transactions

This commit is contained in:
Mike Hearn 2016-04-18 17:47:05 +02:00
parent 70210f3ef9
commit 964f2b502e
2 changed files with 17 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import contracts.Cash
import core.*
import core.crypto.SecureHash
import core.messaging.MessagingService
import core.utilities.RecordingMap
import java.io.InputStream
import java.security.KeyPair
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>) {
storageService.validatedTransactions.putAll(txs.groupBy { it.id }.mapValues { it.value.first() })
fun recordTransactions(txs: List<SignedTransaction>, skipRecordingMap: Boolean = false) {
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 })
}
}

View File

@ -356,20 +356,9 @@ class TwoPartyTradeProtocolTests : TestWithInMemoryNetwork() {
private fun TransactionGroupDSL<ContractState>.insertFakeTransactions(wtxToSign: List<WireTransaction>,
services: ServiceHub,
vararg extraKeys: KeyPair): Map<SecureHash, SignedTransaction> {
val txStorage = services.storageService.validatedTransactions
val signed = signAll(wtxToSign, *extraKeys).associateBy { it.id }
if (txStorage is RecordingMap) {
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
val signed: List<SignedTransaction> = signAll(wtxToSign, *extraKeys)
services.recordTransactions(signed, skipRecordingMap = true)
return signed.associateBy { it.id }
}
private fun TransactionGroupDSL<ContractState>.fillUpForBuyer(withError: Boolean, bobKey: PublicKey = BOB): Pair<Wallet, List<WireTransaction>> {