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
50 changed files with 523 additions and 495 deletions

View File

@ -23,7 +23,7 @@ import net.corda.testing.driver.DriverDSL
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver
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.junit.Test
import java.net.URL
@ -50,7 +50,7 @@ class AttachmentLoadingTests {
driver(DriverParameters(
startNodesInProcess = false,
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)),
cordappsForAllNodes = cordappsForPackages(javaClass.packageName)
cordappsForAllNodes = listOf(enclosedCordapp())
)) {
installIsolatedCordapp(ALICE_NAME)
@ -73,7 +73,7 @@ class AttachmentLoadingTests {
driver(DriverParameters(
startNodesInProcess = false,
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)),
cordappsForAllNodes = cordappsForPackages(javaClass.packageName)
cordappsForAllNodes = listOf(enclosedCordapp())
)) {
installIsolatedCordapp(ALICE_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.internal.DummyClusterSpec
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import net.corda.testing.node.internal.cordappWithPackages
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import rx.Observable
@ -43,8 +44,7 @@ class DistributedServiceTests {
invokeRpc(CordaRPCOps::stateMachinesFeed))
)
driver(DriverParameters(
extraCordappPackagesToScan = listOf("net.corda.notary.raft"),
cordappsForAllNodes = FINANCE_CORDAPPS,
cordappsForAllNodes = FINANCE_CORDAPPS + cordappWithPackages("net.corda.notary.raft"),
notarySpecs = listOf(NotarySpec(
DUMMY_NOTARY_NAME,
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.driver
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 java.time.Instant
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`() {
driver(DriverParameters(
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 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.driver
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 kotlin.test.assertEquals
@ -76,9 +78,10 @@ class LargeTransactionsTest {
val bigFile2 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 1, "b")
val bigFile3 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 2, "c")
val bigFile4 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 3, "d")
driver(DriverParameters(
startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
networkParameters = testNetworkParameters(maxMessageSize = 15.MB.toInt(), maxTransactionSize = 13.MB.toInt())
)) {
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.sequence
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.InternalMockNodeParameters
import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.testActor
import org.apache.commons.io.IOUtils
import org.assertj.core.api.Assertions.*
@ -94,7 +94,7 @@ class CordaRPCOpsImplTest {
@Before
fun setup() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.finance"))
mockNet = InternalMockNetwork(cordappsForAllNodes = FINANCE_CORDAPPS)
aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME))
rpc = aliceNode.rpcOps
CURRENT_RPC_CONTEXT.set(RpcAuthContext(InvocationContext.rpc(testActor()), buildSubject("TEST_USER", emptySet())))

View File

@ -1,11 +1,11 @@
package net.corda.node.internal
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.InvocationOrigin
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.ServiceHub
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.node.internal.cordapp.DummyRPCFlow
import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
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.Before
import org.junit.Test
@ -28,69 +31,13 @@ import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
@StartableByService
class DummyServiceFlow : FlowLogic<InvocationContext>() {
companion object {
object TEST_STEP : ProgressTracker.Step("Custom progress step")
}
override val progressTracker: ProgressTracker = ProgressTracker(TEST_STEP)
@Suspendable
override fun call(): InvocationContext {
// We call a subFlow, otehrwise there is no chance to subscribe to the ProgressTracker
subFlow(CashIssueFlow(100.DOLLARS, OpaqueBytes.of(1), serviceHub.networkMapCache.notaryIdentities.first()))
progressTracker.currentStep = TEST_STEP
return stateMachine.context
}
}
@CordaService
class TestCordaService(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() {
fun startServiceFlow() {
val handle = appServiceHub.startFlow(DummyServiceFlow())
val context = handle.returnValue.get()
assertEquals(this.javaClass.name, (context.origin as InvocationOrigin.Service).serviceClassName)
}
fun startServiceFlowAndTrack() {
val handle = appServiceHub.startTrackedFlow(DummyServiceFlow())
val count = AtomicInteger(0)
val subscriber = handle.progress.subscribe { count.incrementAndGet() }
handle.returnValue.get()
// Simply prove some progress was made.
// The actual number is currently 11, but don't want to hard code an implementation detail.
assertTrue(count.get() > 1)
subscriber.unsubscribe()
}
}
@CordaService
class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() {
fun startInvalidRPCFlow() {
val handle = appServiceHub.startFlow(DummyRPCFlow())
handle.returnValue.get()
}
}
@CordaService
class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken()
@CordaService
class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
init {
val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED)
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"))
mockNet = MockNetwork(MockNetworkParameters(threadPerNode = true, cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, enclosedCordapp())))
nodeA = mockNet.createNode()
mockNet.startNodes()
}
@ -139,4 +86,60 @@ class CordaServiceTest {
fun `Can query vault service in constructor`() {
nodeA.services.cordaService(VaultQueryService::class.java)
}
@StartableByService
class DummyServiceFlow : FlowLogic<InvocationContext>() {
companion object {
object TEST_STEP : ProgressTracker.Step("Custom progress step")
}
override val progressTracker: ProgressTracker = ProgressTracker(TEST_STEP)
@Suspendable
override fun call(): InvocationContext {
// We call a subFlow, otehrwise there is no chance to subscribe to the ProgressTracker
subFlow(CashIssueFlow(100.DOLLARS, OpaqueBytes.of(1), serviceHub.networkMapCache.notaryIdentities.first()))
progressTracker.currentStep = TEST_STEP
return stateMachine.context
}
}
@CordaService
class TestCordaService(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() {
fun startServiceFlow() {
val handle = appServiceHub.startFlow(DummyServiceFlow())
val context = handle.returnValue.get()
assertEquals(this.javaClass.name, (context.origin as InvocationOrigin.Service).serviceClassName)
}
fun startServiceFlowAndTrack() {
val handle = appServiceHub.startTrackedFlow(DummyServiceFlow())
val count = AtomicInteger(0)
val subscriber = handle.progress.subscribe { count.incrementAndGet() }
handle.returnValue.get()
// Simply prove some progress was made.
// The actual number is currently 11, but don't want to hard code an implementation detail.
assertTrue(count.get() > 1)
subscriber.unsubscribe()
}
}
@CordaService
class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() {
fun startInvalidRPCFlow() {
val handle = appServiceHub.startFlow(DummyRPCFlow())
handle.returnValue.get()
}
}
@CordaService
class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken()
@CordaService
class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
init {
val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED)
serviceHub.vaultService.trackBy(ContractState::class.java, criteria)
}
}
}

View File

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

View File

@ -70,13 +70,11 @@ import kotlin.test.assertTrue
@RunWith(Parameterized::class)
class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
companion object {
private val cordappPackages = listOf("net.corda.finance.contracts", "net.corda.finance.schemas")
@JvmStatic
@Parameterized.Parameters(name = "Anonymous = {0}")
fun data(): Collection<Boolean> = listOf(true, false)
private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
private val DUMMY_NOTARY get() = dummyNotary.party
}
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 in the unit test thread exclusively to speed things up, ensure deterministic results and
// 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 notary = mockNet.defaultNotaryIdentity
notaryNode.services.ledger(notary) {
@ -149,7 +147,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test(expected = InsufficientBalanceException::class)
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
notaryNode.services.ledger(notaryNode.info.singleIdentity()) {
val aliceNode = mockNet.createPartyNode(ALICE_NAME)
@ -205,7 +203,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
fun `shutdown and restore`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages))
mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
val notaryNode = mockNet.defaultNotaryNode
val notary = mockNet.defaultNotaryIdentity
notaryNode.services.ledger(notary) {
@ -314,7 +312,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
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 aliceNode = makeNodeWithTracking(ALICE_NAME)
val bobNode = makeNodeWithTracking(BOB_NAME)
@ -417,7 +415,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
fun `track works`() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages))
mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
val notaryNode = mockNet.defaultNotaryNode
val aliceNode = makeNodeWithTracking(ALICE_NAME)
val bobNode = makeNodeWithTracking(BOB_NAME)
@ -498,7 +496,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
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) {
runWithError(true, false, "at least one cash input")
}
@ -506,7 +504,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
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) {
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.flows.*
import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.contextLogger
import net.corda.core.utilities.getOrThrow
@ -42,7 +41,7 @@ class ScheduledFlowsDrainingModeTest {
@Before
fun setup() {
mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
threadPerNode = true
)
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.StateMachineRunId
import net.corda.core.internal.cordapp.CordappResolver
import net.corda.core.internal.packageName
import net.corda.core.toFuture
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
@ -43,7 +42,7 @@ class FinalityHandlerTest {
legalName = BOB_NAME,
// 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.
additionalCordapps = setOf(cordappWithPackages(javaClass.packageName).copy(targetPlatformVersion = 3))
additionalCordapps = setOf(DUMMY_CONTRACTS_CORDAPP.copy(targetPlatformVersion = 3))
))
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.dummyCommand
import net.corda.testing.core.singleIdentity
import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkNotarySpec
import net.corda.testing.node.MockNodeParameters
import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.*
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.After
import org.junit.Before
@ -47,10 +45,10 @@ class NotaryChangeTests {
@Before
fun setUp() {
mockNet = MockNetwork(
mockNet = MockNetwork(MockNetworkParameters(
notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName), MockNetworkNotarySpec(newNotaryName)),
cordappPackages = listOf("net.corda.testing.contracts")
)
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP)
))
clientNodeA = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME))
clientNodeB = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
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.FlowLogic
import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.services.queryBy
import net.corda.core.transactions.SignedTransaction
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.contracts.asset.Cash
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.startFlow
import org.assertj.core.api.Assertions.assertThat
@ -24,11 +23,7 @@ import rx.schedulers.Schedulers
import java.util.concurrent.CountDownLatch
class ServiceHubConcurrentUsageTest {
private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(
"net.corda.finance.schemas",
"net.corda.node.services.vault.VaultQueryExceptionsTests",
Cash::class.packageName
))
private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP))
@After
fun stopNodes() {
@ -42,7 +37,7 @@ class ServiceHubConcurrentUsageTest {
val initiatingFlow = TestFlow(mockNet.defaultNotaryIdentity)
val node = mockNet.createPartyNode()
node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe { _ ->
node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe {
try {
node.services.vaultService.queryBy<ContractState>().states
successful = true

View File

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

View File

@ -6,7 +6,6 @@ import net.corda.core.context.InvocationOrigin
import net.corda.core.contracts.*
import net.corda.core.flows.*
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.queryBy
import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria
@ -112,7 +111,7 @@ class ScheduledFlowTests {
@Before
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))
bobNode = mockNet.createNode(InternalMockNodeParameters(legalName = BOB_NAME))
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.MockNetworkParameters
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 org.junit.After
import org.junit.Before
@ -43,7 +43,7 @@ class ExposeJpaToFlowsTests {
@Before
fun setUp() {
mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = cordappsForPackages(javaClass.packageName)))
mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(enclosedCordapp())))
val (db, mockServices) = MockServices.makeTestDatabaseAndMockServices(
cordappPackages = listOf(javaClass.packageName),
identityService = makeTestIdentityService(myself.identity),

View File

@ -2,8 +2,6 @@ package net.corda.node.services.persistence
import co.paralleluniverse.fibers.Suspendable
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.transactions.TransactionBuilder
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.testing.core.BOC_NAME
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.MockNetworkParameters
import net.corda.testing.node.StartedMockNode
import net.corda.testing.node.internal.FINANCE_CORDAPPS
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -48,9 +48,7 @@ class HibernateColumnConverterTests {
@Before
fun start() {
mockNet = MockNetwork(
servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin(),
cordappPackages = listOf("net.corda.finance.contracts.asset", "net.corda.finance.schemas"))
mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS))
bankOfCordaNode = mockNet.createPartyNode(BOC_NAME)
bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME)
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.flows.*
import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.StatesToRecord
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker
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.BOB_NAME
import net.corda.testing.core.singleIdentity
import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappWithPackages
import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow
import org.junit.After
import org.junit.Before
@ -25,15 +29,15 @@ import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class ObserverNodeTransactionTests {
private lateinit var mockNet: InternalMockNetwork
@Before
fun start() {
mockNet = InternalMockNetwork(
cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)),
cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()),
networkSendManuallyPumped = false,
threadPerNode = true)
threadPerNode = true
)
}
@After
@ -50,15 +54,15 @@ class ObserverNodeTransactionTests {
fun buildTransactionChain(initialMessage: MessageData, chainLength: Int) {
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)
}.singleOrNull()
}
for (_i in 0.until(chainLength -1 )) {
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)
}.singleOrNull()
}
}
}
@ -86,101 +90,98 @@ class ObserverNodeTransactionTests {
val outputMessage = MessageData("AAAA")
checkObserverTransactions(outputMessage)
}
}
@StartableByRPC
class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic<SignedTransaction>() {
companion object {
object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.")
object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.")
object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") {
override fun childProgressTracker() = FinalityFlow.tracker()
@StartableByRPC
class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic<SignedTransaction>() {
companion object {
object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.")
object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.")
object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") {
override fun childProgressTracker() = FinalityFlow.tracker()
}
fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION)
}
fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION)
override val progressTracker = tracker()
@Suspendable
override fun call(): SignedTransaction {
progressTracker.currentStep = GENERATING_TRANSACTION
val messageState = MessageChainState(message = message, by = ourIdentity)
val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), txCommand)
progressTracker.currentStep = VERIFYING_TRANSACTION
txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify()
progressTracker.currentStep = SIGNING_TRANSACTION
val signedTx = serviceHub.signInitialTransaction(txBuilder)
progressTracker.currentStep = FINALISING_TRANSACTION
return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker()))
}
}
override val progressTracker = tracker()
@StartableByRPC
class ContinueMessageChainFlow(private val stateRef: StateAndRef<MessageChainState>,
private val notary: Party) : FlowLogic<SignedTransaction>() {
companion object {
object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.")
object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.")
object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") {
override fun childProgressTracker() = FinalityFlow.tracker()
}
@Suspendable
override fun call(): SignedTransaction {
progressTracker.currentStep = GENERATING_TRANSACTION
val messageState = MessageChainState(message = message, by = ourIdentity)
val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), txCommand)
progressTracker.currentStep = VERIFYING_TRANSACTION
txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify()
progressTracker.currentStep = SIGNING_TRANSACTION
val signedTx = serviceHub.signInitialTransaction(txBuilder)
progressTracker.currentStep = FINALISING_TRANSACTION
return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker()))
}
}
@StartableByRPC
class ContinueMessageChainFlow(private val stateRef: StateAndRef<MessageChainState>,
private val notary: Party) : FlowLogic<SignedTransaction>() {
companion object {
object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.")
object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.")
object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.")
object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") {
override fun childProgressTracker() = FinalityFlow.tracker()
fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION)
}
fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION)
override val progressTracker = tracker()
@Suspendable
override fun call(): SignedTransaction {
progressTracker.currentStep = GENERATING_TRANSACTION
val oldMessageState = stateRef.state.data
val messageState = MessageChainState(MessageData(oldMessageState.message.value + "A"),
ourIdentity,
stateRef.state.data.linearId)
val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(
StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID),
txCommand,
stateRef)
progressTracker.currentStep = VERIFYING_TRANSACTION
txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify()
progressTracker.currentStep = SIGNING_TRANSACTION
val signedTx = serviceHub.signInitialTransaction(txBuilder)
progressTracker.currentStep = FINALISING_TRANSACTION
return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker()))
}
}
override val progressTracker = tracker()
@InitiatingFlow
@StartableByRPC
class ReportToCounterparty(private val regulator: Party, private val signedTx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val session = initiateFlow(regulator)
subFlow(SendTransactionFlow(session, signedTx))
}
}
@Suspendable
override fun call(): SignedTransaction {
progressTracker.currentStep = GENERATING_TRANSACTION
val oldMessageState = stateRef.state.data
val messageState = MessageChainState(MessageData(oldMessageState.message.value + "A"),
ourIdentity,
stateRef.state.data.linearId)
val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(
StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID),
txCommand,
stateRef)
progressTracker.currentStep = VERIFYING_TRANSACTION
txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify()
progressTracker.currentStep = SIGNING_TRANSACTION
val signedTx = serviceHub.signInitialTransaction(txBuilder)
progressTracker.currentStep = FINALISING_TRANSACTION
return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker()))
@InitiatedBy(ReportToCounterparty::class)
class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE))
}
}
}
@InitiatingFlow
@StartableByRPC
class ReportToCounterparty(
private val regulator: Party,
private val signedTx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val session = initiateFlow(regulator)
subFlow(SendTransactionFlow(session, signedTx))
}
}
@InitiatedBy(ReportToCounterparty::class)
class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
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.flows.*
import net.corda.core.identity.Party
import net.corda.core.internal.packageName
import net.corda.core.node.StatesToRecord
import net.corda.core.node.services.Vault
import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
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.BOB_NAME
import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.cordappWithPackages
import net.corda.testing.node.internal.enclosedCordapp
import net.corda.testing.node.internal.startFlow
import org.junit.After
import org.junit.Before
@ -30,9 +34,10 @@ class TransactionOrderingTests {
@Before
fun start() {
mockNet = InternalMockNetwork(
cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)),
cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()),
networkSendManuallyPumped = false,
threadPerNode = true)
threadPerNode = true
)
}
@After
@ -91,25 +96,26 @@ class TransactionOrderingTests {
val bobStates = bob.services.vaultService.queryBy(MessageChainState::class.java, queryCriteria)
assertEquals(3, bobStates.states.size)
}
}
@InitiatingFlow
@StartableByRPC
class SendTx(private val party: Party,
private val stx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val session = initiateFlow(party)
subFlow(SendTransactionFlow(session, stx))
session.receive<Unit>()
@InitiatingFlow
@StartableByRPC
class SendTx(private val party: Party,
private val stx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val session = initiateFlow(party)
subFlow(SendTransactionFlow(session, stx))
session.receive<Unit>()
}
}
@InitiatedBy(SendTx::class)
class ReceiveTx(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ONLY_RELEVANT))
otherSideSession.send(Unit)
}
}
}
@InitiatedBy(SendTx::class)
class ReceiveTx(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ONLY_RELEVANT))
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.services.CordaService
import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.testing.node.internal.InternalMockNetwork
import net.corda.testing.node.internal.TestStartedNode
import net.corda.testing.node.internal.cordappsForPackages
import net.corda.testing.node.internal.startFlow
import net.corda.testing.node.internal.*
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -28,7 +25,7 @@ class FlowAsyncOperationTests {
@Before
fun setup() {
mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.node.services.statemachine"),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()),
notarySpecs = emptyList()
)
aliceNode = mockNet.createNode()

View File

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

View File

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

View File

@ -40,7 +40,7 @@ class FlowFrameworkTripartyTests {
@Before
fun setUpGlobalMockNet() {
mockNet = InternalMockNetwork(
cordappsForAllNodes = cordappsForPackages("net.corda.finance.contracts", "net.corda.testing.contracts"),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
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.internal.IdempotentFlow
import net.corda.core.internal.TimedFlow
import net.corda.core.internal.packageName
import net.corda.core.utilities.seconds
import net.corda.node.services.config.FlowTimeoutConfiguration
import net.corda.testing.node.internal.*
@ -33,7 +32,7 @@ class IdempotentFlowTests {
@Before
fun start() {
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName))
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp()))
nodeA = mockNet.createNode(InternalMockNodeParameters(
legalName = CordaX500Name("Alice", "AliceCorp", "GB"),
configOverrides = {

View File

@ -7,7 +7,6 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party
import net.corda.core.internal.FlowStateMachine
import net.corda.core.internal.concurrent.flatMap
import net.corda.core.internal.packageName
import net.corda.core.messaging.MessageRecipients
import net.corda.core.utilities.UntrustworthyData
import net.corda.core.utilities.getOrThrow
@ -39,7 +38,7 @@ class RetryFlowMockTest {
@Before
fun start() {
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName))
mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp()))
nodeA = mockNet.createNode()
nodeB = mockNet.createNode()
mockNet.startNodes()
@ -180,108 +179,109 @@ class RetryFlowMockTest {
nodeA.smm.killFlow(flow.id)
assertThat(nodeA.smm.flowHospital.track().snapshot).isEmpty()
}
}
class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint")
class RetryCausingError : SQLException("deadlock")
class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint")
class RetryFlow(private val i: Int) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
class RetryCausingError : SQLException("deadlock")
class RetryFlow(private val i: Int) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
}
@Suspendable
override fun call() {
logger.info("Hello $count")
if (count++ < i) {
if (i == Int.MAX_VALUE) {
throw LimitedRetryCausingError()
} else {
throw RetryCausingError()
}
}
}
}
@Suspendable
override fun call() {
logger.info("Hello $count")
if (count++ < i) {
if (i == Int.MAX_VALUE) {
throw LimitedRetryCausingError()
} else {
@InitiatingFlow
class SendAndRetryFlow(private val i: Int, private val other: Party) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
}
@Suspendable
override fun call() {
logger.info("Sending...")
val session = initiateFlow(other)
session.send("Boo")
if (count++ < i) {
throw RetryCausingError()
}
}
}
}
@InitiatingFlow
class SendAndRetryFlow(private val i: Int, private val other: Party) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
}
@Suspendable
override fun call() {
logger.info("Sending...")
val session = initiateFlow(other)
session.send("Boo")
if (count++ < i) {
throw RetryCausingError()
}
}
}
@Suppress("unused")
@InitiatedBy(SendAndRetryFlow::class)
class ReceiveFlow2(private val other: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val received = other.receive<String>().unwrap { it }
logger.info("Received... $received")
}
}
@InitiatingFlow
class KeepSendingFlow(private val i: Int, private val other: Party) : FlowLogic<Unit>() {
companion object {
val count = AtomicInteger(0)
}
@Suspendable
override fun call() {
val session = initiateFlow(other)
session.send(i.toString())
do {
logger.info("Sending... $count")
session.send("Boo")
} while (count.getAndIncrement() < i)
}
}
@Suppress("unused")
@InitiatedBy(KeepSendingFlow::class)
class ReceiveFlow3(private val other: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
var count = other.receive<String>().unwrap { it.toInt() }
while (count-- > 0) {
@Suppress("unused")
@InitiatedBy(SendAndRetryFlow::class)
class ReceiveFlow2(private val other: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val received = other.receive<String>().unwrap { it }
logger.info("Received... $received $count")
logger.info("Received... $received")
}
}
}
class RetryInsertFlow(private val i: Int) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
@InitiatingFlow
class KeepSendingFlow(private val i: Int, private val other: Party) : FlowLogic<Unit>() {
companion object {
val count = AtomicInteger(0)
}
@Suspendable
override fun call() {
val session = initiateFlow(other)
session.send(i.toString())
do {
logger.info("Sending... $count")
session.send("Boo")
} while (count.getAndIncrement() < i)
}
}
@Suspendable
override fun call() {
logger.info("Hello")
doInsert()
// Checkpoint so we roll back to here
FlowLogic.sleep(Duration.ofSeconds(0))
if (count++ < i) {
@Suppress("unused")
@InitiatedBy(KeepSendingFlow::class)
class ReceiveFlow3(private val other: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
var count = other.receive<String>().unwrap { it.toInt() }
while (count-- > 0) {
val received = other.receive<String>().unwrap { it }
logger.info("Received... $received $count")
}
}
}
class RetryInsertFlow(private val i: Int) : FlowLogic<Unit>() {
companion object {
@Volatile
var count = 0
}
@Suspendable
override fun call() {
logger.info("Hello")
doInsert()
// Checkpoint so we roll back to here
FlowLogic.sleep(Duration.ofSeconds(0))
if (count++ < i) {
doInsert()
}
}
private fun doInsert() {
val tx = DBTransactionStorage.DBTransaction("Foo")
contextTransaction.session.save(tx)
}
}
private fun doInsert() {
val tx = DBTransactionStorage.DBTransaction("Foo")
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.singleIdentity
import net.corda.testing.node.MockNetwork
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.MockNodeParameters
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.assertThatThrownBy
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -37,10 +41,12 @@ class MaxTransactionSizeTests {
@Before
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))
bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
bobNode.registerInitiatedFlow(ReceiveLargeTransactionFlow::class.java)
notaryNode = mockNet.defaultNotaryNode
notary = mockNet.defaultNotaryIdentity
alice = aliceNode.info.singleIdentity()
@ -90,11 +96,10 @@ class MaxTransactionSizeTests {
assertEquals(hash1, bigFile1.sha256)
SendLargeTransactionFlow(notary, bob, hash1, hash2, hash3, hash4, verify = false)
}
assertFailsWith<UnexpectedFlowEndException> {
val future = aliceNode.startFlow(flow)
mockNet.runNetwork()
future.getOrThrow()
}
val future = aliceNode.startFlow(flow)
mockNet.runNetwork()
assertThatThrownBy { future.getOrThrow() }.hasMessageContaining("Transaction exceeded network's maximum transaction size limit")
}
private fun StartedMockNode.importAttachment(inputStream: InputStream): AttachmentId {
@ -133,7 +138,11 @@ class MaxTransactionSizeTests {
class ReceiveLargeTransactionFlow(private val otherSide: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(ReceiveTransactionFlow(otherSide))
try {
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).
otherSide.send(Unit)
}

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,6 @@ import net.corda.core.contracts.*
import net.corda.core.flows.*
import net.corda.core.identity.AbstractParty
import net.corda.core.internal.FlowStateMachine
import net.corda.core.internal.packageName
import net.corda.core.internal.uncheckedCast
import net.corda.core.node.ServicesForResolution
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.internal.rigorousMock
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 org.junit.After
import org.junit.Test
@ -79,7 +78,7 @@ class VaultSoftLockManagerTest {
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) {
override fun makeVaultService(keyManagementService: KeyManagementService,
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.identity.AbstractParty
@ -48,7 +48,7 @@ object MessageChainSchemaV1 : MappedSchema(
) : 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 {
override fun verify(tx: LedgerTransaction) {
@ -67,4 +67,3 @@ open class MessageChainContract : Contract {
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.nodeapi.internal.DevIdentityGenerator
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.contracts.DummyContract
import net.corda.testing.core.dummyCommand
@ -60,7 +57,7 @@ class BFTNotaryServiceTests {
@BeforeClass
@JvmStatic
fun before() {
mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"))
mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP))
val clusterSize = minClusterSize(1)
val started = startBftClusterAndNode(clusterSize, mockNet)
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.node.ClusterSpec
import net.corda.testing.node.NotarySpec
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
import org.junit.Test
import java.util.*
import kotlin.test.assertEquals
@ -32,7 +33,7 @@ class RaftNotaryServiceTests {
fun `detect double spend`() {
driver(DriverParameters(
startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))
)) {
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`() {
driver(DriverParameters(
startNodesInProcess = true,
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"),
cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP),
notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))
)) {
val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow()