Reducing the size of the CorDapp jars used in tests (#4600)

The helper method enclosedCordapp is a replacement to scanning the current package (which pulls in a lot more into the jar than intended).
This commit is contained in:
Shams Asari 2019-01-21 13:54:26 +00:00 committed by GitHub
parent e5d00cf85e
commit c6a7d14f4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 523 additions and 495 deletions

View File

@ -69,7 +69,7 @@ buildscript {
ext.commons_cli_version = '1.4' ext.commons_cli_version = '1.4'
ext.protonj_version = '0.27.1' // This is now aligned with the Artemis version, but retaining in case we ever need to diverge again for a bug fix. ext.protonj_version = '0.27.1' // This is now aligned with the Artemis version, but retaining in case we ever need to diverge again for a bug fix.
ext.snappy_version = '0.4' ext.snappy_version = '0.4'
ext.class_graph_version = '4.2.12' ext.class_graph_version = '4.6.12'
ext.jcabi_manifests_version = '1.1' ext.jcabi_manifests_version = '1.1'
ext.picocli_version = '3.8.0' ext.picocli_version = '3.8.0'
ext.commons_io_version = '2.6' ext.commons_io_version = '2.6'

View File

@ -14,15 +14,11 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate import net.corda.core.identity.PartyAndCertificate
import net.corda.core.internal.packageName
import net.corda.testing.core.* import net.corda.testing.core.*
import net.corda.testing.internal.matchers.allOf import net.corda.testing.internal.matchers.allOf
import net.corda.testing.internal.matchers.flow.willReturn import net.corda.testing.internal.matchers.flow.willReturn
import net.corda.testing.internal.matchers.hasOnlyEntries import net.corda.testing.internal.matchers.hasOnlyEntries
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.*
import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.internal.startFlow
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.AfterClass import org.junit.AfterClass
import org.junit.Test import org.junit.Test
@ -33,7 +29,7 @@ class SwapIdentitiesFlowTests {
private val mockNet = InternalMockNetwork( private val mockNet = InternalMockNetwork(
networkSendManuallyPumped = false, networkSendManuallyPumped = false,
threadPerNode = true, threadPerNode = true,
cordappsForAllNodes = cordappsForPackages(this::class.packageName) cordappsForAllNodes = listOf(enclosedCordapp())
) )
@AfterClass @AfterClass
@ -166,12 +162,12 @@ class SwapIdentitiesFlowTests {
private fun TestStartedNode.holdsOwningKey() = HoldsOwningKeyMatcher(this) private fun TestStartedNode.holdsOwningKey() = HoldsOwningKeyMatcher(this)
//endregion //endregion
}
@InitiatingFlow @InitiatingFlow
private class SwapIdentitiesInitiator(private val otherSide: Party) : FlowLogic<Map<Party, AnonymousParty>>() { private class SwapIdentitiesInitiator(private val otherSide: Party) : FlowLogic<Map<Party, AnonymousParty>>() {
@Suspendable @Suspendable
override fun call(): Map<Party, AnonymousParty> = subFlow(SwapIdentitiesFlow(initiateFlow(otherSide))) override fun call(): Map<Party, AnonymousParty> = subFlow(SwapIdentitiesFlow(initiateFlow(otherSide)))
} }
@InitiatedBy(SwapIdentitiesInitiator::class) @InitiatedBy(SwapIdentitiesInitiator::class)
@ -181,3 +177,4 @@ private class SwapIdentitiesResponder(private val otherSide: FlowSession) : Flow
subFlow(SwapIdentitiesFlow(otherSide)) subFlow(SwapIdentitiesFlow(otherSide))
} }
} }
}

View File

