在 Corda 流测试中,如何让模块化的 cordapps 只分配给各方?

In Corda flow tests, how to get the modularized cordapps assigned only to the respective parties?

根据 Corda 编码指南,我已将模块分离为契约和工作流 - 通用。有特定于一方的工作流模块,如 workflows-party1、workflows-part2 等。现在我只想将这些工作流程提供给流程测试中的那个特定节点。如何实现?

Corda v4中可以这样实现

    private val network = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(
            TestCordapp.findCordapp("com.template.contracts"),
            TestCordapp.findCordapp("com.template.common")),
            networkParameters = testNetworkParameters(minimumPlatformVersion = 4),
            notarySpecs = listOf(MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB")))))

    private val party1 = network.createNode(MockNodeParameters(
            additionalCordapps = listOf(TestCordapp.findCordapp("com.template.workflows.party1")),
            legalName = CordaX500Name.parse("O=Party,L=London,C=GB")))

另一个答案是实现此目的的一种方法,另一种是使用 DriverDSL(取决于您编写测试的方式)

driver(DriverParameters(startNodesInProcess = false, inMemoryDB = false)) {
  val charlie = startNode(
    NodeParameters(
      providedName = CHARLIE_NAME,
      rpcUsers = listOf(rpcUser),
      // important line
      additionalCordapps = cordappsForPackages("package name")
    )
  ).getOrThrow()
  // stuff
}

两种解决方案都有效