mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Cleanup of mock network pre-NetworkParameters (#1802)
* MockNode rename overrideServices to notaryIdentity Permit only one override of service. * MockNetwork: force creation of NetworkMapNode Tests cleanup: decouple normal nodes and network map. NetworkMap node is created as first.
This commit is contained in:
parent
33ba145149
commit
66d78fcf65
@ -42,12 +42,12 @@ class IdentitySyncFlowTests {
|
||||
@Test
|
||||
fun `sync confidential identities`() {
|
||||
// Set up values we'll need
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val alice: Party = aliceNode.services.myInfo.chooseIdentity()
|
||||
val bob: Party = bobNode.services.myInfo.chooseIdentity()
|
||||
val notary = notaryNode.services.getDefaultNotary()
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
bobNode.internals.registerInitiatedFlow(Receive::class.java)
|
||||
|
||||
// Alice issues then pays some cash to a new confidential identity that Bob doesn't know about
|
||||
@ -73,9 +73,9 @@ class IdentitySyncFlowTests {
|
||||
fun `don't offer other's identities confidential identities`() {
|
||||
// Set up values we'll need
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val charlieNode = mockNet.createPartyNode(notaryNode.network.myAddress, CHARLIE.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val charlieNode = mockNet.createPartyNode(CHARLIE.name)
|
||||
val alice: Party = aliceNode.services.myInfo.chooseIdentity()
|
||||
val bob: Party = bobNode.services.myInfo.chooseIdentity()
|
||||
val charlie: Party = charlieNode.services.myInfo.chooseIdentity()
|
||||
|
@ -23,11 +23,10 @@ class SwapIdentitiesFlowTests {
|
||||
|
||||
// Set up values we'll need
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val alice: Party = aliceNode.services.myInfo.chooseIdentity()
|
||||
val bob: Party = bobNode.services.myInfo.chooseIdentity()
|
||||
mockNet.registerIdentities()
|
||||
|
||||
// Run the flows
|
||||
val requesterFlow = aliceNode.services.startFlow(SwapIdentitiesFlow(bob))
|
||||
|
@ -20,15 +20,14 @@ import static org.junit.Assert.fail;
|
||||
public class FlowsInJavaTest {
|
||||
|
||||
private final MockNetwork mockNet = new MockNetwork();
|
||||
private StartedNode<MockNetwork.MockNode> notaryNode;
|
||||
private StartedNode<MockNetwork.MockNode> aliceNode;
|
||||
private StartedNode<MockNetwork.MockNode> bobNode;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
notaryNode = mockNet.createNotaryNode();
|
||||
aliceNode = mockNet.createPartyNode(notaryNode.getNetwork().getMyAddress(), TestConstants.getALICE().getName());
|
||||
bobNode = mockNet.createPartyNode(notaryNode.getNetwork().getMyAddress(), TestConstants.getBOB().getName());
|
||||
mockNet.createNotaryNode();
|
||||
aliceNode = mockNet.createPartyNode(TestConstants.getALICE().getName());
|
||||
bobNode = mockNet.createPartyNode(TestConstants.getBOB().getName());
|
||||
mockNet.runNetwork();
|
||||
// Ensure registration was successful
|
||||
aliceNode.getInternals().getNodeReadyFuture().get();
|
||||
|
@ -56,9 +56,9 @@ class AttachmentTests {
|
||||
|
||||
@Test
|
||||
fun `download and store`() {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
|
||||
// Ensure that registration was successful before progressing any further
|
||||
mockNet.runNetwork()
|
||||
@ -94,9 +94,9 @@ class AttachmentTests {
|
||||
|
||||
@Test
|
||||
fun `missing`() {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
|
||||
// Ensure that registration was successful before progressing any further
|
||||
mockNet.runNetwork()
|
||||
@ -120,14 +120,14 @@ class AttachmentTests {
|
||||
val aliceNode = mockNet.createNode(legalName = ALICE.name, nodeFactory = object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override fun start() = super.start().apply { attachments.checkAttachmentsOnLoad = false }
|
||||
}
|
||||
}
|
||||
}, advertisedServices = *arrayOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
val bobNode = mockNet.createNode(aliceNode.network.myAddress, legalName = BOB.name)
|
||||
val bobNode = mockNet.createNode(legalName = BOB.name)
|
||||
|
||||
// Ensure that registration was successful before progressing any further
|
||||
mockNet.runNetwork()
|
||||
|
@ -34,9 +34,9 @@ class CollectSignaturesFlowTests {
|
||||
setCordappPackages("net.corda.testing.contracts")
|
||||
mockNet = MockNetwork()
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
charlieNode = mockNet.createPartyNode(notaryNode.network.myAddress, CHARLIE.name)
|
||||
aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(BOB.name)
|
||||
charlieNode = mockNet.createPartyNode(CHARLIE.name)
|
||||
mockNet.runNetwork()
|
||||
notary = notaryNode.services.getDefaultNotary()
|
||||
aliceNode.internals.ensureRegistered()
|
||||
|
@ -43,8 +43,8 @@ class ContractUpgradeFlowTest {
|
||||
setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows")
|
||||
mockNet = MockNetwork()
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(BOB.name)
|
||||
|
||||
// Process registration
|
||||
mockNet.runNetwork()
|
||||
|
@ -25,9 +25,9 @@ class FinalityFlowTests {
|
||||
fun setup() {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork()
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
mockNet.createNotaryNode()
|
||||
aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
bobNode = mockNet.createPartyNode(BOB.name)
|
||||
mockNet.runNetwork()
|
||||
aliceNode.internals.ensureRegistered()
|
||||
notary = aliceNode.services.getDefaultNotary()
|
||||
|
@ -39,8 +39,8 @@ class ResolveTransactionsFlowTest {
|
||||
setCordappPackages("net.corda.testing.contracts")
|
||||
mockNet = MockNetwork()
|
||||
notaryNode = mockNet.createNotaryNode()
|
||||
megaCorpNode = mockNet.createPartyNode(notaryNode.network.myAddress, MEGA_CORP.name)
|
||||
miniCorpNode = mockNet.createPartyNode(notaryNode.network.myAddress, MINI_CORP.name)
|
||||
megaCorpNode = mockNet.createPartyNode(MEGA_CORP.name)
|
||||
miniCorpNode = mockNet.createPartyNode(MINI_CORP.name)
|
||||
megaCorpNode.internals.registerInitiatedFlow(TestResponseFlow::class.java)
|
||||
miniCorpNode.internals.registerInitiatedFlow(TestResponseFlow::class.java)
|
||||
mockNet.runNetwork()
|
||||
|
@ -70,7 +70,7 @@ class AttachmentSerializationTest {
|
||||
fun setUp() {
|
||||
mockNet = MockNetwork()
|
||||
server = mockNet.createNode()
|
||||
client = mockNet.createNode(server.network.myAddress)
|
||||
client = mockNet.createNode()
|
||||
client.internals.disableDBCloseOnStop() // Otherwise the in-memory database may disappear (taking the checkpoint with it) while we reboot the client.
|
||||
mockNet.runNetwork()
|
||||
server.internals.ensureRegistered()
|
||||
@ -159,11 +159,11 @@ class AttachmentSerializationTest {
|
||||
|
||||
private fun rebootClientAndGetAttachmentContent(checkAttachmentsOnLoad: Boolean = true): String {
|
||||
client.dispose()
|
||||
client = mockNet.createNode(server.network.myAddress, client.internals.id, object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
client = mockNet.createNode(client.internals.id, object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override fun start() = super.start().apply { attachments.checkAttachmentsOnLoad = checkAttachmentsOnLoad }
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import java.util.*
|
||||
class CustomVaultQueryTest {
|
||||
|
||||
lateinit var mockNet: MockNetwork
|
||||
lateinit var notaryNode: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeA: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeB: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var notary: Party
|
||||
@ -32,12 +31,12 @@ class CustomVaultQueryTest {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork(threadPerNode = true)
|
||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||
notaryNode = mockNet.createNode(
|
||||
mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
overrideServices = mapOf(notaryService to DUMMY_NOTARY_KEY),
|
||||
notaryIdentity = notaryService to DUMMY_NOTARY_KEY,
|
||||
advertisedServices = *arrayOf(notaryService))
|
||||
nodeA = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeB = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeA = mockNet.createPartyNode()
|
||||
nodeB = mockNet.createPartyNode()
|
||||
|
||||
nodeA.internals.registerInitiatedFlow(TopupIssuerFlow.TopupIssuer::class.java)
|
||||
nodeA.internals.installCordaService(CustomVaultQuery.Service::class.java)
|
||||
|
@ -20,7 +20,6 @@ import kotlin.test.assertEquals
|
||||
|
||||
class FxTransactionBuildTutorialTest {
|
||||
lateinit var mockNet: MockNetwork
|
||||
lateinit var notaryNode: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeA: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeB: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var notary: Party
|
||||
@ -30,12 +29,12 @@ class FxTransactionBuildTutorialTest {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork(threadPerNode = true)
|
||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||
notaryNode = mockNet.createNode(
|
||||
mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
overrideServices = mapOf(notaryService to DUMMY_NOTARY_KEY),
|
||||
notaryIdentity = notaryService to DUMMY_NOTARY_KEY,
|
||||
advertisedServices = *arrayOf(notaryService))
|
||||
nodeA = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeB = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeA = mockNet.createPartyNode()
|
||||
nodeB = mockNet.createPartyNode()
|
||||
nodeA.internals.registerCustomSchemas(setOf(CashSchemaV1))
|
||||
nodeB.internals.registerCustomSchemas(setOf(CashSchemaV1))
|
||||
nodeB.internals.registerInitiatedFlow(ForeignExchangeRemoteFlow::class.java)
|
||||
|
@ -20,7 +20,6 @@ import kotlin.test.assertEquals
|
||||
|
||||
class WorkflowTransactionBuildTutorialTest {
|
||||
lateinit var mockNet: MockNetwork
|
||||
lateinit var notaryNode: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeA: StartedNode<MockNetwork.MockNode>
|
||||
lateinit var nodeB: StartedNode<MockNetwork.MockNode>
|
||||
|
||||
@ -35,12 +34,12 @@ class WorkflowTransactionBuildTutorialTest {
|
||||
setCordappPackages("net.corda.docs")
|
||||
mockNet = MockNetwork(threadPerNode = true)
|
||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||
notaryNode = mockNet.createNode(
|
||||
mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
overrideServices = mapOf(Pair(notaryService, DUMMY_NOTARY_KEY)),
|
||||
notaryIdentity = Pair(notaryService, DUMMY_NOTARY_KEY),
|
||||
advertisedServices = *arrayOf(notaryService))
|
||||
nodeA = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeB = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
nodeA = mockNet.createPartyNode()
|
||||
nodeB = mockNet.createPartyNode()
|
||||
nodeA.internals.registerInitiatedFlow(RecordCompletionFlow::class.java)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class CashExitFlowTests {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||
notaryNode = mockNet.createNotaryNode()
|
||||
bankOfCordaNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
bankOfCordaNode = mockNet.createPartyNode(BOC.name)
|
||||
notary = notaryNode.services.getDefaultNotary()
|
||||
bankOfCorda = bankOfCordaNode.info.chooseIdentity()
|
||||
|
||||
|
@ -33,7 +33,7 @@ class CashIssueFlowTests {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||
notaryNode = mockNet.createNotaryNode()
|
||||
bankOfCordaNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
bankOfCordaNode = mockNet.createPartyNode(BOC.name)
|
||||
bankOfCorda = bankOfCordaNode.info.chooseIdentity()
|
||||
notary = notaryNode.services.getDefaultNotary()
|
||||
mockNet.runNetwork()
|
||||
|
@ -34,7 +34,7 @@ class CashPaymentFlowTests {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||
notaryNode = mockNet.createNotaryNode()
|
||||
bankOfCordaNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
bankOfCordaNode = mockNet.createPartyNode(BOC.name)
|
||||
bankOfCorda = bankOfCordaNode.info.chooseIdentity()
|
||||
notary = notaryNode.services.getDefaultNotary()
|
||||
val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref, notary)).resultFuture
|
||||
|
@ -58,7 +58,6 @@ class BFTNotaryServiceTests {
|
||||
val notaryClusterAddresses = replicaIds.map { NetworkHostAndPort("localhost", 11000 + it * 10) }
|
||||
replicaIds.forEach { replicaId ->
|
||||
mockNet.createNode(
|
||||
node.network.myAddress,
|
||||
advertisedServices = bftNotaryService,
|
||||
configOverrides = {
|
||||
whenever(it.bftSMaRt).thenReturn(BFTSMaRtConfiguration(replicaId, false, exposeRaces))
|
||||
|
@ -67,9 +67,8 @@ class CordaRPCOpsImplTest {
|
||||
setCordappPackages("net.corda.finance.contracts.asset")
|
||||
|
||||
mockNet = MockNetwork()
|
||||
val networkMap = mockNet.createNode()
|
||||
aliceNode = mockNet.createNode(networkMapAddress = networkMap.network.myAddress)
|
||||
notaryNode = mockNet.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type), networkMapAddress = networkMap.network.myAddress)
|
||||
aliceNode = mockNet.createNode()
|
||||
notaryNode = mockNet.createNode(advertisedServices = ServiceInfo(SimpleNotaryService.type))
|
||||
rpc = CordaRPCOpsImpl(aliceNode.services, aliceNode.smm, aliceNode.database)
|
||||
CURRENT_RPC_CONTEXT.set(RpcContext(User("user", "pwd", permissions = setOf(
|
||||
startFlowPermission<CashIssueFlow>(),
|
||||
@ -77,7 +76,7 @@ class CordaRPCOpsImplTest {
|
||||
))))
|
||||
|
||||
mockNet.runNetwork()
|
||||
networkMap.internals.ensureRegistered()
|
||||
mockNet.networkMapNode.internals.ensureRegistered()
|
||||
notary = rpc.notaryIdentities().first()
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,9 @@ class InMemoryMessagingTests {
|
||||
|
||||
@Test
|
||||
fun basics() {
|
||||
val node1 = mockNet.createNode()
|
||||
val node2 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
val node3 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
val node1 = mockNet.networkMapNode
|
||||
val node2 = mockNet.createNode()
|
||||
val node3 = mockNet.createNode()
|
||||
|
||||
val bits = "test-content".toByteArray()
|
||||
var finalDelivery: Message? = null
|
||||
@ -76,9 +76,9 @@ class InMemoryMessagingTests {
|
||||
|
||||
@Test
|
||||
fun broadcast() {
|
||||
val node1 = mockNet.createNode()
|
||||
val node2 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
val node3 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
val node1 = mockNet.networkMapNode
|
||||
val node2 = mockNet.createNode()
|
||||
val node3 = mockNet.createNode()
|
||||
|
||||
val bits = "test-content".toByteArray()
|
||||
|
||||
@ -95,8 +95,8 @@ class InMemoryMessagingTests {
|
||||
*/
|
||||
@Test
|
||||
fun `skip unhandled messages`() {
|
||||
val node1 = mockNet.createNode()
|
||||
val node2 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
val node1 = mockNet.networkMapNode
|
||||
val node2 = mockNet.createNode()
|
||||
var received = 0
|
||||
|
||||
node1.network.addMessageHandler("valid_message") { _, _ ->
|
||||
|
@ -104,9 +104,9 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
|
||||
ledger(initialiseSerialization = false) {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(BOC.name)
|
||||
val notary = notaryNode.services.getDefaultNotary()
|
||||
val cashIssuer = bankNode.info.chooseIdentity().ref(1)
|
||||
val cpIssuer = bankNode.info.chooseIdentity().ref(1, 2, 3)
|
||||
@ -153,9 +153,9 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
|
||||
ledger(initialiseSerialization = false) {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(BOC.name)
|
||||
val issuer = bankNode.info.chooseIdentity().ref(1)
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
|
||||
@ -207,14 +207,11 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
mockNet = MockNetwork(false)
|
||||
ledger(initialiseSerialization = false) {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
var bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
var bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(BOC.name)
|
||||
val issuer = bankNode.info.chooseIdentity().ref(1, 2, 3)
|
||||
|
||||
// Let the nodes know about each other - normally the network map would handle this
|
||||
mockNet.registerIdentities()
|
||||
|
||||
aliceNode.database.transaction {
|
||||
aliceNode.services.identityService.verifyAndRegisterIdentity(bobNode.info.chooseIdentityAndCert())
|
||||
}
|
||||
@ -276,11 +273,11 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
|
||||
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
||||
// that Bob was waiting on before the reboot occurred.
|
||||
bobNode = mockNet.createNode(networkMapAddress, bobAddr.id, object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
bobNode = mockNet.createNode(bobAddr.id, object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
return MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, bobAddr.id, overrideServices, entropyRoot)
|
||||
return MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, bobAddr.id, notaryIdentity, entropyRoot)
|
||||
}
|
||||
}, BOB.name)
|
||||
|
||||
@ -319,14 +316,14 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
networkMapAddress: SingleMessageRecipient?,
|
||||
name: CordaX500Name): StartedNode<MockNetwork.MockNode> {
|
||||
// Create a node in the mock network ...
|
||||
return mockNet.createNode(networkMapAddress, nodeFactory = object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
return mockNet.createNode(nodeFactory = object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration,
|
||||
network: MockNetwork,
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : MockNetwork.MockNode(config, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
// That constructs a recording tx storage
|
||||
override fun makeTransactionStorage(): WritableTransactionStorage {
|
||||
return RecordingTransactionStorage(database, super.makeTransactionStorage())
|
||||
@ -349,8 +346,6 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
notaryNode.internals.ensureRegistered()
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
|
||||
mockNet.registerIdentities()
|
||||
|
||||
ledger(aliceNode.services, initialiseSerialization = false) {
|
||||
|
||||
// Insert a prospectus type attachment into the commercial paper transaction.
|
||||
@ -457,8 +452,6 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
notaryNode.internals.ensureRegistered()
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
|
||||
mockNet.registerIdentities()
|
||||
|
||||
ledger(aliceNode.services, initialiseSerialization = false) {
|
||||
// Insert a prospectus type attachment into the commercial paper transaction.
|
||||
val stream = ByteArrayOutputStream()
|
||||
@ -604,18 +597,15 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) {
|
||||
expectedMessageSubstring: String
|
||||
) {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val bobNode = mockNet.createPartyNode(BOB.name)
|
||||
val bankNode = mockNet.createPartyNode(BOC.name)
|
||||
val issuer = bankNode.info.chooseIdentity().ref(1, 2, 3)
|
||||
|
||||
mockNet.runNetwork()
|
||||
notaryNode.internals.ensureRegistered()
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
|
||||
// Let the nodes know about each other - normally the network map would handle this
|
||||
mockNet.registerIdentities()
|
||||
|
||||
val bobsBadCash = bobNode.database.transaction {
|
||||
fillUpForBuyer(bobError, issuer, bobNode.info.chooseIdentity(),
|
||||
notary).second
|
||||
|
@ -42,10 +42,9 @@ class NotaryChangeTests {
|
||||
oldNotaryNode = mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(ValidatingNotaryService.type)))
|
||||
clientNodeA = mockNet.createNode(networkMapAddress = oldNotaryNode.network.myAddress)
|
||||
clientNodeB = mockNet.createNode(networkMapAddress = oldNotaryNode.network.myAddress)
|
||||
newNotaryNode = mockNet.createNode(networkMapAddress = oldNotaryNode.network.myAddress, advertisedServices = ServiceInfo(ValidatingNotaryService.type))
|
||||
mockNet.registerIdentities()
|
||||
clientNodeA = mockNet.createNode()
|
||||
clientNodeB = mockNet.createNode()
|
||||
newNotaryNode = mockNet.createNode(advertisedServices = ServiceInfo(ValidatingNotaryService.type))
|
||||
mockNet.runNetwork() // Clear network map registration messages
|
||||
oldNotaryNode.internals.ensureRegistered()
|
||||
newNotaryParty = newNotaryNode.info.legalIdentities[1]
|
||||
|
@ -98,8 +98,8 @@ class ScheduledFlowTests {
|
||||
notaryNode = mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(ValidatingNotaryService.type)))
|
||||
val a = mockNet.createUnstartedNode(notaryNode.network.myAddress)
|
||||
val b = mockNet.createUnstartedNode(notaryNode.network.myAddress)
|
||||
val a = mockNet.createUnstartedNode()
|
||||
val b = mockNet.createUnstartedNode()
|
||||
|
||||
notaryNode.internals.ensureRegistered()
|
||||
|
||||
|
@ -50,11 +50,8 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
@Before
|
||||
fun setup() {
|
||||
mockNet = MockNetwork(defaultFactory = nodeFactory)
|
||||
mapServiceNode = mockNet.createNode(
|
||||
nodeFactory = nodeFactory,
|
||||
legalName = DUMMY_MAP.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
alice = mockNet.createNode(mapServiceNode.network.myAddress, nodeFactory = nodeFactory, legalName = ALICE.name)
|
||||
mapServiceNode = mockNet.networkMapNode
|
||||
alice = mockNet.createNode(nodeFactory = nodeFactory, legalName = ALICE.name)
|
||||
mockNet.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
}
|
||||
@ -249,7 +246,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
}
|
||||
|
||||
private fun addNewNodeToNetworkMap(legalName: CordaX500Name): StartedNode<MockNode> {
|
||||
val node = mockNet.createNode(mapServiceNode.network.myAddress, legalName = legalName)
|
||||
val node = mockNet.createNode(legalName = legalName)
|
||||
mockNet.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
return node
|
||||
@ -275,9 +272,9 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>,
|
||||
id: Int,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNode {
|
||||
return object : MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : MockNode(config, network, null, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override fun makeNetworkMapService() = NullNetworkMapService
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ class NetworkMapCacheTest {
|
||||
|
||||
@Test
|
||||
fun registerWithNetwork() {
|
||||
val mapNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(mapNode.network.myAddress, ALICE.name)
|
||||
val future = aliceNode.services.networkMapCache.addMapService(aliceNode.network, mapNode.network.myAddress, false, null)
|
||||
mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val future = aliceNode.services.networkMapCache.addMapService(aliceNode.network, mockNet.networkMapNode.network.myAddress, false, null)
|
||||
mockNet.runNetwork()
|
||||
future.getOrThrow()
|
||||
}
|
||||
@ -39,13 +39,12 @@ class NetworkMapCacheTest {
|
||||
fun `key collision`() {
|
||||
val entropy = BigInteger.valueOf(24012017L)
|
||||
val aliceNode = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = ALICE.name, entropyRoot = entropy)
|
||||
val bobNode = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = BOB.name, entropyRoot = entropy)
|
||||
assertEquals(aliceNode.info.chooseIdentity(), bobNode.info.chooseIdentity())
|
||||
|
||||
mockNet.runNetwork()
|
||||
|
||||
// Node A currently knows only about itself, so this returns node A
|
||||
assertEquals(aliceNode.services.networkMapCache.getNodesByLegalIdentityKey(aliceNode.info.chooseIdentity().owningKey).singleOrNull(), aliceNode.info)
|
||||
val bobNode = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = BOB.name, entropyRoot = entropy)
|
||||
assertEquals(aliceNode.info.chooseIdentity(), bobNode.info.chooseIdentity())
|
||||
|
||||
aliceNode.services.networkMapCache.addNode(bobNode.info)
|
||||
// The details of node B write over those for node A
|
||||
@ -55,7 +54,7 @@ class NetworkMapCacheTest {
|
||||
@Test
|
||||
fun `getNodeByLegalIdentity`() {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val notaryCache: NetworkMapCache = notaryNode.services.networkMapCache
|
||||
val expected = aliceNode.info
|
||||
|
||||
@ -69,7 +68,7 @@ class NetworkMapCacheTest {
|
||||
@Test
|
||||
fun `remove node from cache`() {
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val aliceNode = mockNet.createPartyNode(ALICE.name)
|
||||
val notaryLegalIdentity = notaryNode.info.chooseIdentity()
|
||||
val alice = aliceNode.info.chooseIdentity()
|
||||
val notaryCache = notaryNode.services.networkMapCache as PersistentNetworkMapCache
|
||||
|
@ -32,9 +32,9 @@ class PersistentNetworkMapServiceTest : AbstractNetworkMapServiceTest<Persistent
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>,
|
||||
id: Int,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNode {
|
||||
return object : MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : MockNode(config, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override fun makeNetworkMapService() = SwizzleNetworkMapService(services)
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class FlowFrameworkTests {
|
||||
setCordappPackages("net.corda.finance.contracts", "net.corda.testing.contracts")
|
||||
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin())
|
||||
node1 = mockNet.createNode()
|
||||
node2 = mockNet.createNode(networkMapAddress = node1.network.myAddress)
|
||||
node2 = mockNet.createNode()
|
||||
|
||||
mockNet.runNetwork()
|
||||
node1.internals.ensureRegistered()
|
||||
@ -87,17 +87,15 @@ class FlowFrameworkTests {
|
||||
// We intentionally create our own notary and ignore the one provided by the network
|
||||
val notaryKeyPair = generateKeyPair()
|
||||
val notaryService = ServiceInfo(ValidatingNotaryService.type, CordaX500Name(commonName = ValidatingNotaryService.type.id, organisation = "Notary service 2000", locality = "London", country = "GB"))
|
||||
val overrideServices = mapOf(Pair(notaryService, notaryKeyPair))
|
||||
val notaryIdentityOverride = Pair(notaryService, notaryKeyPair)
|
||||
// Note that these notaries don't operate correctly as they don't share their state. They are only used for testing
|
||||
// service addressing.
|
||||
notary1 = mockNet.createNotaryNode(networkMapAddress = node1.network.myAddress, overrideServices = overrideServices, serviceName = notaryService.name)
|
||||
notary2 = mockNet.createNotaryNode(networkMapAddress = node1.network.myAddress, overrideServices = overrideServices, serviceName = notaryService.name)
|
||||
notary1 = mockNet.createNotaryNode(notaryIdentity = notaryIdentityOverride, serviceName = notaryService.name)
|
||||
notary2 = mockNet.createNotaryNode(notaryIdentity = notaryIdentityOverride, serviceName = notaryService.name)
|
||||
|
||||
receivedSessionMessagesObservable().forEach { receivedSessionMessages += it }
|
||||
mockNet.runNetwork()
|
||||
|
||||
// We don't create a network map, so manually handle registrations
|
||||
mockNet.registerIdentities()
|
||||
notary1Identity = notary1.services.myInfo.legalIdentities[1]
|
||||
notary2Identity = notary2.services.myInfo.legalIdentities[1]
|
||||
}
|
||||
@ -160,7 +158,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `flow added before network map does run after init`() {
|
||||
val node3 = mockNet.createNode(node1.network.myAddress) //create vanilla node
|
||||
val node3 = mockNet.createNode() //create vanilla node
|
||||
val flow = NoOpFlow()
|
||||
node3.services.startFlow(flow)
|
||||
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||
@ -170,7 +168,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `flow added before network map will be init checkpointed`() {
|
||||
var node3 = mockNet.createNode(node1.network.myAddress) //create vanilla node
|
||||
var node3 = mockNet.createNode() //create vanilla node
|
||||
val flow = NoOpFlow()
|
||||
node3.services.startFlow(flow)
|
||||
assertEquals(false, flow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||
@ -178,7 +176,7 @@ class FlowFrameworkTests {
|
||||
node3.services.networkMapCache.clearNetworkMapCache() // zap persisted NetworkMapCache to force use of network.
|
||||
node3.dispose()
|
||||
|
||||
node3 = mockNet.createNode(node1.network.myAddress, node3.internals.id)
|
||||
node3 = mockNet.createNode(node3.internals.id)
|
||||
val restoredFlow = node3.getSingleFlow<NoOpFlow>().first
|
||||
assertEquals(false, restoredFlow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||
mockNet.runNetwork() // Allow network map messages to flow
|
||||
@ -189,7 +187,7 @@ class FlowFrameworkTests {
|
||||
node3.dispose()
|
||||
|
||||
// Now it is completed the flow should leave no Checkpoint.
|
||||
node3 = mockNet.createNode(node1.network.myAddress, node3.internals.id)
|
||||
node3 = mockNet.createNode(node3.internals.id)
|
||||
mockNet.runNetwork() // Allow network map messages to flow
|
||||
node3.smm.executor.flush()
|
||||
assertTrue(node3.smm.findStateMachines(NoOpFlow::class.java).isEmpty())
|
||||
@ -215,7 +213,7 @@ class FlowFrameworkTests {
|
||||
var sentCount = 0
|
||||
mockNet.messagingNetwork.sentMessages.toSessionTransfers().filter { it.isPayloadTransfer }.forEach { sentCount++ }
|
||||
|
||||
val node3 = mockNet.createNode(node1.network.myAddress)
|
||||
val node3 = mockNet.createNode()
|
||||
val secondFlow = node3.registerFlowFactory(PingPongFlow::class) { PingPongFlow(it, payload2) }
|
||||
mockNet.runNetwork()
|
||||
|
||||
@ -233,7 +231,7 @@ class FlowFrameworkTests {
|
||||
assertEquals(1, node2.checkpointStorage.checkpoints().size) // confirm checkpoint
|
||||
node2.services.networkMapCache.clearNetworkMapCache()
|
||||
}
|
||||
val node2b = mockNet.createNode(node1.network.myAddress, node2.internals.id, advertisedServices = *node2.internals.advertisedServices.toTypedArray())
|
||||
val node2b = mockNet.createNode(node2.internals.id, advertisedServices = *node2.internals.advertisedServices.toTypedArray())
|
||||
node2.internals.manuallyCloseDB()
|
||||
val (firstAgain, fut1) = node2b.getSingleFlow<PingPongFlow>()
|
||||
// Run the network which will also fire up the second flow. First message should get deduped. So message data stays in sync.
|
||||
@ -260,7 +258,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `sending to multiple parties`() {
|
||||
val node3 = mockNet.createNode(node1.network.myAddress)
|
||||
val node3 = mockNet.createNode()
|
||||
mockNet.runNetwork()
|
||||
node2.registerFlowFactory(SendFlow::class) { InitiatedReceiveFlow(it).nonTerminating() }
|
||||
node3.registerFlowFactory(SendFlow::class) { InitiatedReceiveFlow(it).nonTerminating() }
|
||||
@ -292,7 +290,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `receiving from multiple parties`() {
|
||||
val node3 = mockNet.createNode(node1.network.myAddress)
|
||||
val node3 = mockNet.createNode()
|
||||
mockNet.runNetwork()
|
||||
val node2Payload = "Test 1"
|
||||
val node3Payload = "Test 2"
|
||||
@ -501,7 +499,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `FlowException propagated in invocation chain`() {
|
||||
val node3 = mockNet.createNode(node1.network.myAddress)
|
||||
val node3 = mockNet.createNode()
|
||||
mockNet.runNetwork()
|
||||
|
||||
node3.registerFlowFactory(ReceiveFlow::class) { ExceptionFlow { MyFlowException("Chain") } }
|
||||
@ -515,7 +513,7 @@ class FlowFrameworkTests {
|
||||
|
||||
@Test
|
||||
fun `FlowException thrown and there is a 3rd unrelated party flow`() {
|
||||
val node3 = mockNet.createNode(node1.network.myAddress)
|
||||
val node3 = mockNet.createNode()
|
||||
mockNet.runNetwork()
|
||||
|
||||
// Node 2 will send its payload and then block waiting for the receive from node 1. Meanwhile node 1 will move
|
||||
@ -763,7 +761,7 @@ class FlowFrameworkTests {
|
||||
private inline fun <reified P : FlowLogic<*>> StartedNode<MockNode>.restartAndGetRestoredFlow(networkMapNode: StartedNode<*>? = null) = internals.run {
|
||||
disableDBCloseOnStop() // Handover DB to new node copy
|
||||
stop()
|
||||
val newNode = mockNet.createNode(networkMapNode?.network?.myAddress, id, advertisedServices = *advertisedServices.toTypedArray())
|
||||
val newNode = mockNet.createNode(id, advertisedServices = *advertisedServices.toTypedArray())
|
||||
newNode.internals.acceptableLiveFiberCountOnStop = 1
|
||||
manuallyCloseDB()
|
||||
mockNet.runNetwork() // allow NetworkMapService messages to stabilise and thus start the state machine
|
||||
|
@ -39,7 +39,7 @@ class NotaryServiceTests {
|
||||
notaryNode = mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(SimpleNotaryService.type)))
|
||||
clientNode = mockNet.createNode(notaryNode.network.myAddress)
|
||||
clientNode = mockNet.createNode()
|
||||
mockNet.runNetwork() // Clear network map registration messages
|
||||
notaryNode.internals.ensureRegistered()
|
||||
notary = clientNode.services.getDefaultNotary()
|
||||
|
@ -40,7 +40,7 @@ class ValidatingNotaryServiceTests {
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(ValidatingNotaryService.type))
|
||||
)
|
||||
clientNode = mockNet.createNode(notaryNode.network.myAddress)
|
||||
clientNode = mockNet.createNode()
|
||||
mockNet.runNetwork() // Clear network map registration messages
|
||||
notaryNode.internals.ensureRegistered()
|
||||
notary = clientNode.services.getDefaultNotary()
|
||||
|
@ -204,7 +204,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
fun `network tearoff`() {
|
||||
val mockNet = MockNetwork(initialiseSerialization = false)
|
||||
val n1 = mockNet.createNotaryNode()
|
||||
val oracleNode = mockNet.createNode(n1.network.myAddress).apply {
|
||||
val oracleNode = mockNet.createNode().apply {
|
||||
internals.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
||||
internals.registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
||||
database.transaction {
|
||||
|
@ -54,9 +54,9 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
// This puts together a mock network of SimulatedNodes.
|
||||
|
||||
open class SimulatedNode(config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger)
|
||||
: MockNetwork.MockNode(config, mockNet, networkMapAddress, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
: MockNetwork.MockNode(config, mockNet, networkMapAddress, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override val started: StartedNode<SimulatedNode>? get() = uncheckedCast(super.started)
|
||||
override fun findMyLocation(): WorldMapLocation? {
|
||||
return configuration.myLegalName.locality.let { CityDatabase[it] }
|
||||
@ -67,7 +67,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
var counter = 0
|
||||
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): SimulatedNode {
|
||||
val letter = 'A' + counter
|
||||
val (city, country) = bankLocations[counter++ % bankLocations.size]
|
||||
@ -75,13 +75,13 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
val cfg = testNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = CordaX500Name(organisation = "Bank $letter", locality = city, country = country))
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot)
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot)
|
||||
}
|
||||
|
||||
fun createAll(): List<SimulatedNode> {
|
||||
return bankLocations.mapIndexed { i, _ ->
|
||||
// Use deterministic seeds so the simulation is stable. Needed so that party owning keys are stable.
|
||||
mockNet.createUnstartedNode(networkMap.network.myAddress, nodeFactory = this, entropyRoot = BigInteger.valueOf(i.toLong()))
|
||||
mockNet.createUnstartedNode(nodeFactory = this, entropyRoot = BigInteger.valueOf(i.toLong()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,24 +90,24 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
|
||||
object NetworkMapNodeFactory : MockNetwork.Factory<SimulatedNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): SimulatedNode {
|
||||
val cfg = testNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = DUMMY_MAP.name)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {}
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {}
|
||||
}
|
||||
}
|
||||
|
||||
object NotaryNodeFactory : MockNetwork.Factory<SimulatedNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): SimulatedNode {
|
||||
require(advertisedServices.containsType(SimpleNotaryService.type))
|
||||
val cfg = testNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = DUMMY_NOTARY.name)
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot)
|
||||
return SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot)
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,12 +116,12 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
val RATES_SERVICE_NAME = CordaX500Name(organisation = "Rates Service Provider", locality = "Madrid", country = "ES")
|
||||
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): SimulatedNode {
|
||||
val cfg = testNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = RATES_SERVICE_NAME)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
override fun start() = super.start().apply {
|
||||
registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
||||
registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
||||
@ -137,12 +137,12 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
|
||||
object RegulatorFactory : MockNetwork.Factory<SimulatedNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): SimulatedNode {
|
||||
val cfg = testNodeConfiguration(
|
||||
baseDirectory = config.baseDirectory,
|
||||
myLegalName = DUMMY_REGULATOR.name)
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot) {
|
||||
return object : SimulatedNode(cfg, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot) {
|
||||
// TODO: Regulatory nodes don't actually exist properly, this is a last minute demo request.
|
||||
// So we just fire a message at a node that doesn't know how to handle it, and it'll ignore it.
|
||||
// But that's fine for visualisation purposes.
|
||||
@ -152,10 +152,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
|
||||
val mockNet = MockNetwork(networkSendManuallyPumped, runAsync)
|
||||
// This one must come first.
|
||||
val networkMap = mockNet.createNode(nodeFactory = NetworkMapNodeFactory)
|
||||
val notary = mockNet.createNode(networkMap.network.myAddress, nodeFactory = NotaryNodeFactory, advertisedServices = ServiceInfo(SimpleNotaryService.type))
|
||||
val regulators = listOf(mockNet.createUnstartedNode(networkMap.network.myAddress, nodeFactory = RegulatorFactory))
|
||||
val ratesOracle = mockNet.createUnstartedNode(networkMap.network.myAddress, nodeFactory = RatesOracleFactory)
|
||||
val networkMap = mockNet.startNetworkMapNode(nodeFactory = NetworkMapNodeFactory)
|
||||
val notary = mockNet.createNode(nodeFactory = NotaryNodeFactory, advertisedServices = ServiceInfo(SimpleNotaryService.type))
|
||||
val regulators = listOf(mockNet.createUnstartedNode(nodeFactory = RegulatorFactory))
|
||||
val ratesOracle = mockNet.createUnstartedNode(nodeFactory = RatesOracleFactory)
|
||||
|
||||
// All nodes must be in one of these two lists for the purposes of the visualiser tool.
|
||||
val serviceProviders: List<SimulatedNode> = listOf(notary.internals, ratesOracle, networkMap.internals)
|
||||
@ -264,7 +264,6 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
||||
fun start(): Future<Unit> {
|
||||
setCordappPackages("net.corda.irs.contract", "net.corda.finance.contract")
|
||||
mockNet.startNodes()
|
||||
mockNet.registerIdentities()
|
||||
// Wait for all the nodes to have finished registering with the network map service.
|
||||
return networkInitialisationFinished.thenCompose { startMainSimulation() }
|
||||
}
|
||||
|
@ -295,9 +295,9 @@ class FlowStackSnapshotTest {
|
||||
val notaryService = ServiceInfo(ValidatingNotaryService.type)
|
||||
val notaryNode = mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
overrideServices = mapOf(notaryService to DUMMY_NOTARY_KEY),
|
||||
notaryIdentity = notaryService to DUMMY_NOTARY_KEY,
|
||||
advertisedServices = *arrayOf(notaryService))
|
||||
val node = mockNet.createPartyNode(notaryNode.network.myAddress)
|
||||
val node = mockNet.createPartyNode()
|
||||
node.internals.registerInitiatedFlow(DummyFlow::class.java)
|
||||
node.services.startFlow(FlowStackSnapshotSerializationTestingFlow()).resultFuture.get()
|
||||
val thrown = try {
|
||||
|
@ -6,6 +6,7 @@ import com.nhaarman.mockito_kotlin.whenever
|
||||
import net.corda.core.crypto.entropyToKeyPair
|
||||
import net.corda.core.crypto.random63BitValue
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.identity.PartyAndCertificate
|
||||
import net.corda.core.internal.cert
|
||||
import net.corda.core.internal.concurrent.doneFuture
|
||||
@ -76,6 +77,11 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
InMemoryMessagingNetwork.ServicePeerAllocationStrategy.Random(),
|
||||
private val defaultFactory: Factory<*> = MockNetwork.DefaultFactory,
|
||||
private val initialiseSerialization: Boolean = true) {
|
||||
companion object {
|
||||
// TODO In future PR we're removing the concept of network map node so the details of this mock are not important.
|
||||
val MOCK_NET_MAP = Party(CordaX500Name(organisation = "Mock Network Map", locality = "Madrid", country = "ES"), DUMMY_KEY_1.public)
|
||||
}
|
||||
|
||||
var nextNodeId = 0
|
||||
private set
|
||||
private val filesystem = Jimfs.newFileSystem(unix())
|
||||
@ -87,6 +93,9 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
/** A read only view of the current set of executing nodes. */
|
||||
val nodes: List<MockNode> get() = _nodes
|
||||
|
||||
private var _networkMapNode: StartedNode<MockNode>? = null
|
||||
val networkMapNode: StartedNode<MockNode> get() = _networkMapNode ?: startNetworkMapNode()
|
||||
|
||||
init {
|
||||
if (initialiseSerialization) initialiseTestSerialization()
|
||||
filesystem.getPath("/nodes").createDirectory()
|
||||
@ -95,21 +104,21 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
/** Allows customisation of how nodes are created. */
|
||||
interface Factory<out N : MockNode> {
|
||||
/**
|
||||
* @param overrideServices a set of service entries to use in place of the node's default service entries,
|
||||
* for example where a node's service is part of a cluster.
|
||||
* @param notaryIdentity is an additional override to use in place of the node's default notary service,
|
||||
* main usage is for when the node is part of a notary cluster.
|
||||
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
||||
* but can be overriden to cause nodes to have stable or colliding identity/service keys.
|
||||
*/
|
||||
fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): N
|
||||
}
|
||||
|
||||
object DefaultFactory : Factory<MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNode {
|
||||
return MockNode(config, network, networkMapAddr, advertisedServices, id, overrideServices, entropyRoot)
|
||||
return MockNode(config, network, networkMapAddr, advertisedServices, id, notaryIdentity, entropyRoot)
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,8 +146,8 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
}
|
||||
|
||||
/**
|
||||
* @param overrideServices a set of service entries to use in place of the node's default service entries,
|
||||
* for example where a node's service is part of a cluster.
|
||||
* @param notaryIdentity is an additional override to use in place of the node's default notary service,
|
||||
* main usage is for when the node is part of a notary cluster.
|
||||
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
||||
* but can be overriden to cause nodes to have stable or colliding identity/service keys.
|
||||
*/
|
||||
@ -147,7 +156,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
override val networkMapAddress: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>,
|
||||
val id: Int,
|
||||
val overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
internal val notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
val entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue())) :
|
||||
AbstractNode(config, advertisedServices, TestClock(), mockNet.busyLatch) {
|
||||
var counter = entropyRoot
|
||||
@ -199,7 +208,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
}
|
||||
|
||||
override fun makeKeyManagementService(identityService: IdentityService): KeyManagementService {
|
||||
return E2ETestKeyManagementService(identityService, partyKeys + (overrideServices?.values ?: emptySet()))
|
||||
return E2ETestKeyManagementService(identityService, partyKeys + (notaryIdentity?.let { setOf(it.second) } ?: emptySet()))
|
||||
}
|
||||
|
||||
override fun startMessagingService(rpcOps: RPCOps) {
|
||||
@ -212,12 +221,11 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
|
||||
override fun getNotaryIdentity(): PartyAndCertificate? {
|
||||
val defaultIdentity = super.getNotaryIdentity()
|
||||
val override = overrideServices?.filter { it.key.type.isNotary() }?.entries?.singleOrNull()
|
||||
return if (override == null || defaultIdentity == null)
|
||||
return if (notaryIdentity == null || !notaryIdentity.first.type.isNotary() || defaultIdentity == null)
|
||||
defaultIdentity
|
||||
else {
|
||||
// Ensure that we always have notary in name and type of it. TODO It is temporary solution until we will have proper handling of NetworkParameters
|
||||
myNotaryIdentity = getTestPartyAndCertificate(defaultIdentity.name, override.value.public)
|
||||
myNotaryIdentity = getTestPartyAndCertificate(defaultIdentity.name, notaryIdentity.second.public)
|
||||
myNotaryIdentity
|
||||
}
|
||||
}
|
||||
@ -294,49 +302,67 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
}
|
||||
}
|
||||
|
||||
fun createUnstartedNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int? = null,
|
||||
legalName: CordaX500Name? = null, overrideServices: Map<ServiceInfo, KeyPair>? = null,
|
||||
fun <N : MockNode> startNetworkMapNode(nodeFactory: Factory<N>? = null): StartedNode<N> {
|
||||
check(_networkMapNode == null) { "Trying to start more than one network map node" }
|
||||
return uncheckedCast(createNodeImpl(networkMapAddress = null,
|
||||
forcedID = null,
|
||||
nodeFactory = nodeFactory ?: defaultFactory,
|
||||
legalName = MOCK_NET_MAP.name,
|
||||
notaryIdentity = null,
|
||||
advertisedServices = arrayOf(),
|
||||
entropyRoot = BigInteger.valueOf(random63BitValue()),
|
||||
configOverrides = {},
|
||||
start = true
|
||||
).started!!.apply {
|
||||
_networkMapNode = this
|
||||
})
|
||||
}
|
||||
|
||||
fun createUnstartedNode(forcedID: Int? = null,
|
||||
legalName: CordaX500Name? = null, notaryIdentity: Pair<ServiceInfo, KeyPair>? = null,
|
||||
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
|
||||
vararg advertisedServices: ServiceInfo,
|
||||
configOverrides: (NodeConfiguration) -> Any? = {}): MockNode {
|
||||
return createUnstartedNode(networkMapAddress, forcedID, defaultFactory, legalName, overrideServices, entropyRoot, *advertisedServices, configOverrides = configOverrides)
|
||||
return createUnstartedNode(forcedID, defaultFactory, legalName, notaryIdentity, entropyRoot, *advertisedServices, configOverrides = configOverrides)
|
||||
}
|
||||
|
||||
fun <N : MockNode> createUnstartedNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int? = null, nodeFactory: Factory<N>,
|
||||
legalName: CordaX500Name? = null, overrideServices: Map<ServiceInfo, KeyPair>? = null,
|
||||
fun <N : MockNode> createUnstartedNode(forcedID: Int? = null, nodeFactory: Factory<N>,
|
||||
legalName: CordaX500Name? = null, notaryIdentity: Pair<ServiceInfo, KeyPair>? = null,
|
||||
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
|
||||
vararg advertisedServices: ServiceInfo,
|
||||
configOverrides: (NodeConfiguration) -> Any? = {}): N {
|
||||
return createNodeImpl(networkMapAddress, forcedID, nodeFactory, false, legalName, overrideServices, entropyRoot, advertisedServices, configOverrides)
|
||||
val networkMapAddress = networkMapNode.network.myAddress
|
||||
return createNodeImpl(networkMapAddress, forcedID, nodeFactory, false, legalName, notaryIdentity, entropyRoot, advertisedServices, configOverrides)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a node, optionally created by the passed factory method.
|
||||
* @param overrideServices a set of service entries to use in place of the node's default service entries,
|
||||
* @param notaryIdentity a set of service entries to use in place of the node's default service entries,
|
||||
* for example where a node's service is part of a cluster.
|
||||
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
||||
* but can be overridden to cause nodes to have stable or colliding identity/service keys.
|
||||
* @param configOverrides add/override behaviour of the [NodeConfiguration] mock object.
|
||||
*/
|
||||
fun createNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int? = null,
|
||||
legalName: CordaX500Name? = null, overrideServices: Map<ServiceInfo, KeyPair>? = null,
|
||||
fun createNode(forcedID: Int? = null,
|
||||
legalName: CordaX500Name? = null, notaryIdentity: Pair<ServiceInfo, KeyPair>? = null,
|
||||
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
|
||||
vararg advertisedServices: ServiceInfo,
|
||||
configOverrides: (NodeConfiguration) -> Any? = {}): StartedNode<MockNode> {
|
||||
return createNode(networkMapAddress, forcedID, defaultFactory, legalName, overrideServices, entropyRoot, *advertisedServices, configOverrides = configOverrides)
|
||||
return createNode(forcedID, defaultFactory, legalName, notaryIdentity, entropyRoot, *advertisedServices, configOverrides = configOverrides)
|
||||
}
|
||||
|
||||
/** Like the other [createNode] but takes a [Factory] and propagates its [MockNode] subtype. */
|
||||
fun <N : MockNode> createNode(networkMapAddress: SingleMessageRecipient? = null, forcedID: Int? = null, nodeFactory: Factory<N>,
|
||||
legalName: CordaX500Name? = null, overrideServices: Map<ServiceInfo, KeyPair>? = null,
|
||||
fun <N : MockNode> createNode(forcedID: Int? = null, nodeFactory: Factory<N>,
|
||||
legalName: CordaX500Name? = null, notaryIdentity: Pair<ServiceInfo, KeyPair>? = null,
|
||||
entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue()),
|
||||
vararg advertisedServices: ServiceInfo,
|
||||
configOverrides: (NodeConfiguration) -> Any? = {}): StartedNode<N> {
|
||||
return uncheckedCast(createNodeImpl(networkMapAddress, forcedID, nodeFactory, true, legalName, overrideServices, entropyRoot, advertisedServices, configOverrides).started)!!
|
||||
val networkMapAddress = networkMapNode.network.myAddress
|
||||
return uncheckedCast(createNodeImpl(networkMapAddress, forcedID, nodeFactory, true, legalName, notaryIdentity, entropyRoot, advertisedServices, configOverrides).started)!!
|
||||
}
|
||||
|
||||
private fun <N : MockNode> createNodeImpl(networkMapAddress: SingleMessageRecipient?, forcedID: Int?, nodeFactory: Factory<N>,
|
||||
start: Boolean, legalName: CordaX500Name?, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
start: Boolean, legalName: CordaX500Name?, notaryIdentity: Pair<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger,
|
||||
advertisedServices: Array<out ServiceInfo>,
|
||||
configOverrides: (NodeConfiguration) -> Any?): N {
|
||||
@ -347,7 +373,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
whenever(it.dataSourceProperties).thenReturn(makeTestDataSourceProperties("node_${id}_net_$networkId"))
|
||||
configOverrides(it)
|
||||
}
|
||||
return nodeFactory.create(config, this, networkMapAddress, advertisedServices.toSet(), id, overrideServices, entropyRoot).apply {
|
||||
return nodeFactory.create(config, this, networkMapAddress, advertisedServices.toSet(), id, notaryIdentity, entropyRoot).apply {
|
||||
if (start) {
|
||||
start()
|
||||
if (threadPerNode && networkMapAddress != null) nodeReadyFuture.getOrThrow() // XXX: What about manually-started nodes?
|
||||
@ -379,36 +405,22 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register network identities in identity service, normally it's done on network map cache change, but we may run without
|
||||
* network map service.
|
||||
*/
|
||||
fun registerIdentities(){
|
||||
nodes.forEach { itNode ->
|
||||
itNode.started!!.database.transaction {
|
||||
nodes.map { it.started!!.info.legalIdentitiesAndCerts.first() }.map(itNode.started!!.services.identityService::verifyAndRegisterIdentity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a default notary node.
|
||||
*/
|
||||
fun createNotaryNode() = createNotaryNode(null, DUMMY_NOTARY.name, null, null)
|
||||
fun createNotaryNode() = createNotaryNode(DUMMY_NOTARY.name, null, null)
|
||||
|
||||
fun createNotaryNode(networkMapAddress: SingleMessageRecipient? = null,
|
||||
legalName: CordaX500Name? = null,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>? = null,
|
||||
fun createNotaryNode(legalName: CordaX500Name? = null,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>? = null,
|
||||
serviceName: CordaX500Name? = null): StartedNode<MockNode> {
|
||||
return createNode(networkMapAddress, legalName = legalName, overrideServices = overrideServices,
|
||||
return createNode(legalName = legalName, notaryIdentity = notaryIdentity,
|
||||
advertisedServices = *arrayOf(ServiceInfo(ValidatingNotaryService.type, serviceName)))
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun createPartyNode(networkMapAddress: SingleMessageRecipient,
|
||||
legalName: CordaX500Name? = null,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>? = null): StartedNode<MockNode> {
|
||||
return createNode(networkMapAddress, legalName = legalName, overrideServices = overrideServices)
|
||||
fun createPartyNode(legalName: CordaX500Name? = null,
|
||||
notaryIdentity: Pair<ServiceInfo, KeyPair>? = null): StartedNode<MockNode> {
|
||||
return createNode(legalName = legalName, notaryIdentity = notaryIdentity)
|
||||
}
|
||||
|
||||
@Suppress("unused") // This is used from the network visualiser tool.
|
||||
|
Loading…
Reference in New Issue
Block a user