@ -14,14 +14,15 @@ import org.junit.Test;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import static java.util.Collections.singletonList;
import static net.corda.testing.core.TestUtils.singleIdentity; import static net.corda.testing.core.TestUtils.singleIdentity;
import static net.corda.testing.node.internal.InternalTestUtilsKt.cordappsForPackages; import static net.corda.testing.node.internal.InternalTestUtilsKt.enclosedCordapp;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
public class FlowsInJavaTest { public class FlowsInJavaTest {
private final MockNetwork mockNet = new MockNetwork( private final MockNetwork mockNet = new MockNetwork(
new MockNetworkParameters().withCordappsForAllNodes(cordappsForPackages("net.corda.core.flows")) new MockNetworkParameters().withCordappsForAllNodes(singletonList(enclosedCordapp(this)))
); );
private StartedMockNode aliceNode; private StartedMockNode aliceNode;
private StartedMockNode bobNode; private StartedMockNode bobNode;

View File

@ -13,7 +13,7 @@ import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -25,7 +25,7 @@ class ContractHierarchyTest {
@Before @Before
fun before() { fun before() {
// We run this in parallel threads to help catch any race conditions that may exist. // We run this in parallel threads to help catch any race conditions that may exist.
mockNet = InternalMockNetwork(networkSendManuallyPumped = false, threadPerNode = true, cordappsForAllNodes = cordappsForPackages("net.corda.core.contracts")) mockNet = InternalMockNetwork(networkSendManuallyPumped = false, threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp()))
} }
@After @After

View File

@ -19,9 +19,10 @@ import net.corda.testing.internal.matchers.flow.willReturn
import net.corda.testing.internal.matchers.flow.willThrow import net.corda.testing.internal.matchers.flow.willThrow
import net.corda.testing.internal.rigorousMock import net.corda.testing.internal.rigorousMock
import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import org.junit.AfterClass import org.junit.AfterClass
import org.junit.Test import org.junit.Test
@ -29,7 +30,7 @@ class CollectSignaturesFlowTests : WithContracts {
companion object { companion object {
private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
private val miniCorpServices = MockServices(listOf("net.corda.testing.contracts"), miniCorp, rigorousMock<IdentityService>()) private val miniCorpServices = MockServices(listOf("net.corda.testing.contracts"), miniCorp, rigorousMock<IdentityService>())
private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.core.flows")) private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()))
private const val MAGIC_NUMBER = 1337 private const val MAGIC_NUMBER = 1337

View File

@ -8,8 +8,6 @@ import com.natpryce.hamkrest.isA
import net.corda.core.CordaRuntimeException import net.corda.core.CordaRuntimeException
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.testing.internal.matchers.rpc.willReturn
import net.corda.testing.internal.matchers.rpc.willThrow
import net.corda.core.flows.mixins.WithContracts import net.corda.core.flows.mixins.WithContracts
import net.corda.core.flows.mixins.WithFinality import net.corda.core.flows.mixins.WithFinality
import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.CordaRPCOps
@ -21,6 +19,8 @@ import net.corda.testing.contracts.DummyContractV2
import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.internal.matchers.rpc.willReturn
import net.corda.testing.internal.matchers.rpc.willThrow
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.internal.* import net.corda.testing.node.internal.*
import org.junit.AfterClass import org.junit.AfterClass
@ -28,7 +28,7 @@ import org.junit.Test
class ContractUpgradeFlowRPCTest : WithContracts, WithFinality { class ContractUpgradeFlowRPCTest : WithContracts, WithFinality {
companion object { companion object {
private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows")) private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()))
@JvmStatic @JvmStatic
@AfterClass @AfterClass

View File

@ -23,17 +23,15 @@ import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.internal.matchers.flow.willReturn import net.corda.testing.internal.matchers.flow.willReturn
import net.corda.testing.internal.matchers.flow.willThrow import net.corda.testing.internal.matchers.flow.willThrow
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.*
import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.internal.startFlow
import org.junit.AfterClass import org.junit.AfterClass
import org.junit.Test import org.junit.Test
import java.util.* import java.util.*
class ContractUpgradeFlowTest : WithContracts, WithFinality { class ContractUpgradeFlowTest : WithContracts, WithFinality {
companion object { companion object {
private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows", "net.corda.finance.schemas")) private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()))
@JvmStatic @JvmStatic
@AfterClass @AfterClass

View File

@ -26,11 +26,7 @@ class FinalityFlowTests : WithFinality {
private val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party private val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party
} }
override val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages( override val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, enclosedCordapp()))
"net.corda.finance.contracts.asset",
"net.corda.finance.schemas",
"net.corda.core.flows.mixins"
))
private val aliceNode = makeNode(ALICE_NAME) private val aliceNode = makeNode(ALICE_NAME)

View File

@ -14,111 +14,16 @@ import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.node.VersionInfo import net.corda.node.VersionInfo
import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.*
import net.corda.testing.node.internal.InternalMockNodeParameters
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Test import org.junit.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
// A dummy reference state contract.
internal class RefState : Contract {
companion object {
const val CONTRACT_ID = "net.corda.core.flows.RefState"
}
override fun verify(tx: LedgerTransaction) = Unit
data class State(val owner: Party, val version: Int = 0, override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState {
override val participants: List<AbstractParty> get() = listOf(owner)
fun update() = copy(version = version + 1)
}
class Create : CommandData
class Update : CommandData
}
// A flow to create a reference state.
internal class CreateRefState : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID)
addCommand(RefState.Create(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
// A flow to update a specific reference state.
internal class UpdateRefState(private val stateAndRef: StateAndRef<RefState.State>) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addInputState(stateAndRef)
addOutputState(stateAndRef.state.data.update(), RefState.CONTRACT_ID)
addCommand(RefState.Update(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
// A set of flows to share a stateref with all other nodes in the mock network.
internal object ShareRefState {
@InitiatingFlow
class Initiator(private val stateAndRef: StateAndRef<ContractState>) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val sessions = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }.map { initiateFlow(it) }
val transactionId = stateAndRef.ref.txhash
val transaction = serviceHub.validatedTransactions.getTransaction(transactionId)
?: throw FlowException("Cannot find $transactionId.")
sessions.forEach { subFlow(SendTransactionFlow(it, transaction)) }
}
}
@InitiatedBy(ShareRefState.Initiator::class)
class Responder(private val otherSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
logger.info("Receiving dependencies.")
subFlow(ReceiveTransactionFlow(
otherSideSession = otherSession,
checkSufficientSignatures = true,
statesToRecord = StatesToRecord.ALL_VISIBLE
))
}
}
}
// A flow to use a reference state in another transaction.
internal class UseRefState(private val linearId: UniqueIdentifier) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val query = QueryCriteria.LinearStateQueryCriteria(
linearId = listOf(linearId),
relevancyStatus = Vault.RelevancyStatus.ALL
)
val referenceState = serviceHub.vaultService.queryBy<ContractState>(query).states.single()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addReferenceState(referenceState.referenced())
addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID)
addCommand(RefState.Create(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
class WithReferencedStatesFlowTests { class WithReferencedStatesFlowTests {
companion object { companion object {
@JvmStatic @JvmStatic
private val mockNet = InternalMockNetwork( private val mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.core.flows", "net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
threadPerNode = true, threadPerNode = true,
initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)
) )
@ -142,7 +47,7 @@ class WithReferencedStatesFlowTests {
val newRefState = newRefTx.tx.outRefsOfType<RefState.State>().single() val newRefState = newRefTx.tx.outRefsOfType<RefState.State>().single()
// 2. Share it with others. // 2. Share it with others.
nodes[0].services.startFlow(ShareRefState.Initiator(newRefState)).resultFuture.getOrThrow() nodes[0].services.startFlow(Initiator(newRefState)).resultFuture.getOrThrow()
// 3. Update the reference state but don't share the update. // 3. Update the reference state but don't share the update.
val updatedRefTx = nodes[0].services.startFlow(UpdateRefState(newRefState)).resultFuture.getOrThrow() val updatedRefTx = nodes[0].services.startFlow(UpdateRefState(newRefState)).resultFuture.getOrThrow()
@ -152,10 +57,100 @@ class WithReferencedStatesFlowTests {
val useRefTx = nodes[1].services.startFlow(WithReferencedStatesFlow { UseRefState(newRefState.state.data.linearId) }).resultFuture val useRefTx = nodes[1].services.startFlow(WithReferencedStatesFlow { UseRefState(newRefState.state.data.linearId) }).resultFuture
// 5. Share the update reference state. // 5. Share the update reference state.
nodes[0].services.startFlow(ShareRefState.Initiator(updatedRefState)).resultFuture.getOrThrow() nodes[0].services.startFlow(Initiator(updatedRefState)).resultFuture.getOrThrow()
// 6. Check that we have a valid signed transaction with the updated reference state. // 6. Check that we have a valid signed transaction with the updated reference state.
val result = useRefTx.getOrThrow() val result = useRefTx.getOrThrow()
assertEquals(updatedRefState.ref, result.tx.references.single()) assertEquals(updatedRefState.ref, result.tx.references.single())
} }
// A dummy reference state contract.
class RefState : Contract {
companion object {
val CONTRACT_ID: String = RefState::class.java.name
}
override fun verify(tx: LedgerTransaction) = Unit
data class State(val owner: Party, val version: Int = 0, override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState {
override val participants: List<AbstractParty> get() = listOf(owner)
fun update() = copy(version = version + 1)
}
class Create : CommandData
class Update : CommandData
}
// A flow to create a reference state.
class CreateRefState : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID)
addCommand(RefState.Create(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
// A flow to update a specific reference state.
class UpdateRefState(private val stateAndRef: StateAndRef<RefState.State>) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addInputState(stateAndRef)
addOutputState(stateAndRef.state.data.update(), RefState.CONTRACT_ID)
addCommand(RefState.Update(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
// A set of flows to share a stateref with all other nodes in the mock network.
@InitiatingFlow
class Initiator(private val stateAndRef: StateAndRef<ContractState>) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val sessions = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }.map { initiateFlow(it) }
val transactionId = stateAndRef.ref.txhash
val transaction = serviceHub.validatedTransactions.getTransaction(transactionId)
?: throw FlowException("Cannot find $transactionId.")
sessions.forEach { subFlow(SendTransactionFlow(it, transaction)) }
}
}
@InitiatedBy(Initiator::class)
class Responder(private val otherSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
logger.info("Receiving dependencies.")
subFlow(ReceiveTransactionFlow(
otherSideSession = otherSession,
checkSufficientSignatures = true,
statesToRecord = StatesToRecord.ALL_VISIBLE
))
}
}
// A flow to use a reference state in another transaction.
class UseRefState(private val linearId: UniqueIdentifier) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities.first()
val query = QueryCriteria.LinearStateQueryCriteria(
linearId = listOf(linearId),
relevancyStatus = Vault.RelevancyStatus.ALL
)
val referenceState = serviceHub.vaultService.queryBy<ContractState>(query).states.single()
val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply {
addReferenceState(referenceState.referenced())
addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID)
addCommand(RefState.Create(), listOf(ourIdentity.owningKey))
})
return subFlow(FinalityFlow(stx, emptyList()))
}
}
} }

View File

@ -15,7 +15,8 @@ import net.corda.testing.core.singleIdentity
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.enclosedCordapp
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -40,7 +41,7 @@ class ResolveTransactionsFlowTest {
@Before @Before
fun setup() { fun setup() {
mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName))) mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp())))
notaryNode = mockNet.defaultNotaryNode notaryNode = mockNet.defaultNotaryNode
megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB")) megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB"))
miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB")) miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB"))

