mirror of
https://github.com/corda/corda.git
synced 2024-12-24 07:06:44 +00:00
Minor: Replace MockServices with a new class that's in core instead of node, old class becomes MockServiceHubInternal.
This commit is contained in:
parent
301d787e45
commit
c2aee2d4e8
@ -34,7 +34,7 @@ import javax.annotation.concurrent.ThreadSafe
|
|||||||
* A singleton utility that only provides a mock identity, key and storage service. However, this is sufficient for
|
* A singleton utility that only provides a mock identity, key and storage service. However, this is sufficient for
|
||||||
* building chains of transactions and verifying them. It isn't sufficient for testing protocols however.
|
* building chains of transactions and verifying them. It isn't sufficient for testing protocols however.
|
||||||
*/
|
*/
|
||||||
open class UnitTestServices(val key: KeyPair = generateKeyPair()) : ServiceHub {
|
open class MockServices(val key: KeyPair = generateKeyPair()) : ServiceHub {
|
||||||
override fun <T : Any> invokeProtocolAsync(logicType: Class<out ProtocolLogic<T>>, vararg args: Any?): ListenableFuture<T> {
|
override fun <T : Any> invokeProtocolAsync(logicType: Class<out ProtocolLogic<T>>, vararg args: Any?): ListenableFuture<T> {
|
||||||
throw UnsupportedOperationException("not implemented")
|
throw UnsupportedOperationException("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import com.r3corda.core.contracts.TransactionBuilder
|
|||||||
import com.r3corda.core.crypto.*
|
import com.r3corda.core.crypto.*
|
||||||
import com.r3corda.core.node.ServiceHub
|
import com.r3corda.core.node.ServiceHub
|
||||||
import com.r3corda.core.node.services.testing.MockIdentityService
|
import com.r3corda.core.node.services.testing.MockIdentityService
|
||||||
import com.r3corda.core.node.services.testing.UnitTestServices
|
import com.r3corda.core.node.services.testing.MockServices
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
import java.security.KeyPair
|
import java.security.KeyPair
|
||||||
@ -94,10 +94,10 @@ fun freeLocalHostAndPort(): HostAndPort {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and tests a ledger built by the passed in dsl. The provided services can be customised, otherwise a default
|
* Creates and tests a ledger built by the passed in dsl. The provided services can be customised, otherwise a default
|
||||||
* of a freshly built [UnitTestServices] is used.
|
* of a freshly built [MockServices] is used.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads fun ledger(
|
@JvmOverloads fun ledger(
|
||||||
services: ServiceHub = UnitTestServices(),
|
services: ServiceHub = MockServices(),
|
||||||
dsl: LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter>.() -> Unit
|
dsl: LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter>.() -> Unit
|
||||||
): LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter> {
|
): LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter> {
|
||||||
val ledgerDsl = LedgerDSL(TestLedgerDSLInterpreter(services))
|
val ledgerDsl = LedgerDSL(TestLedgerDSLInterpreter(services))
|
||||||
|
@ -4,7 +4,6 @@ import com.r3corda.core.contracts.*
|
|||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
import com.r3corda.core.days
|
import com.r3corda.core.days
|
||||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
@ -112,7 +111,7 @@ class BillOfLadingAgreement : Contract {
|
|||||||
/**
|
/**
|
||||||
* Returns a transaction that issues a Bill of Lading Agreement
|
* Returns a transaction that issues a Bill of Lading Agreement
|
||||||
*/
|
*/
|
||||||
fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party = DUMMY_NOTARY): TransactionBuilder {
|
fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party): TransactionBuilder {
|
||||||
val state = State(owner, beneficiary, props)
|
val state = State(owner, beneficiary, props)
|
||||||
val builder = TransactionType.General.Builder(notary = notary)
|
val builder = TransactionType.General.Builder(notary = notary)
|
||||||
builder.setTime(Instant.now(), notary, 1.days)
|
builder.setTime(Instant.now(), notary, 1.days)
|
||||||
|
@ -48,7 +48,7 @@ class BillOfLadingAgreementTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun issueGenerationMethod() {
|
fun issueGenerationMethod() {
|
||||||
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary,Bill.props).apply {
|
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY).apply {
|
||||||
signWith(ALICE_KEY)
|
signWith(ALICE_KEY)
|
||||||
signWith(DUMMY_NOTARY_KEY)
|
signWith(DUMMY_NOTARY_KEY)
|
||||||
}
|
}
|
||||||
@ -58,14 +58,14 @@ class BillOfLadingAgreementTests {
|
|||||||
|
|
||||||
@Test(expected = IllegalStateException::class)
|
@Test(expected = IllegalStateException::class)
|
||||||
fun issueGenerationMethod_Unsigned() {
|
fun issueGenerationMethod_Unsigned() {
|
||||||
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props)
|
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY)
|
||||||
val stx = ptx.toSignedTransaction()
|
val stx = ptx.toSignedTransaction()
|
||||||
stx.verifyToLedgerTransaction(MOCK_IDENTITY_SERVICE,attachments)
|
stx.verifyToLedgerTransaction(MOCK_IDENTITY_SERVICE,attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException::class)
|
@Test(expected = IllegalStateException::class)
|
||||||
fun issueGenerationMethod_KeyMismatch() {
|
fun issueGenerationMethod_KeyMismatch() {
|
||||||
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props).apply {
|
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY).apply {
|
||||||
signWith(BOB_KEY)
|
signWith(BOB_KEY)
|
||||||
}
|
}
|
||||||
val stx = ptx.toSignedTransaction()
|
val stx = ptx.toSignedTransaction()
|
||||||
|
@ -19,7 +19,7 @@ import com.r3corda.node.services.statemachine.StateMachineManager
|
|||||||
import com.r3corda.node.services.wallet.NodeWalletService
|
import com.r3corda.node.services.wallet.NodeWalletService
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
|
|
||||||
open class MockServices(
|
open class MockServiceHubInternal(
|
||||||
customWallet: WalletService? = null,
|
customWallet: WalletService? = null,
|
||||||
val keyManagement: KeyManagementService? = null,
|
val keyManagement: KeyManagementService? = null,
|
||||||
val net: MessagingServiceInternal? = null,
|
val net: MessagingServiceInternal? = null,
|
@ -60,7 +60,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() {
|
|||||||
init {
|
init {
|
||||||
val kms = MockKeyManagementService(ALICE_KEY)
|
val kms = MockKeyManagementService(ALICE_KEY)
|
||||||
val mockMessagingService = InMemoryMessagingNetwork(false).InMemoryMessaging(false, InMemoryMessagingNetwork.Handle(0, "None"))
|
val mockMessagingService = InMemoryMessagingNetwork(false).InMemoryMessaging(false, InMemoryMessagingNetwork.Handle(0, "None"))
|
||||||
val mockServices = object : MockServices(overrideClock = testClock, keyManagement = kms, net = mockMessagingService), TestReference {
|
val mockServices = object : MockServiceHubInternal(overrideClock = testClock, keyManagement = kms, net = mockMessagingService), TestReference {
|
||||||
override val testReference = this@NodeSchedulerServiceTest
|
override val testReference = this@NodeSchedulerServiceTest
|
||||||
}
|
}
|
||||||
services = mockServices
|
services = mockServices
|
||||||
|
@ -8,7 +8,7 @@ import com.r3corda.core.contracts.*
|
|||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
import com.r3corda.core.node.services.WalletService
|
import com.r3corda.core.node.services.WalletService
|
||||||
import com.r3corda.core.node.services.testing.MockStorageService
|
import com.r3corda.core.node.services.testing.MockStorageService
|
||||||
import com.r3corda.core.node.services.testing.UnitTestServices
|
import com.r3corda.core.node.services.testing.MockServices
|
||||||
import com.r3corda.core.testing.*
|
import com.r3corda.core.testing.*
|
||||||
import com.r3corda.core.utilities.BriefLogFormatter
|
import com.r3corda.core.utilities.BriefLogFormatter
|
||||||
import com.r3corda.node.services.wallet.NodeWalletService
|
import com.r3corda.node.services.wallet.NodeWalletService
|
||||||
@ -23,13 +23,13 @@ import kotlin.test.assertNull
|
|||||||
// TODO: Move this to the cash contract tests once mock services are further split up.
|
// TODO: Move this to the cash contract tests once mock services are further split up.
|
||||||
|
|
||||||
class WalletWithCashTest {
|
class WalletWithCashTest {
|
||||||
lateinit var services: UnitTestServices
|
lateinit var services: MockServices
|
||||||
val wallet: WalletService get() = services.walletService
|
val wallet: WalletService get() = services.walletService
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
BriefLogFormatter.loggingOn(NodeWalletService::class)
|
BriefLogFormatter.loggingOn(NodeWalletService::class)
|
||||||
services = object : UnitTestServices() {
|
services = object : MockServices() {
|
||||||
override val walletService: WalletService = NodeWalletService(this)
|
override val walletService: WalletService = NodeWalletService(this)
|
||||||
|
|
||||||
override fun recordTransactions(txs: Iterable<SignedTransaction>) {
|
override fun recordTransactions(txs: Iterable<SignedTransaction>) {
|
||||||
|
@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Fiber
|
|||||||
import co.paralleluniverse.fibers.Suspendable
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
import com.r3corda.core.messaging.MessagingService
|
import com.r3corda.core.messaging.MessagingService
|
||||||
import com.r3corda.core.protocols.ProtocolLogic
|
import com.r3corda.core.protocols.ProtocolLogic
|
||||||
import com.r3corda.node.services.MockServices
|
import com.r3corda.node.services.MockServiceHubInternal
|
||||||
import com.r3corda.node.services.api.Checkpoint
|
import com.r3corda.node.services.api.Checkpoint
|
||||||
import com.r3corda.node.services.api.CheckpointStorage
|
import com.r3corda.node.services.api.CheckpointStorage
|
||||||
import com.r3corda.node.services.api.MessagingServiceInternal
|
import com.r3corda.node.services.api.MessagingServiceInternal
|
||||||
@ -45,7 +45,7 @@ class StateMachineManagerTests {
|
|||||||
assertThat(protocol.lazyTime).isNotNull()
|
assertThat(protocol.lazyTime).isNotNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createManager() = StateMachineManager(object : MockServices() {
|
private fun createManager() = StateMachineManager(object : MockServiceHubInternal() {
|
||||||
override val networkService: MessagingServiceInternal get() = network
|
override val networkService: MessagingServiceInternal get() = network
|
||||||
}, emptyList(), checkpointStorage, AffinityExecutor.SAME_THREAD)
|
}, emptyList(), checkpointStorage, AffinityExecutor.SAME_THREAD)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user