Fix a TODO in NodeWalletService by utilising ServiceHub.recordTransactions

This commit is contained in:
Mike Hearn 2016-04-19 18:08:36 +02:00
parent bfa5e2091c
commit 6968a47a63
3 changed files with 13 additions and 11 deletions

View File

@ -139,7 +139,7 @@ class NodeWalletService(private val services: ServiceHub) : WalletService {
* TODO: Move this out of NodeWalletService
*/
fun fillWithSomeTestCash(howMuch: Amount, atLeastThisManyStates: Int = 3, atMostThisManyStates: Int = 10,
rng: Random = Random()): Wallet {
rng: Random = Random()) {
val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng)
val myIdentity = services.storageService.myLegalIdentity
@ -160,10 +160,7 @@ class NodeWalletService(private val services: ServiceHub) : WalletService {
return@map issuance.toSignedTransaction(true)
}
// TODO: Centralise the process of transaction acceptance and filtering into the wallet, then move this out.
services.storageService.validatedTransactions.putAll(transactions.associateBy { it.id })
return notifyAll(transactions.map { it.tx })
services.recordTransactions(transactions)
}
private fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, rng: Random): LongArray {

View File

@ -91,7 +91,7 @@ class MockAttachmentStorage : AttachmentStorage {
class MockStorageService : StorageServiceImpl(MockAttachmentStorage(), generateKeyPair())
class MockServices(
val wallet: WalletService? = null,
customWallet: WalletService? = null,
val keyManagement: KeyManagementService? = null,
val net: MessagingService? = null,
val identity: IdentityService? = MockIdentityService,
@ -99,8 +99,8 @@ class MockServices(
val networkMap: NetworkMapCache? = MockNetworkMapCache(),
val overrideClock: Clock? = Clock.systemUTC()
) : ServiceHub {
override val walletService: WalletService
get() = wallet ?: throw UnsupportedOperationException()
override val walletService: WalletService = customWallet ?: NodeWalletService(this)
override val keyManagementService: KeyManagementService
get() = keyManagement ?: throw UnsupportedOperationException()
override val identityService: IdentityService

View File

@ -15,7 +15,6 @@ import kotlin.test.assertNull
class NodeWalletServiceTest {
val kms = MockKeyManagementService(ALICE_KEY)
val services: ServiceHub = MockServices(keyManagement = kms)
@Before
fun setUp() {
@ -27,9 +26,15 @@ class NodeWalletServiceTest {
BriefLogFormatter.loggingOff(NodeWalletService::class)
}
fun make(): Pair<NodeWalletService, ServiceHub> {
val services = MockServices(keyManagement = kms)
return Pair(services.walletService as NodeWalletService, services)
}
@Test
fun splits() {
val wallet = NodeWalletService(services)
val (wallet, services) = make()
kms.nextKeys += Array(3) { ALICE_KEY }
// Fix the PRNG so that we get the same splits every time.
wallet.fillWithSomeTestCash(100.DOLLARS, 3, 3, Random(0L))
@ -49,7 +54,7 @@ class NodeWalletServiceTest {
@Test
fun basics() {
val wallet = NodeWalletService(services)
val (wallet, services) = make()
// A tx that sends us money.
val freshKey = services.keyManagementService.freshKey()