View File

@ -9,8 +9,10 @@ import net.corda.finance.flows.CashException
import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashIssueFlow
import net.corda.finance.flows.CashPaymentFlow import net.corda.finance.flows.CashPaymentFlow
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.MockNodeConfigOverrides import net.corda.testing.node.MockNodeConfigOverrides
import net.corda.testing.node.MockNodeParameters import net.corda.testing.node.MockNodeParameters
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.After import org.junit.After
import org.junit.Test import org.junit.Test
@ -18,7 +20,7 @@ import java.util.Collections.nCopies
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
class CashSelectionH2ImplTest { class CashSelectionH2ImplTest {
private val mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance")) private val mockNet = MockNetwork(MockNetworkParameters(threadPerNode = true, cordappsForAllNodes = FINANCE_CORDAPPS))
@After @After
fun cleanUp() { fun cleanUp() {

View File

@ -9,7 +9,9 @@ import net.corda.finance.contracts.asset.Cash
import net.corda.testing.core.BOC_NAME import net.corda.testing.core.BOC_NAME
import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -26,8 +28,7 @@ class CashExitFlowTests {
@Before @Before
fun start() { fun start() {
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS))
cordappPackages = listOf("net.corda.finance.contracts.asset", "net.corda.finance.schemas"))
bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME)
bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME)
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -9,7 +9,9 @@ import net.corda.finance.contracts.asset.Cash
import net.corda.testing.core.BOC_NAME import net.corda.testing.core.BOC_NAME
import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -24,9 +26,7 @@ class CashIssueFlowTests {
@Before @Before
fun start() { fun start() {
mockNet = MockNetwork( mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS))
servicePeerAllocationStrategy = RoundRobin(),
cordappPackages = listOf("net.corda.finance.contracts", "net.corda.finance.schemas"))
bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME)
bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME)
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -12,7 +12,9 @@ import net.corda.finance.contracts.asset.Cash
import net.corda.testing.core.* import net.corda.testing.core.*
import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -30,7 +32,7 @@ class CashPaymentFlowTests {
@Before @Before
fun start() { fun start() {
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance")) mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS))
bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME)
bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME)
aliceNode = mockNet.createPartyNode(ALICE_NAME) aliceNode = mockNet.createPartyNode(ALICE_NAME)

View File

@ -23,7 +23,7 @@ import net.corda.testing.driver.DriverDSL
import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.NotarySpec import net.corda.testing.node.NotarySpec
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test import org.junit.Test
import java.net.URL import java.net.URL
@ -50,7 +50,7 @@ class AttachmentLoadingTests {
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = false, startNodesInProcess = false,
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)), notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)),
cordappsForAllNodes = cordappsForPackages(javaClass.packageName) cordappsForAllNodes = listOf(enclosedCordapp())
)) { )) {
installIsolatedCordapp(ALICE_NAME) installIsolatedCordapp(ALICE_NAME)
@ -73,7 +73,7 @@ class AttachmentLoadingTests {
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = false, startNodesInProcess = false,
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)), notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)),
cordappsForAllNodes = cordappsForPackages(javaClass.packageName) cordappsForAllNodes = listOf(enclosedCordapp())
)) { )) {
installIsolatedCordapp(ALICE_NAME) installIsolatedCordapp(ALICE_NAME)
installIsolatedCordapp(BOB_NAME) installIsolatedCordapp(BOB_NAME)

View File

@ -23,6 +23,7 @@ import net.corda.testing.node.NotarySpec
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.internal.DummyClusterSpec import net.corda.testing.node.internal.DummyClusterSpec
import net.corda.testing.node.internal.FINANCE_CORDAPPS import net.corda.testing.node.internal.FINANCE_CORDAPPS
import net.corda.testing.node.internal.cordappWithPackages
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.Test
import rx.Observable import rx.Observable
@ -43,8 +44,7 @@ class DistributedServiceTests {
invokeRpc(CordaRPCOps::stateMachinesFeed)) invokeRpc(CordaRPCOps::stateMachinesFeed))
) )
driver(DriverParameters( driver(DriverParameters(
extraCordappPackagesToScan = listOf("net.corda.notary.raft"), cordappsForAllNodes = FINANCE_CORDAPPS + cordappWithPackages("net.corda.notary.raft"),
cordappsForAllNodes = FINANCE_CORDAPPS,
notarySpecs = listOf(NotarySpec( notarySpecs = listOf(NotarySpec(
DUMMY_NOTARY_NAME, DUMMY_NOTARY_NAME,
rpcUsers = listOf(testUser), rpcUsers = listOf(testUser),

View File

@ -23,6 +23,9 @@ import net.corda.testing.core.dummyCommand
import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.cordappWithPackages
import net.corda.testing.node.internal.enclosedCordapp
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
@ -97,7 +100,7 @@ class ScheduledFlowIntegrationTests {
fun `test that when states are being spent at the same time that schedules trigger everything is processed`() { fun `test that when states are being spent at the same time that schedules trigger everything is processed`() {
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = true, startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts", "net.corda.testMessage") cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, cordappWithPackages("net.corda.testMessage"), enclosedCordapp())
)) { )) {
val N = 23 val N = 23
val rpcUser = User("admin", "admin", setOf("ALL")) val rpcUser = User("admin", "admin", setOf("ALL"))

View File

@ -20,6 +20,8 @@ import net.corda.testing.core.dummyCommand
import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.enclosedCordapp
import org.junit.Test import org.junit.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -76,9 +78,10 @@ class LargeTransactionsTest {
val bigFile2 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 1, "b") val bigFile2 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 1, "b")
val bigFile3 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 2, "c") val bigFile3 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 2, "c")
val bigFile4 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 3, "d") val bigFile4 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 3, "d")
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = true, startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
networkParameters = testNetworkParameters(maxMessageSize = 15.MB.toInt(), maxTransactionSize = 13.MB.toInt()) networkParameters = testNetworkParameters(maxMessageSize = 15.MB.toInt(), maxTransactionSize = 13.MB.toInt())
)) { )) {
val rpcUser = User("admin", "admin", setOf("ALL")) val rpcUser = User("admin", "admin", setOf("ALL"))

View File

@ -47,10 +47,10 @@ import net.corda.testing.core.expect
import net.corda.testing.core.expectEvents import net.corda.testing.core.expectEvents
import net.corda.testing.core.sequence import net.corda.testing.core.sequence
import net.corda.testing.internal.fromUserList import net.corda.testing.internal.fromUserList
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.InternalMockNodeParameters import net.corda.testing.node.internal.InternalMockNodeParameters
import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.testActor import net.corda.testing.node.testActor
import org.apache.commons.io.IOUtils import org.apache.commons.io.IOUtils
import org.assertj.core.api.Assertions.* import org.assertj.core.api.Assertions.*
@ -94,7 +94,7 @@ class CordaRPCOpsImplTest {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.finance")) mockNet = InternalMockNetwork(cordappsForAllNodes = FINANCE_CORDAPPS)
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))
rpc = aliceNode.rpcOps rpc = aliceNode.rpcOps
CURRENT_RPC_CONTEXT.set(RpcAuthContext(InvocationContext.rpc(testActor()), buildSubject("TEST_USER", emptySet()))) CURRENT_RPC_CONTEXT.set(RpcAuthContext(InvocationContext.rpc(testActor()), buildSubject("TEST_USER", emptySet())))

View File

@ -1,11 +1,11 @@
package net.corda.node.internal package net.corda.node.internal
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByService
import net.corda.core.context.InvocationContext import net.corda.core.context.InvocationContext
import net.corda.core.context.InvocationOrigin import net.corda.core.context.InvocationOrigin
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByService
import net.corda.core.node.AppServiceHub import net.corda.core.node.AppServiceHub
import net.corda.core.node.ServiceHub import net.corda.core.node.ServiceHub
import net.corda.core.node.services.CordaService import net.corda.core.node.services.CordaService
@ -18,7 +18,10 @@ import net.corda.finance.DOLLARS
import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashIssueFlow
import net.corda.node.internal.cordapp.DummyRPCFlow import net.corda.node.internal.cordapp.DummyRPCFlow
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.enclosedCordapp
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -28,6 +31,62 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals import kotlin.test.assertNotEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
class CordaServiceTest {
private lateinit var mockNet: MockNetwork
private lateinit var nodeA: StartedMockNode
@Before
fun start() {
mockNet = MockNetwork(MockNetworkParameters(threadPerNode = true, cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, enclosedCordapp())))
nodeA = mockNet.createNode()
mockNet.startNodes()
}
@After
fun cleanUp() {
mockNet.stopNodes()
}
@Test
fun `Can find distinct services on node`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
val service2 = nodeA.services.cordaService(TestCordaService2::class.java)
val legacyService = nodeA.services.cordaService(LegacyCordaService::class.java)
assertEquals(TestCordaService::class.java, service.javaClass)
assertEquals(TestCordaService2::class.java, service2.javaClass)
assertNotEquals(service.appServiceHub, service2.appServiceHub) // Each gets a customised AppServiceHub
assertEquals(LegacyCordaService::class.java, legacyService.javaClass)
}
@Test
fun `Can start StartableByService flows`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
service.startServiceFlow()
}
@Test
fun `Can't start StartableByRPC flows`() {
val service = nodeA.services.cordaService(TestCordaService2::class.java)
assertFailsWith<IllegalArgumentException> { service.startInvalidRPCFlow() }
}
@Test
fun `Test flow with progress tracking`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
service.startServiceFlowAndTrack()
}
/**
* Reproduce CORDA-2296
* Querying the vault from a services constructor failed because the criteriaBuilder
* had not been initialized.
*/
@Test
fun `Can query vault service in constructor`() {
nodeA.services.cordaService(VaultQueryService::class.java)
}
@StartableByService @StartableByService
class DummyServiceFlow : FlowLogic<InvocationContext>() { class DummyServiceFlow : FlowLogic<InvocationContext>() {
companion object { companion object {
@ -83,60 +142,4 @@ class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToke
serviceHub.vaultService.trackBy(ContractState::class.java, criteria) serviceHub.vaultService.trackBy(ContractState::class.java, criteria)
} }
} }
class CordaServiceTest {
private lateinit var mockNet: MockNetwork
private lateinit var nodeA: StartedMockNode
@Before
fun start() {
mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.node.internal","net.corda.finance"))
nodeA = mockNet.createNode()
mockNet.startNodes()
}
@After
fun cleanUp() {
mockNet.stopNodes()
}
@Test
fun `Can find distinct services on node`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
val service2 = nodeA.services.cordaService(TestCordaService2::class.java)
val legacyService = nodeA.services.cordaService(LegacyCordaService::class.java)
assertEquals(TestCordaService::class.java, service.javaClass)
assertEquals(TestCordaService2::class.java, service2.javaClass)
assertNotEquals(service.appServiceHub, service2.appServiceHub) // Each gets a customised AppServiceHub
assertEquals(LegacyCordaService::class.java, legacyService.javaClass)
}
@Test
fun `Can start StartableByService flows`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
service.startServiceFlow()
}
@Test
fun `Can't start StartableByRPC flows`() {
val service = nodeA.services.cordaService(TestCordaService2::class.java)
assertFailsWith<IllegalArgumentException> { service.startInvalidRPCFlow() }
}
@Test
fun `Test flow with progress tracking`() {
val service = nodeA.services.cordaService(TestCordaService::class.java)
service.startServiceFlowAndTrack()
}
/**
* Reproduce CORDA-2296
* Querying the vault from a services constructor failed because the criteriaBuilder
* had not been initialized.
*/
@Test
fun `Can query vault service in constructor`() {
nodeA.services.cordaService(VaultQueryService::class.java)
}
} }

