mirror of
https://github.com/corda/corda.git
synced 2025-06-16 22:28:15 +00:00
CORDA-652: Remove uses of createSomeNodes
for consistency (#1492)
Replace use of `createSomeNodes()` with creating notary and party nodes individually. This typically results in less code as the basket of nodes isn't built first then the nodes, but instead the nodes generated directly. Notably this identified issues in notary change and contract upgrade tests, which were not actually using a validating notary and therefore it had been missed that the transactions were failing validation. Renamed nodes in tests for consistency as well, so nodes are now `aliceNode`, `bobNode`, etc. instead of `a`, `b`, or `n0`, `n1`, or other variants of those.
This commit is contained in:
@ -93,15 +93,13 @@ class TwoPartyTradeFlowTests {
|
||||
mockNet = MockNetwork(false, true)
|
||||
|
||||
ledger(initialiseSerialization = false) {
|
||||
val basketOfNodes = mockNet.createSomeNodes(3)
|
||||
val notaryNode = basketOfNodes.notaryNode
|
||||
val aliceNode = basketOfNodes.partyNodes[0]
|
||||
val bobNode = basketOfNodes.partyNodes[1]
|
||||
val bankNode = basketOfNodes.partyNodes[2]
|
||||
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 notary = notaryNode.services.getDefaultNotary()
|
||||
val cashIssuer = bankNode.info.chooseIdentity().ref(1)
|
||||
val cpIssuer = bankNode.info.chooseIdentity().ref(1, 2, 3)
|
||||
val notary = aliceNode.services.getDefaultNotary()
|
||||
|
||||
|
||||
aliceNode.internals.disableDBCloseOnStop()
|
||||
bobNode.internals.disableDBCloseOnStop()
|
||||
@ -144,7 +142,7 @@ class TwoPartyTradeFlowTests {
|
||||
mockNet = MockNetwork(false, true)
|
||||
|
||||
ledger(initialiseSerialization = false) {
|
||||
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||
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)
|
||||
@ -198,7 +196,7 @@ class TwoPartyTradeFlowTests {
|
||||
fun `shutdown and restore`() {
|
||||
mockNet = MockNetwork(false)
|
||||
ledger(initialiseSerialization = false) {
|
||||
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||
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)
|
||||
@ -332,7 +330,7 @@ class TwoPartyTradeFlowTests {
|
||||
fun `check dependencies of sale asset are resolved`() {
|
||||
mockNet = MockNetwork(false)
|
||||
|
||||
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = makeNodeWithTracking(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = makeNodeWithTracking(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = makeNodeWithTracking(notaryNode.network.myAddress, BOC.name)
|
||||
@ -439,7 +437,7 @@ class TwoPartyTradeFlowTests {
|
||||
fun `track works`() {
|
||||
mockNet = MockNetwork(false)
|
||||
|
||||
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = makeNodeWithTracking(notaryNode.network.myAddress, ALICE.name)
|
||||
val bobNode = makeNodeWithTracking(notaryNode.network.myAddress, BOB.name)
|
||||
val bankNode = makeNodeWithTracking(notaryNode.network.myAddress, BOC.name)
|
||||
@ -596,7 +594,7 @@ class TwoPartyTradeFlowTests {
|
||||
aliceError: Boolean,
|
||||
expectedMessageSubstring: String
|
||||
) {
|
||||
val notaryNode = mockNet.createNotaryNode(null, DUMMY_NOTARY.name)
|
||||
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)
|
||||
|
@ -5,6 +5,7 @@ import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.nodeapi.internal.ServiceInfo
|
||||
import net.corda.testing.ALICE
|
||||
import net.corda.testing.BOB
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.chooseIdentity
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -29,10 +30,9 @@ class NetworkMapCacheTest {
|
||||
|
||||
@Test
|
||||
fun registerWithNetwork() {
|
||||
val nodes = mockNet.createSomeNodes(1)
|
||||
val n0 = nodes.mapNode
|
||||
val n1 = nodes.partyNodes[0]
|
||||
val future = n1.services.networkMapCache.addMapService(n1.network, n0.network.myAddress, false, null)
|
||||
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.runNetwork()
|
||||
future.getOrThrow()
|
||||
}
|
||||
@ -40,30 +40,29 @@ class NetworkMapCacheTest {
|
||||
@Test
|
||||
fun `key collision`() {
|
||||
val entropy = BigInteger.valueOf(24012017L)
|
||||
val nodeA = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = ALICE.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
val nodeB = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = BOB.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
assertEquals(nodeA.info.chooseIdentity(), nodeB.info.chooseIdentity())
|
||||
val aliceNode = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = ALICE.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
val bobNode = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = BOB.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
assertEquals(aliceNode.info.chooseIdentity(), bobNode.info.chooseIdentity())
|
||||
|
||||
mockNet.runNetwork()
|
||||
|
||||
// Node A currently knows only about itself, so this returns node A
|
||||
assertEquals(nodeA.services.networkMapCache.getNodesByLegalIdentityKey(nodeA.info.chooseIdentity().owningKey).singleOrNull(), nodeA.info)
|
||||
assertEquals(aliceNode.services.networkMapCache.getNodesByLegalIdentityKey(aliceNode.info.chooseIdentity().owningKey).singleOrNull(), aliceNode.info)
|
||||
|
||||
nodeA.services.networkMapCache.addNode(nodeB.info)
|
||||
aliceNode.services.networkMapCache.addNode(bobNode.info)
|
||||
// The details of node B write over those for node A
|
||||
assertEquals(nodeA.services.networkMapCache.getNodesByLegalIdentityKey(nodeA.info.chooseIdentity().owningKey).singleOrNull(), nodeB.info)
|
||||
assertEquals(aliceNode.services.networkMapCache.getNodesByLegalIdentityKey(aliceNode.info.chooseIdentity().owningKey).singleOrNull(), bobNode.info)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getNodeByLegalIdentity`() {
|
||||
val nodes = mockNet.createSomeNodes(1)
|
||||
val n0 = nodes.mapNode
|
||||
val n1 = nodes.partyNodes[0]
|
||||
val node0Cache: NetworkMapCache = n0.services.networkMapCache
|
||||
val expected = n1.info
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val notaryCache: NetworkMapCache = notaryNode.services.networkMapCache
|
||||
val expected = aliceNode.info
|
||||
|
||||
mockNet.runNetwork()
|
||||
val actual = n0.database.transaction { node0Cache.getNodeByLegalIdentity(n1.info.chooseIdentity()) }
|
||||
val actual = notaryNode.database.transaction { notaryCache.getNodeByLegalIdentity(aliceNode.info.chooseIdentity()) }
|
||||
assertEquals(expected, actual)
|
||||
|
||||
// TODO: Should have a test case with anonymous lookup
|
||||
@ -71,19 +70,18 @@ class NetworkMapCacheTest {
|
||||
|
||||
@Test
|
||||
fun `remove node from cache`() {
|
||||
val nodes = mockNet.createSomeNodes(1)
|
||||
val n0 = nodes.mapNode
|
||||
val n1 = nodes.partyNodes[0]
|
||||
val n0Identity = n0.info.chooseIdentity()
|
||||
val n1Identity = n1.info.chooseIdentity()
|
||||
val node0Cache = n0.services.networkMapCache as PersistentNetworkMapCache
|
||||
val notaryNode = mockNet.createNotaryNode()
|
||||
val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name)
|
||||
val notaryLegalIdentity = notaryNode.info.chooseIdentity()
|
||||
val alice = aliceNode.info.chooseIdentity()
|
||||
val notaryCache = notaryNode.services.networkMapCache as PersistentNetworkMapCache
|
||||
mockNet.runNetwork()
|
||||
n0.database.transaction {
|
||||
assertThat(node0Cache.getNodeByLegalIdentity(n1Identity) != null)
|
||||
node0Cache.removeNode(n1.info)
|
||||
assertThat(node0Cache.getNodeByLegalIdentity(n1Identity) == null)
|
||||
assertThat(node0Cache.getNodeByLegalIdentity(n0Identity) != null)
|
||||
assertThat(node0Cache.getNodeByLegalName(n1Identity.name) == null)
|
||||
notaryNode.database.transaction {
|
||||
assertThat(notaryCache.getNodeByLegalIdentity(alice) != null)
|
||||
notaryCache.removeNode(aliceNode.info)
|
||||
assertThat(notaryCache.getNodeByLegalIdentity(alice) == null)
|
||||
assertThat(notaryCache.getNodeByLegalIdentity(notaryLegalIdentity) != null)
|
||||
assertThat(notaryCache.getNodeByLegalName(alice.name) == null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user