mirror of
https://github.com/corda/corda.git
synced 2024-12-30 01:39:04 +00:00
Fix a TODO in NodeWalletService by utilising ServiceHub.recordTransactions
This commit is contained in:
parent
bfa5e2091c
commit
6968a47a63
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user