View File

@ -1,12 +1,11 @@
package net.corda.node.internal package net.corda.node.internal
import net.corda.core.internal.packageName
import net.corda.core.node.ServiceHub import net.corda.core.node.ServiceHub
import net.corda.core.node.services.CordaService import net.corda.core.node.services.CordaService
import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import org.junit.After import org.junit.After
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
@ -19,7 +18,7 @@ class NodeUnloadHandlerTests {
val shutdownLatch = CountDownLatch(1) val shutdownLatch = CountDownLatch(1)
} }
private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(javaClass.packageName), notarySpecs = emptyList()) private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(enclosedCordapp()), notarySpecs = emptyList())
@After @After
fun cleanUp() { fun cleanUp() {

View File

@ -70,13 +70,11 @@ import kotlin.test.assertTrue
@RunWith(Parameterized::class) @RunWith(Parameterized::class)
class TwoPartyTradeFlowTests(private val anonymous: Boolean) { class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
companion object { companion object {
private val cordappPackages = listOf("net.corda.finance.contracts", "net.corda.finance.schemas")
@JvmStatic @JvmStatic
@Parameterized.Parameters(name = "Anonymous = {0}") @Parameterized.Parameters(name = "Anonymous = {0}")
fun data(): Collection<Boolean> = listOf(true, false) fun data(): Collection<Boolean> = listOf(true, false)
private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
private val DUMMY_NOTARY get() = dummyNotary.party
} }
private lateinit var mockNet: InternalMockNetwork private lateinit var mockNet: InternalMockNetwork
@ -99,7 +97,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
// We run this in parallel threads to help catch any race conditions that may exist. The other tests // We run this in parallel threads to help catch any race conditions that may exist. The other tests
// we run in the unit test thread exclusively to speed things up, ensure deterministic results and // we run in the unit test thread exclusively to speed things up, ensure deterministic results and
// allow interruption half way through. // allow interruption half way through.
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages), threadPerNode = true) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP), threadPerNode = true)
val notaryNode = mockNet.defaultNotaryNode val notaryNode = mockNet.defaultNotaryNode
val notary = mockNet.defaultNotaryIdentity val notary = mockNet.defaultNotaryIdentity
notaryNode.services.ledger(notary) { notaryNode.services.ledger(notary) {
@ -149,7 +147,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test(expected = InsufficientBalanceException::class) @Test(expected = InsufficientBalanceException::class)
fun `trade cash for commercial paper fails using soft locking`() { fun `trade cash for commercial paper fails using soft locking`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages), threadPerNode = true) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP), threadPerNode = true)
val notaryNode = mockNet.defaultNotaryNode val notaryNode = mockNet.defaultNotaryNode
notaryNode.services.ledger(notaryNode.info.singleIdentity()) { notaryNode.services.ledger(notaryNode.info.singleIdentity()) {
val aliceNode = mockNet.createPartyNode(ALICE_NAME) val aliceNode = mockNet.createPartyNode(ALICE_NAME)
@ -205,7 +203,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test @Test
fun `shutdown and restore`() { fun `shutdown and restore`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
val notaryNode = mockNet.defaultNotaryNode val notaryNode = mockNet.defaultNotaryNode
val notary = mockNet.defaultNotaryIdentity val notary = mockNet.defaultNotaryIdentity
notaryNode.services.ledger(notary) { notaryNode.services.ledger(notary) {
@ -314,7 +312,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test @Test
fun `check dependencies of sale asset are resolved`() { fun `check dependencies of sale asset are resolved`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
val notaryNode = mockNet.defaultNotaryNode val notaryNode = mockNet.defaultNotaryNode
val aliceNode = makeNodeWithTracking(ALICE_NAME) val aliceNode = makeNodeWithTracking(ALICE_NAME)
val bobNode = makeNodeWithTracking(BOB_NAME) val bobNode = makeNodeWithTracking(BOB_NAME)
@ -417,7 +415,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test @Test
fun `track works`() { fun `track works`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
val notaryNode = mockNet.defaultNotaryNode val notaryNode = mockNet.defaultNotaryNode
val aliceNode = makeNodeWithTracking(ALICE_NAME) val aliceNode = makeNodeWithTracking(ALICE_NAME)
val bobNode = makeNodeWithTracking(BOB_NAME) val bobNode = makeNodeWithTracking(BOB_NAME)
@ -498,7 +496,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test @Test
fun `dependency with error on buyer side`() { fun `dependency with error on buyer side`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) { mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) {
runWithError(true, false, "at least one cash input") runWithError(true, false, "at least one cash input")
} }
@ -506,7 +504,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test @Test
fun `dependency with error on seller side`() { fun `dependency with error on seller side`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) { mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) {
runWithError(false, true, "Issuances have a time-window") runWithError(false, true, "Issuances have a time-window")
} }

View File

@ -4,7 +4,6 @@ import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.contextLogger import net.corda.core.utilities.contextLogger
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
@ -42,7 +41,7 @@ class ScheduledFlowsDrainingModeTest {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
threadPerNode = true threadPerNode = true
) )
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))

View File

@ -6,7 +6,6 @@ import net.corda.core.crypto.SecureHash
import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FinalityFlow
import net.corda.core.flows.StateMachineRunId import net.corda.core.flows.StateMachineRunId
import net.corda.core.internal.cordapp.CordappResolver import net.corda.core.internal.cordapp.CordappResolver
import net.corda.core.internal.packageName
import net.corda.core.toFuture import net.corda.core.toFuture
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
@ -43,7 +42,7 @@ class FinalityHandlerTest {
legalName = BOB_NAME, legalName = BOB_NAME,
// The node disables the FinalityHandler completely if there are no old CorDapps loaded, so we need to add // The node disables the FinalityHandler completely if there are no old CorDapps loaded, so we need to add
// a token old CorDapp to keep the handler running. // a token old CorDapp to keep the handler running.
additionalCordapps = setOf(cordappWithPackages(javaClass.packageName).copy(targetPlatformVersion = 3)) additionalCordapps = setOf(DUMMY_CONTRACTS_CORDAPP.copy(targetPlatformVersion = 3))
)) ))
val stx = alice.issueCashTo(bob) val stx = alice.issueCashTo(bob)

View File

@ -19,10 +19,8 @@ import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.dummyCommand import net.corda.testing.core.dummyCommand
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.node.MockNetwork import net.corda.testing.node.*
import net.corda.testing.node.MockNetworkNotarySpec import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.MockNodeParameters
import net.corda.testing.node.StartedMockNode
import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -47,10 +45,10 @@ class NotaryChangeTests {
@Before @Before
fun setUp() { fun setUp() {
mockNet = MockNetwork( mockNet = MockNetwork(MockNetworkParameters(
notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName), MockNetworkNotarySpec(newNotaryName)), notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName), MockNetworkNotarySpec(newNotaryName)),
cordappPackages = listOf("net.corda.testing.contracts") cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP)
) ))
clientNodeA = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME)) clientNodeA = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME))
clientNodeB = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) clientNodeB = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
clientA = clientNodeA.info.singleIdentity() clientA = clientNodeA.info.singleIdentity()

View File

@ -5,7 +5,6 @@ import net.corda.core.contracts.ContractState
import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FinalityFlow
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.services.queryBy import net.corda.core.node.services.queryBy
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
@ -14,7 +13,7 @@ import net.corda.core.utilities.getOrThrow
import net.corda.finance.DOLLARS import net.corda.finance.DOLLARS
import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.Cash
import net.corda.finance.issuedBy import net.corda.finance.issuedBy
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.FINANCE_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.startFlow import net.corda.testing.node.internal.startFlow
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
@ -24,11 +23,7 @@ import rx.schedulers.Schedulers
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
class ServiceHubConcurrentUsageTest { class ServiceHubConcurrentUsageTest {
private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages( private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
"net.corda.finance.schemas",
"net.corda.node.services.vault.VaultQueryExceptionsTests",
Cash::class.packageName
))
@After @After
fun stopNodes() { fun stopNodes() {
@ -42,7 +37,7 @@ class ServiceHubConcurrentUsageTest {
val initiatingFlow = TestFlow(mockNet.defaultNotaryIdentity) val initiatingFlow = TestFlow(mockNet.defaultNotaryIdentity)
val node = mockNet.createPartyNode() val node = mockNet.createPartyNode()
node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe { _ -> node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe {
try { try {
node.services.vaultService.queryBy<ContractState>().states node.services.vaultService.queryBy<ContractState>().states
successful = true successful = true

View File

@ -75,7 +75,7 @@ class TimedFlowTests {
@JvmStatic @JvmStatic
fun setup() { fun setup() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.node.services"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
defaultParameters = MockNetworkParameters().withServicePeerAllocationStrategy(InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin()), defaultParameters = MockNetworkParameters().withServicePeerAllocationStrategy(InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin()),
threadPerNode = true threadPerNode = true
) )

View File

@ -6,7 +6,6 @@ import net.corda.core.context.InvocationOrigin
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.services.VaultService import net.corda.core.node.services.VaultService
import net.corda.core.node.services.queryBy import net.corda.core.node.services.queryBy
import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria
@ -112,7 +111,7 @@ class ScheduledFlowTests {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName), threadPerNode = true) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), threadPerNode = true)
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))
bobNode = mockNet.createNode(InternalMockNodeParameters(legalName = BOB_NAME)) bobNode = mockNet.createNode(InternalMockNodeParameters(legalName = BOB_NAME))
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -13,7 +13,7 @@ import net.corda.testing.core.TestIdentity
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.makeTestIdentityService import net.corda.testing.node.makeTestIdentityService
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -43,7 +43,7 @@ class ExposeJpaToFlowsTests {
@Before @Before
fun setUp() { fun setUp() {
mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = cordappsForPackages(javaClass.packageName))) mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(enclosedCordapp())))
val (db, mockServices) = MockServices.makeTestDatabaseAndMockServices( val (db, mockServices) = MockServices.makeTestDatabaseAndMockServices(
cordappPackages = listOf(javaClass.packageName), cordappPackages = listOf(javaClass.packageName),
identityService = makeTestIdentityService(myself.identity), identityService = makeTestIdentityService(myself.identity),

View File

@ -2,8 +2,6 @@ package net.corda.node.services.persistence
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.Amount import net.corda.core.contracts.Amount
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
@ -17,9 +15,11 @@ import net.corda.node.services.identity.PersistentIdentityService
import net.corda.node.services.keys.E2ETestKeyManagementService import net.corda.node.services.keys.E2ETestKeyManagementService
import net.corda.testing.core.BOC_NAME import net.corda.testing.core.BOC_NAME
import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.TestingNamedCacheFactory
import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -48,9 +48,7 @@ class HibernateColumnConverterTests {
@Before @Before
fun start() { fun start() {
mockNet = MockNetwork( mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS))
servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin(),
cordappPackages = listOf("net.corda.finance.contracts.asset", "net.corda.finance.schemas"))
bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME)
bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME)
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -6,17 +6,21 @@ import net.corda.core.contracts.StateAndContract
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.StatesToRecord import net.corda.core.node.StatesToRecord
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.node.testing.MESSAGE_CHAIN_CONTRACT_PROGRAM_ID
import net.corda.node.testing.MessageChainContract
import net.corda.node.testing.MessageChainState
import net.corda.node.testing.MessageData
import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappWithPackages import net.corda.testing.node.internal.cordappWithPackages
import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -25,15 +29,15 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
class ObserverNodeTransactionTests { class ObserverNodeTransactionTests {
private lateinit var mockNet: InternalMockNetwork private lateinit var mockNet: InternalMockNetwork
@Before @Before
fun start() { fun start() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)), cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()),
networkSendManuallyPumped = false, networkSendManuallyPumped = false,
threadPerNode = true) threadPerNode = true
)
} }
@After @After
@ -50,15 +54,15 @@ class ObserverNodeTransactionTests {
fun buildTransactionChain(initialMessage: MessageData, chainLength: Int) { fun buildTransactionChain(initialMessage: MessageData, chainLength: Int) {
node.services.startFlow(StartMessageChainFlow(initialMessage, notary)).resultFuture.getOrThrow() node.services.startFlow(StartMessageChainFlow(initialMessage, notary)).resultFuture.getOrThrow()
var result = node.services.vaultService.queryBy(MessageChainState::class.java).states.filter { var result = node.services.vaultService.queryBy(MessageChainState::class.java).states.singleOrNull {
it.state.data.message.value.startsWith(initialMessage.value) it.state.data.message.value.startsWith(initialMessage.value)
}.singleOrNull() }
for (_i in 0.until(chainLength -1 )) { for (_i in 0.until(chainLength -1 )) {
node.services.startFlow(ContinueMessageChainFlow(result!!, notary)).resultFuture.getOrThrow() node.services.startFlow(ContinueMessageChainFlow(result!!, notary)).resultFuture.getOrThrow()
result = node.services.vaultService.queryBy(MessageChainState::class.java).states.filter { result = node.services.vaultService.queryBy(MessageChainState::class.java).states.singleOrNull {
it.state.data.message.value.startsWith(initialMessage.value) it.state.data.message.value.startsWith(initialMessage.value)
}.singleOrNull() }
} }
} }
@ -86,7 +90,7 @@ class ObserverNodeTransactionTests {
val outputMessage = MessageData("AAAA") val outputMessage = MessageData("AAAA")
checkObserverTransactions(outputMessage) checkObserverTransactions(outputMessage)
} }
}
@StartableByRPC @StartableByRPC
class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic<SignedTransaction>() { class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic<SignedTransaction>() {
@ -165,10 +169,7 @@ class ContinueMessageChainFlow(private val stateRef: StateAndRef<MessageChainSta
@InitiatingFlow @InitiatingFlow
@StartableByRPC @StartableByRPC
class ReportToCounterparty( class ReportToCounterparty(private val regulator: Party, private val signedTx: SignedTransaction) : FlowLogic<Unit>() {
private val regulator: Party,
private val signedTx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable @Suspendable
override fun call() { override fun call() {
val session = initiateFlow(regulator) val session = initiateFlow(regulator)
@ -178,9 +179,9 @@ class ReportToCounterparty(
@InitiatedBy(ReportToCounterparty::class) @InitiatedBy(ReportToCounterparty::class)
class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic<Unit>() { class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable @Suspendable
override fun call() { override fun call() {
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE)) subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE))
} }
} }
}

View File

@ -7,17 +7,21 @@ import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.StatesToRecord import net.corda.core.node.StatesToRecord
import net.corda.core.node.services.Vault import net.corda.core.node.services.Vault
import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.node.testing.MESSAGE_CHAIN_CONTRACT_PROGRAM_ID
import net.corda.node.testing.MessageChainContract
import net.corda.node.testing.MessageChainState
import net.corda.node.testing.MessageData
import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME import net.corda.testing.core.BOB_NAME
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappWithPackages import net.corda.testing.node.internal.cordappWithPackages
import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
@ -30,9 +34,10 @@ class TransactionOrderingTests {
@Before @Before
fun start() { fun start() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)), cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()),
networkSendManuallyPumped = false, networkSendManuallyPumped = false,
threadPerNode = true) threadPerNode = true
)
} }
@After @After
@ -91,7 +96,7 @@ class TransactionOrderingTests {
val bobStates = bob.services.vaultService.queryBy(MessageChainState::class.java, queryCriteria) val bobStates = bob.services.vaultService.queryBy(MessageChainState::class.java, queryCriteria)
assertEquals(3, bobStates.states.size) assertEquals(3, bobStates.states.size)
} }
}
@InitiatingFlow @InitiatingFlow
@StartableByRPC @StartableByRPC
@ -113,3 +118,4 @@ class ReceiveTx(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
otherSideSession.send(Unit) otherSideSession.send(Unit)
} }
} }
}

View File

@ -11,10 +11,7 @@ import net.corda.core.internal.executeAsync
import net.corda.core.node.AppServiceHub import net.corda.core.node.AppServiceHub
import net.corda.core.node.services.CordaService import net.corda.core.node.services.CordaService
import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.*
import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -28,7 +25,7 @@ class FlowAsyncOperationTests {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.node.services.statemachine"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
notarySpecs = emptyList() notarySpecs = emptyList()
) )
aliceNode = mockNet.createNode() aliceNode = mockNet.createNode()

View File

@ -43,7 +43,7 @@ class FlowFrameworkPersistenceTests {
@Before @Before
fun start() { fun start() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.finance.contracts", "net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin() servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin()
) )
aliceFlowManager = MockNodeFlowManager() aliceFlowManager = MockNodeFlowManager()

View File

@ -66,7 +66,7 @@ class FlowFrameworkTests {
@Before @Before
fun setUpMockNet() { fun setUpMockNet() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts") + FINANCE_CORDAPPS, cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
servicePeerAllocationStrategy = RoundRobin() servicePeerAllocationStrategy = RoundRobin()
) )

View File

@ -40,7 +40,7 @@ class FlowFrameworkTripartyTests {
@Before @Before
fun setUpGlobalMockNet() { fun setUpGlobalMockNet() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.finance.contracts", "net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin() servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin()
) )

View File

@ -9,7 +9,6 @@ import net.corda.core.flows.InitiatingFlow
import net.corda.core.identity.CordaX500Name import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.IdempotentFlow import net.corda.core.internal.IdempotentFlow
import net.corda.core.internal.TimedFlow import net.corda.core.internal.TimedFlow
import net.corda.core.internal.packageName
import net.corda.core.utilities.seconds import net.corda.core.utilities.seconds
import net.corda.node.services.config.FlowTimeoutConfiguration import net.corda.node.services.config.FlowTimeoutConfiguration
import net.corda.testing.node.internal.* import net.corda.testing.node.internal.*
@ -33,7 +32,7 @@ class IdempotentFlowTests {
@Before @Before
fun start() { fun start() {
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName)) mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp()))
nodeA = mockNet.createNode(InternalMockNodeParameters( nodeA = mockNet.createNode(InternalMockNodeParameters(
legalName = CordaX500Name("Alice", "AliceCorp", "GB"), legalName = CordaX500Name("Alice", "AliceCorp", "GB"),
configOverrides = { configOverrides = {

View File

@ -7,7 +7,6 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.FlowStateMachine import net.corda.core.internal.FlowStateMachine
import net.corda.core.internal.concurrent.flatMap import net.corda.core.internal.concurrent.flatMap
import net.corda.core.internal.packageName
import net.corda.core.messaging.MessageRecipients import net.corda.core.messaging.MessageRecipients
import net.corda.core.utilities.UntrustworthyData import net.corda.core.utilities.UntrustworthyData
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
@ -39,7 +38,7 @@ class RetryFlowMockTest {
@Before @Before
fun start() { fun start() {
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName)) mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp()))
nodeA = mockNet.createNode() nodeA = mockNet.createNode()
nodeB = mockNet.createNode() nodeB = mockNet.createNode()
mockNet.startNodes() mockNet.startNodes()
@ -180,7 +179,7 @@ class RetryFlowMockTest {
nodeA.smm.killFlow(flow.id) nodeA.smm.killFlow(flow.id)
assertThat(nodeA.smm.flowHospital.track().snapshot).isEmpty() assertThat(nodeA.smm.flowHospital.track().snapshot).isEmpty()
} }
}
class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint") class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint")
@ -285,3 +284,4 @@ class RetryInsertFlow(private val i: Int) : FlowLogic<Unit>() {
contextTransaction.session.save(tx) contextTransaction.session.save(tx)
} }
} }
}

View File

@ -16,9 +16,13 @@ import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.dummyCommand import net.corda.testing.core.dummyCommand
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.MockNodeParameters import net.corda.testing.node.MockNodeParameters
import net.corda.testing.node.StartedMockNode import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import net.corda.testing.node.internal.enclosedCordapp
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -37,10 +41,12 @@ class MaxTransactionSizeTests {
@Before @Before
fun setup() { fun setup() {
mockNet = MockNetwork(listOf("net.corda.testing.contracts"), networkParameters = testNetworkParameters(maxTransactionSize = 3_000_000)) mockNet = MockNetwork(MockNetworkParameters(
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
networkParameters = testNetworkParameters(maxTransactionSize = 3_000_000)
))
aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME))
bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
bobNode.registerInitiatedFlow(ReceiveLargeTransactionFlow::class.java)
notaryNode = mockNet.defaultNotaryNode notaryNode = mockNet.defaultNotaryNode
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity
alice = aliceNode.info.singleIdentity() alice = aliceNode.info.singleIdentity()
@ -90,11 +96,10 @@ class MaxTransactionSizeTests {
assertEquals(hash1, bigFile1.sha256) assertEquals(hash1, bigFile1.sha256)
SendLargeTransactionFlow(notary, bob, hash1, hash2, hash3, hash4, verify = false) SendLargeTransactionFlow(notary, bob, hash1, hash2, hash3, hash4, verify = false)
} }
assertFailsWith<UnexpectedFlowEndException> {
val future = aliceNode.startFlow(flow) val future = aliceNode.startFlow(flow)
mockNet.runNetwork() mockNet.runNetwork()
future.getOrThrow() assertThatThrownBy { future.getOrThrow() }.hasMessageContaining("Transaction exceeded network's maximum transaction size limit")
}
} }
private fun StartedMockNode.importAttachment(inputStream: InputStream): AttachmentId { private fun StartedMockNode.importAttachment(inputStream: InputStream): AttachmentId {
@ -133,7 +138,11 @@ class MaxTransactionSizeTests {
class ReceiveLargeTransactionFlow(private val otherSide: FlowSession) : FlowLogic<Unit>() { class ReceiveLargeTransactionFlow(private val otherSide: FlowSession) : FlowLogic<Unit>() {
@Suspendable @Suspendable
override fun call() { override fun call() {
try {
subFlow(ReceiveTransactionFlow(otherSide)) subFlow(ReceiveTransactionFlow(otherSide))
} catch (e: IllegalArgumentException) {
throw FlowException(e.message)
}
// Unblock the other side by sending some dummy object (Unit is fine here as it's a singleton). // Unblock the other side by sending some dummy object (Unit is fine here as it's a singleton).
otherSide.send(Unit) otherSide.send(Unit)
} }

View File

@ -46,8 +46,10 @@ class NonValidatingNotaryServiceTests {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), mockNet = InternalMockNetwork(
notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, false))) cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, false))
)
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))
notaryNode = mockNet.defaultNotaryNode notaryNode = mockNet.defaultNotaryNode
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -35,7 +35,7 @@ class NotaryServiceTests {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, validating = false)), notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, validating = false)),
initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)
) )

View File

@ -60,7 +60,7 @@ class NotaryWhitelistTests(
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork( mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName, validating = isValidating), MockNetworkNotarySpec(newNotaryName, validating = isValidating)), notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName, validating = isValidating), MockNetworkNotarySpec(newNotaryName, validating = isValidating)),
initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)
) )

View File

@ -48,8 +48,10 @@ class ValidatingNotaryServiceTests {
@Before @Before
fun setup() { fun setup() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), mockNet = InternalMockNetwork(
initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)) cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)
)
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))
notaryNode = mockNet.defaultNotaryNode notaryNode = mockNet.defaultNotaryNode
notary = mockNet.defaultNotaryIdentity notary = mockNet.defaultNotaryIdentity

View File

@ -6,7 +6,6 @@ import net.corda.core.contracts.*
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.internal.FlowStateMachine import net.corda.core.internal.FlowStateMachine
import net.corda.core.internal.packageName
import net.corda.core.internal.uncheckedCast import net.corda.core.internal.uncheckedCast
import net.corda.core.node.ServicesForResolution import net.corda.core.node.ServicesForResolution
import net.corda.core.node.services.KeyManagementService import net.corda.core.node.services.KeyManagementService
@ -26,7 +25,7 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.testing.core.singleIdentity import net.corda.testing.core.singleIdentity
import net.corda.testing.internal.rigorousMock import net.corda.testing.internal.rigorousMock
import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow import net.corda.testing.node.internal.startFlow
import org.junit.After import org.junit.After
import org.junit.Test import org.junit.Test
@ -79,7 +78,7 @@ class VaultSoftLockManagerTest {
doNothing().whenever(it).softLockRelease(any(), anyOrNull()) doNothing().whenever(it).softLockRelease(any(), anyOrNull())
} }
private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(ContractImpl::class.packageName), defaultFactory = { args -> private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(enclosedCordapp()), defaultFactory = { args ->
object : InternalMockNetwork.MockNode(args) { object : InternalMockNetwork.MockNode(args) {
override fun makeVaultService(keyManagementService: KeyManagementService, override fun makeVaultService(keyManagementService: KeyManagementService,
services: ServicesForResolution, services: ServicesForResolution,

View File

@ -1,4 +1,4 @@
package net.corda.node.services.persistence package net.corda.node.testing
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
@ -48,7 +48,7 @@ object MessageChainSchemaV1 : MappedSchema(
) : PersistentState() ) : PersistentState()
} }
const val MESSAGE_CHAIN_CONTRACT_PROGRAM_ID = "net.corda.node.services.persistence.MessageChainContract" const val MESSAGE_CHAIN_CONTRACT_PROGRAM_ID = "net.corda.node.testing.MessageChainContract"
open class MessageChainContract : Contract { open class MessageChainContract : Contract {
override fun verify(tx: LedgerTransaction) { override fun verify(tx: LedgerTransaction) {
@ -67,4 +67,3 @@ open class MessageChainContract : Contract {
class Send : Commands class Send : Commands
} }
} }

View File

@ -24,9 +24,6 @@ import net.corda.core.utilities.seconds
import net.corda.node.services.config.NotaryConfig import net.corda.node.services.config.NotaryConfig
import net.corda.nodeapi.internal.DevIdentityGenerator import net.corda.nodeapi.internal.DevIdentityGenerator
import net.corda.nodeapi.internal.network.NetworkParametersCopier import net.corda.nodeapi.internal.network.NetworkParametersCopier
import net.corda.notary.experimental.bftsmart.BFTSmartConfig
import net.corda.notary.experimental.bftsmart.minClusterSize
import net.corda.notary.experimental.bftsmart.minCorrectReplicas
import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.testing.core.dummyCommand import net.corda.testing.core.dummyCommand
@ -60,7 +57,7 @@ class BFTNotaryServiceTests {
@BeforeClass @BeforeClass
@JvmStatic @JvmStatic
fun before() { fun before() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts")) mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP))
val clusterSize = minClusterSize(1) val clusterSize = minClusterSize(1)
val started = startBftClusterAndNode(clusterSize, mockNet) val started = startBftClusterAndNode(clusterSize, mockNet)
notary = started.first notary = started.first

View File

@ -20,6 +20,7 @@ import net.corda.testing.driver.InProcess
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.ClusterSpec import net.corda.testing.node.ClusterSpec
import net.corda.testing.node.NotarySpec import net.corda.testing.node.NotarySpec
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import org.junit.Test import org.junit.Test
import java.util.* import java.util.*
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -32,7 +33,7 @@ class RaftNotaryServiceTests {
fun `detect double spend`() { fun `detect double spend`() {
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = true, startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3))) notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))
)) { )) {
val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow() val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow()
@ -65,7 +66,7 @@ class RaftNotaryServiceTests {
fun `notarise issue tx with time-window`() { fun `notarise issue tx with time-window`() {
driver(DriverParameters( driver(DriverParameters(
startNodesInProcess = true, startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3))) notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))
)) { )) {
val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow() val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow()

View File

@ -25,7 +25,7 @@ import java.util.zip.ZipEntry
* disparate classes. The CorDapp metadata that's present in the MANIFEST can also be tailored. * disparate classes. The CorDapp metadata that's present in the MANIFEST can also be tailored.
*/ */
data class CustomCordapp( data class CustomCordapp(
val packages: Set<String>, val packages: Set<String> = emptySet(),
val name: String = "custom-cordapp", val name: String = "custom-cordapp",
val versionId: Int = 1, val versionId: Int = 1,
val targetPlatformVersion: Int = PLATFORM_VERSION, val targetPlatformVersion: Int = PLATFORM_VERSION,

View File

@ -28,6 +28,7 @@ import net.corda.testing.node.InMemoryMessagingNetwork
import net.corda.testing.node.TestCordapp import net.corda.testing.node.TestCordapp
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.testContext import net.corda.testing.node.testContext
import org.apache.commons.lang.ClassUtils
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import rx.Observable import rx.Observable
import rx.subjects.AsyncSubject import rx.subjects.AsyncSubject
@ -65,6 +66,13 @@ val FINANCE_WORKFLOWS_CORDAPP: TestCordappImpl = findCordapp("net.corda.finance.
@JvmField @JvmField
val FINANCE_CORDAPPS: Set<TestCordappInternal> = setOf(FINANCE_CONTRACTS_CORDAPP, FINANCE_WORKFLOWS_CORDAPP) val FINANCE_CORDAPPS: Set<TestCordappInternal> = setOf(FINANCE_CONTRACTS_CORDAPP, FINANCE_WORKFLOWS_CORDAPP)
/**
* *Custom* CorDapp containing the contents of the `net.corda.testing.contracts` package, i.e. the dummy contracts. This is not a real CorDapp
* in the way that [FINANCE_CONTRACTS_CORDAPP] and [FINANCE_WORKFLOWS_CORDAPP] are.
*/
@JvmField
val DUMMY_CONTRACTS_CORDAPP: CustomCordapp = cordappWithPackages("net.corda.testing.contracts")
fun cordappsForPackages(vararg packageNames: String): Set<CustomCordapp> = cordappsForPackages(packageNames.asList()) fun cordappsForPackages(vararg packageNames: String): Set<CustomCordapp> = cordappsForPackages(packageNames.asList())
fun cordappsForPackages(packageNames: Iterable<String>): Set<CustomCordapp> { fun cordappsForPackages(packageNames: Iterable<String>): Set<CustomCordapp> {
@ -88,6 +96,25 @@ fun cordappForClasses(vararg classes: Class<*>): CustomCordapp = CustomCordapp(p
*/ */
fun findCordapp(scanPackage: String): TestCordappImpl = TestCordapp.findCordapp(scanPackage) as TestCordappImpl fun findCordapp(scanPackage: String): TestCordappImpl = TestCordapp.findCordapp(scanPackage) as TestCordappImpl
/** Create a *custom* CorDapp which just contains the enclosed classes of the receiver class. */
fun Any.enclosedCordapp(): CustomCordapp {
val receiverClass = javaClass.enclosingClass ?: javaClass // In case this is called in the companion object
val classes = HashSet<Class<*>>()
receiverClass.collectEnclosedClasses(classes)
ClassUtils.getAllSuperclasses(receiverClass).forEach { (it as Class<*>).collectEnclosedClasses(classes) }
ClassUtils.getAllInterfaces(receiverClass).forEach { (it as Class<*>).collectEnclosedClasses(classes) }
require(classes.isNotEmpty()) { "${receiverClass.name} does not contain any enclosed classes to build a CorDapp out of" }
return CustomCordapp(name = receiverClass.name, classes = classes)
}
private fun Class<*>.collectEnclosedClasses(classes: MutableSet<Class<*>>) {
val enclosedClasses = declaredClasses
if (enclosedClasses.isNotEmpty() || enclosingClass != null) {
classes += this
}
enclosedClasses.forEach { it.collectEnclosedClasses(classes) }
}
private fun getCallerClass(directCallerClass: KClass<*>): Class<*>? { private fun getCallerClass(directCallerClass: KClass<*>): Class<*>? {
val stackTrace = Throwable().stackTrace val stackTrace = Throwable().stackTrace
val index = stackTrace.indexOfLast { it.className == directCallerClass.java.name } val index = stackTrace.indexOfLast { it.className == directCallerClass.java.name }

View File

@ -19,6 +19,7 @@ import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.NodeHandle
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.User import net.corda.testing.node.User
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import org.bouncycastle.util.io.Streams import org.bouncycastle.util.io.Streams
import org.junit.Ignore import org.junit.Ignore
import org.junit.Test import org.junit.Test
@ -30,7 +31,7 @@ class HashLookupCommandTest {
fun `hash lookup command returns correct response`() { fun `hash lookup command returns correct response`() {
val user = User("u", "p", setOf(Permissions.all())) val user = User("u", "p", setOf(Permissions.all()))
driver(DriverParameters(notarySpecs = emptyList(), extraCordappPackagesToScan = listOf("net.corda.testing.contracts"))) { driver(DriverParameters(notarySpecs = emptyList(), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP))) {
val nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true) val nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true)
val node = nodeFuture.getOrThrow() val node = nodeFuture.getOrThrow()
val txId = issueTransaction(node) val txId = issueTransaction(node)