diff --git a/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt b/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt index d84cbd3a62..546d2dc088 100644 --- a/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt +++ b/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt @@ -6,6 +6,7 @@ import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.Amount import net.corda.core.cordapp.CordappProvider import net.corda.core.crypto.* +import net.corda.core.identity.CordaX500Name import net.corda.core.node.ServiceHub import net.corda.core.transactions.SignedTransaction import net.corda.finance.USD @@ -20,9 +21,12 @@ import java.util.* import kotlin.test.assertEquals class JacksonSupportTest { - companion object { - private val SEED = BigInteger.valueOf(20170922L) + private companion object { + val SEED = BigInteger.valueOf(20170922L)!! val mapper = JacksonSupport.createNonRpcMapper() + val ALICE_PUBKEY = TestIdentity(ALICE_NAME, 70).pubkey + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val MINI_CORP = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")).party } @Rule diff --git a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java index 04f8847e24..8aa3ed86af 100644 --- a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java +++ b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java @@ -14,7 +14,7 @@ import net.corda.nodeapi.internal.config.User; import net.corda.testing.CoreTestUtils; import net.corda.testing.IntegrationTestKt; import net.corda.testing.IntegrationTestSchemas; -import net.corda.testing.internal.NodeBasedTest; +import net.corda.testing.node.internal.NodeBasedTest; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -31,7 +31,7 @@ import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.contracts.GetBalances.getCashBalance; import static net.corda.node.services.Permissions.invokeRpc; import static net.corda.node.services.Permissions.startFlow; -import static net.corda.testing.TestConstants.getALICE; +import static net.corda.testing.TestConstants.getALICE_NAME; import static net.corda.testing.TestConstants.getDUMMY_NOTARY; public class CordaRPCJavaClientTest extends NodeBasedTest { @@ -65,7 +65,7 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { @Before public void setUp() throws Exception { super.setUp(); - node = startNode(getALICE().getName(), 1, singletonList(rpcUser)); + node = startNode(getALICE_NAME(), 1, singletonList(rpcUser)); client = new CordaRPCClient(requireNonNull(node.getInternals().getConfiguration().getRpcAddress())); } diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt index c675f35539..d0a1dd827f 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt @@ -8,6 +8,7 @@ import net.corda.core.messaging.startFlow import net.corda.core.serialization.CordaSerializable import net.corda.core.utilities.getOrThrow import net.corda.testing.* +import net.corda.testing.ALICE_NAME import net.corda.testing.driver.driver import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.ClassRule @@ -33,7 +34,7 @@ class BlacklistKotlinClosureTest : IntegrationTest() { @Test fun `closure sent via RPC`() { driver(startNodesInProcess = true) { - val rpc = startNode(providedName = ALICE.name).getOrThrow().rpc + val rpc = startNode(providedName = ALICE_NAME).getOrThrow().rpc val packet = Packet { EVIL } assertThatExceptionOfType(KryoException::class.java) .isThrownBy { rpc.startFlow(::FlowC, packet) } diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt index 35b827c4b8..a76a9118ce 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt @@ -22,7 +22,7 @@ import net.corda.node.services.Permissions.Companion.invokeRpc import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User import net.corda.testing.* -import net.corda.testing.internal.NodeBasedTest +import net.corda.testing.node.internal.NodeBasedTest import org.apache.activemq.artemis.api.core.ActiveMQSecurityException import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatExceptionOfType @@ -141,7 +141,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance.contracts", C @Test fun `flow initiator via RPC`() { val externalTrace = Trace.newInstance() - val impersonatedActor = Actor(Actor.Id("Mark Dadada"), AuthServiceId("Test"), owningLegalIdentity = BOB.name) + val impersonatedActor = Actor(Actor.Id("Mark Dadada"), AuthServiceId("Test"), owningLegalIdentity = BOB_NAME) login(rpcUser.username, rpcUser.password, externalTrace, impersonatedActor) val proxy = connection!!.proxy diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt index d4e352de90..624f18a600 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt @@ -14,7 +14,9 @@ import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.nodeapi.RPCApi import net.corda.testing.* import net.corda.testing.internal.poll +import net.corda.testing.SerializationEnvironmentRule import net.corda.testing.internal.* +import net.corda.testing.node.internal.* import org.apache.activemq.artemis.api.core.SimpleString import org.junit.After import org.junit.Assert.assertEquals diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/AbstractRPCTest.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/AbstractRPCTest.kt index 053c8b85c1..11a9a027fa 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/AbstractRPCTest.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/AbstractRPCTest.kt @@ -7,10 +7,10 @@ import net.corda.core.messaging.RPCOps import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.nodeapi.internal.config.User import net.corda.testing.SerializationEnvironmentRule -import net.corda.testing.internal.RPCDriverDSL -import net.corda.testing.internal.rpcTestUser -import net.corda.testing.internal.startInVmRpcClient -import net.corda.testing.internal.startRpcClient +import net.corda.testing.node.internal.RPCDriverDSL +import net.corda.testing.node.internal.rpcTestUser +import net.corda.testing.node.internal.startInVmRpcClient +import net.corda.testing.node.internal.startRpcClient import org.apache.activemq.artemis.api.core.client.ClientSession import org.junit.Rule import org.junit.runners.Parameterized diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/ClientRPCInfrastructureTests.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/ClientRPCInfrastructureTests.kt index eee72cf1b5..43cd0c1ce1 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/ClientRPCInfrastructureTests.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/ClientRPCInfrastructureTests.kt @@ -7,9 +7,9 @@ import net.corda.core.internal.concurrent.thenMatch import net.corda.core.messaging.RPCOps import net.corda.core.utilities.getOrThrow import net.corda.node.services.messaging.rpcContext -import net.corda.testing.internal.RPCDriverDSL -import net.corda.testing.internal.rpcDriver -import net.corda.testing.internal.rpcTestUser +import net.corda.testing.node.internal.RPCDriverDSL +import net.corda.testing.node.internal.rpcDriver +import net.corda.testing.node.internal.rpcTestUser import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.junit.runner.RunWith diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCConcurrencyTests.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCConcurrencyTests.kt index 6d80a39398..22c160a1d0 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCConcurrencyTests.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCConcurrencyTests.kt @@ -9,8 +9,8 @@ import net.corda.core.serialization.CordaSerializable import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.millis import net.corda.node.services.messaging.RPCServerConfiguration -import net.corda.testing.internal.RPCDriverDSL -import net.corda.testing.internal.rpcDriver +import net.corda.testing.node.internal.RPCDriverDSL +import net.corda.testing.node.internal.rpcDriver import net.corda.testing.internal.testThreadFactory import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet import org.junit.After diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCFailureTests.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCFailureTests.kt index 5894520661..96ba3ece6b 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCFailureTests.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCFailureTests.kt @@ -6,8 +6,8 @@ import net.corda.core.internal.concurrent.openFuture import net.corda.core.messaging.* import net.corda.core.utilities.getOrThrow import net.corda.testing.SerializationEnvironmentRule -import net.corda.testing.internal.rpcDriver -import net.corda.testing.internal.startRpcClient +import net.corda.testing.node.internal.rpcDriver +import net.corda.testing.node.internal.startRpcClient import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Rule import org.junit.Test diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPerformanceTests.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPerformanceTests.kt index 90a01ec645..85d3351ade 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPerformanceTests.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPerformanceTests.kt @@ -6,12 +6,12 @@ import net.corda.core.messaging.RPCOps import net.corda.core.utilities.minutes import net.corda.core.utilities.seconds import net.corda.node.services.messaging.RPCServerConfiguration -import net.corda.testing.internal.RPCDriverDSL +import net.corda.testing.node.internal.RPCDriverDSL import net.corda.testing.internal.performance.div -import net.corda.testing.internal.performance.startPublishingFixedRateInjector -import net.corda.testing.internal.performance.startReporter -import net.corda.testing.internal.performance.startTightLoopInjector -import net.corda.testing.internal.rpcDriver +import net.corda.testing.node.internal.performance.startPublishingFixedRateInjector +import net.corda.testing.node.internal.performance.startReporter +import net.corda.testing.node.internal.performance.startTightLoopInjector +import net.corda.testing.node.internal.rpcDriver import net.corda.testing.measure import org.junit.Ignore import org.junit.Test diff --git a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPermissionsTests.kt b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPermissionsTests.kt index 0607541ba9..9d57aa401e 100644 --- a/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPermissionsTests.kt +++ b/client/rpc/src/test/kotlin/net/corda/client/rpc/RPCPermissionsTests.kt @@ -3,8 +3,8 @@ package net.corda.client.rpc import net.corda.core.messaging.RPCOps import net.corda.node.services.messaging.rpcContext import net.corda.nodeapi.internal.config.User -import net.corda.testing.internal.RPCDriverDSL -import net.corda.testing.internal.rpcDriver +import net.corda.testing.node.internal.RPCDriverDSL +import net.corda.testing.node.internal.rpcDriver import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt index 51b24e8bd1..585cb8b6bf 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt @@ -16,6 +16,7 @@ import net.corda.finance.flows.CashIssueAndPaymentFlow import net.corda.finance.flows.CashPaymentFlow import net.corda.testing.* import net.corda.testing.node.MockNetwork +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt index e709715eb9..bc5ad98a35 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt @@ -1,14 +1,11 @@ package net.corda.confidential -import net.corda.core.identity.AbstractParty -import net.corda.core.identity.AnonymousParty -import net.corda.core.identity.Party -import net.corda.core.identity.PartyAndCertificate +import net.corda.core.identity.* import net.corda.core.utilities.getOrThrow import net.corda.testing.* import net.corda.testing.node.MockNetwork import org.junit.Before -import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.junit.Test import kotlin.test.* @@ -24,8 +21,8 @@ class SwapIdentitiesFlowTests { @Test fun `issue key`() { // Set up values we'll need - val aliceNode = mockNet.createPartyNode(ALICE.name) - val bobNode = mockNet.createPartyNode(BOB.name) + val aliceNode = mockNet.createPartyNode(ALICE_NAME) + val bobNode = mockNet.createPartyNode(BOB_NAME) val alice = aliceNode.info.singleIdentity() val bob = bobNode.services.myInfo.singleIdentity() @@ -60,9 +57,9 @@ class SwapIdentitiesFlowTests { @Test fun `verifies identity name`() { // Set up values we'll need - val aliceNode = mockNet.createPartyNode(ALICE.name) - val bobNode = mockNet.createPartyNode(BOB.name) - val charlieNode = mockNet.createPartyNode(CHARLIE.name) + val aliceNode = mockNet.createPartyNode(ALICE_NAME) + val bobNode = mockNet.createPartyNode(BOB_NAME) + val charlieNode = mockNet.createPartyNode(CHARLIE_NAME) val bob: Party = bobNode.services.myInfo.singleIdentity() val notBob = charlieNode.database.transaction { charlieNode.services.keyManagementService.freshKeyAndCert(charlieNode.services.myInfo.chooseIdentityAndCert(), false) @@ -83,8 +80,8 @@ class SwapIdentitiesFlowTests { fun `verifies signature`() { // Set up values we'll need val notaryNode = mockNet.defaultNotaryNode - val aliceNode = mockNet.createPartyNode(ALICE.name) - val bobNode = mockNet.createPartyNode(BOB.name) + val aliceNode = mockNet.createPartyNode(ALICE_NAME) + val bobNode = mockNet.createPartyNode(BOB_NAME) val alice: PartyAndCertificate = aliceNode.info.singleIdentityAndCert() val bob: PartyAndCertificate = bobNode.info.singleIdentityAndCert() val notary: PartyAndCertificate = mockNet.defaultNotaryIdentityAndCert diff --git a/core/src/main/kotlin/net/corda/core/identity/CordaX500Name.kt b/core/src/main/kotlin/net/corda/core/identity/CordaX500Name.kt index ee8baa8733..c3e394b6b5 100644 --- a/core/src/main/kotlin/net/corda/core/identity/CordaX500Name.kt +++ b/core/src/main/kotlin/net/corda/core/identity/CordaX500Name.kt @@ -45,7 +45,7 @@ data class CordaX500Name(val commonName: String?, init { // Legal name checks. - LegalNameValidator.validateOrganization(organisation) + LegalNameValidator.validateOrganization(organisation, LegalNameValidator.Validation.MINIMAL) // Attribute data width checks. require(country.length == LENGTH_COUNTRY) { "Invalid country '$country' Country code must be $LENGTH_COUNTRY letters ISO code " } diff --git a/core/src/main/kotlin/net/corda/core/internal/LegalNameValidator.kt b/core/src/main/kotlin/net/corda/core/internal/LegalNameValidator.kt index 892f83b224..ffdba208b8 100644 --- a/core/src/main/kotlin/net/corda/core/internal/LegalNameValidator.kt +++ b/core/src/main/kotlin/net/corda/core/internal/LegalNameValidator.kt @@ -1,18 +1,27 @@ package net.corda.core.internal -import java.lang.Character.UnicodeScript.* +import net.corda.core.internal.LegalNameValidator.normalize import java.text.Normalizer -import java.util.regex.Pattern import javax.security.auth.x500.X500Principal object LegalNameValidator { + enum class Validation { + MINIMAL, + FULL + } + @Deprecated("Use validateOrganization instead", replaceWith = ReplaceWith("validateOrganization(normalizedLegalName)")) - fun validateLegalName(normalizedLegalName: String) = validateOrganization(normalizedLegalName) + fun validateLegalName(normalizedLegalName: String) = validateOrganization(normalizedLegalName, Validation.FULL) /** * The validation function validates a string for use as part of a legal name. It applies the following rules: * - * - No blacklisted words like "node", "server". + * - Does not contain the null character + * - Must be normalized (as per the [normalize] function). + * - Length must be 255 characters or shorter. + * + * Full validation (typically this is only done for names the Doorman approves) adds: + * * - Restrict names to Latin scripts for now to avoid right-to-left issues, debugging issues when we can't pronounce * names over the phone, and character confusability attacks. * - No commas or equals signs. @@ -20,25 +29,37 @@ object LegalNameValidator { * * @throws IllegalArgumentException if the name does not meet the required rules. The message indicates why not. */ - fun validateNameAttribute(normalizedNameAttribute: String) { - Rule.baseNameRules.forEach { it.validate(normalizedNameAttribute) } + fun validateNameAttribute(normalizedNameAttribute: String, validation: Validation) { + when (validation) { + Validation.MINIMAL -> Rule.attributeRules.forEach { it.validate(normalizedNameAttribute) } + Validation.FULL -> Rule.attributeFullRules.forEach { it.validate(normalizedNameAttribute) } + } } /** * The validation function validates a string for use as the organization attribute of a name, which includes additional - * constraints over basic name attribute checks. It applies the following rules: + * constraints over basic name attribute checks. It applies the following additional rules: * + * - Must be normalized (as per the [normalize] function). + * - Length must be 255 characters or shorter. * - No blacklisted words like "node", "server". + * - Must consist of at least three letters. + * + * Full validation (typically this is only done for names the Doorman approves) adds: + * * - Restrict names to Latin scripts for now to avoid right-to-left issues, debugging issues when we can't pronounce * names over the phone, and character confusability attacks. - * - Must consist of at least three letters and should start with a capital letter. + * - Must start with a capital letter. * - No commas or equals signs. * - No dollars or quote marks, we might need to relax the quote mark constraint in future to handle Irish company names. * * @throws IllegalArgumentException if the name does not meet the required rules. The message indicates why not. */ - fun validateOrganization(normalizedOrganization: String) { - Rule.legalNameRules.forEach { it.validate(normalizedOrganization) } + fun validateOrganization(normalizedOrganization: String, validation: Validation) { + when (validation) { + Validation.MINIMAL -> Rule.legalNameRules.forEach { it.validate(normalizedOrganization) } + Validation.FULL -> Rule.legalNameFullRules.forEach { it.validate(normalizedOrganization) } + } } @Deprecated("Use normalize instead", replaceWith = ReplaceWith("normalize(legalName)")) @@ -57,18 +78,27 @@ object LegalNameValidator { sealed class Rule { companion object { - val baseNameRules: List> = listOf( + val attributeRules: List> = listOf( UnicodeNormalizationRule(), - CharacterRule(',', '=', '$', '"', '\'', '\\'), - WordRule("node", "server"), LengthRule(maxLength = 255), + MustHaveAtLeastTwoLettersRule(), + CharacterRule('\u0000') // Ban null + ) + val attributeFullRules: List> = attributeRules + listOf( + CharacterRule(',', '=', '$', '"', '\'', '\\'), // TODO: Implement confusable character detection if we add more scripts. - UnicodeRangeRule(LATIN, COMMON, INHERITED), + UnicodeRangeRule(Character.UnicodeBlock.BASIC_LATIN), + CapitalLetterRule() + ) + val legalNameRules: List> = attributeRules + listOf( + WordRule("node", "server"), X500NameRule() ) - val legalNameRules: List> = baseNameRules + listOf( - CapitalLetterRule(), - MustHaveAtLeastTwoLettersRule() + val legalNameFullRules: List> = legalNameRules + listOf( + CharacterRule(',', '=', '$', '"', '\'', '\\'), + // TODO: Implement confusable character detection if we add more scripts. + UnicodeRangeRule(Character.UnicodeBlock.BASIC_LATIN), + CapitalLetterRule() ) } @@ -80,18 +110,13 @@ object LegalNameValidator { } } - private class UnicodeRangeRule(vararg supportScripts: Character.UnicodeScript) : Rule() { - private val pattern = supportScripts.map { "\\p{Is$it}" }.joinToString(separator = "", prefix = "[", postfix = "]*").let { Pattern.compile(it) } + private class UnicodeRangeRule(vararg supportScripts: Character.UnicodeBlock) : Rule() { + val supportScriptsSet = supportScripts.toSet() override fun validate(legalName: String) { - require(pattern.matcher(legalName).matches()) { - val illegalChars = legalName.replace(pattern.toRegex(), "").toSet() - if (illegalChars.size > 1) { - "Forbidden characters $illegalChars in \"$legalName\"." - } else { - "Forbidden character $illegalChars in \"$legalName\"." - } - } + val illegalChars = legalName.toCharArray().filter { Character.UnicodeBlock.of(it) !in supportScriptsSet }.size + // We don't expose the characters or the legal name, for security reasons + require (illegalChars == 0) { "$illegalChars forbidden characters in legal name." } } } diff --git a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java index 6d998b4917..7e5670c527 100644 --- a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java +++ b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java @@ -17,6 +17,7 @@ import static net.corda.testing.CoreTestUtils.singleIdentity; import static net.corda.testing.NodeTestUtils.startFlow; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.Assert.fail; +import static net.corda.testing.node.NodeTestUtils.startFlow; public class FlowsInJavaTest { private final MockNetwork mockNet = new MockNetwork(); @@ -26,8 +27,8 @@ public class FlowsInJavaTest { @Before public void setUp() throws Exception { - aliceNode = mockNet.createPartyNode(TestConstants.getALICE().getName()); - bobNode = mockNet.createPartyNode(TestConstants.getBOB().getName()); + aliceNode = mockNet.createPartyNode(TestConstants.getALICE_NAME()); + bobNode = mockNet.createPartyNode(TestConstants.getBOB_NAME()); bob = singleIdentity(bobNode.getInfo()); } diff --git a/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt b/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt index 29ad386359..460fda3328 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt @@ -18,6 +18,11 @@ import kotlin.test.assertTrue * Tests for the version 2 dummy contract, to cover ensuring upgrade transactions are built correctly. */ class DummyContractV2Tests { + private companion object { + val ALICE = TestIdentity(ALICE_NAME, 70).party + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt b/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt index be02cc4599..3968d8cae3 100644 --- a/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt +++ b/core/src/test/kotlin/net/corda/core/crypto/PartialMerkleTreeTest.kt @@ -4,6 +4,7 @@ import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash.Companion.zeroHash +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize @@ -14,6 +15,7 @@ import net.corda.finance.contracts.asset.Cash import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* import net.corda.testing.node.MockServices +import net.corda.testing.node.ledger import org.junit.Before import org.junit.Rule import org.junit.Test @@ -24,6 +26,16 @@ import kotlin.streams.toList import kotlin.test.* class PartialMerkleTreeTest { + private companion object { + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MINI_CORP get() = miniCorp.party + val MINI_CORP_PUBKEY get() = miniCorp.pubkey + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt index 890836e35b..c11589b8e9 100644 --- a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt @@ -13,6 +13,7 @@ import net.corda.node.services.persistence.NodeAttachmentService import net.corda.testing.* import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test @@ -48,9 +49,8 @@ class AttachmentTests { @Test fun `download and store`() { - val aliceNode = mockNet.createPartyNode(ALICE.name) - val bobNode = mockNet.createPartyNode(BOB.name) - + val aliceNode = mockNet.createPartyNode(ALICE_NAME) + val bobNode = mockNet.createPartyNode(BOB_NAME) val alice = aliceNode.info.singleIdentity() aliceNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) bobNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) @@ -81,8 +81,8 @@ class AttachmentTests { @Test fun `missing`() { - val aliceNode = mockNet.createPartyNode(ALICE.name) - val bobNode = mockNet.createPartyNode(BOB.name) + val aliceNode = mockNet.createPartyNode(ALICE_NAME) + val bobNode = mockNet.createPartyNode(BOB_NAME) aliceNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) bobNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) // Get node one to fetch a non-existent attachment. @@ -97,13 +97,13 @@ class AttachmentTests { @Test fun maliciousResponse() { // Make a node that doesn't do sanity checking at load time. - val aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE.name), nodeFactory = { args -> + val aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME), nodeFactory = { args -> object : MockNetwork.MockNode(args) { override fun start() = super.start().apply { attachments.checkAttachmentsOnLoad = false } } }) - val bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB.name)) - val alice = aliceNode.services.myInfo.identityFromX500Name(ALICE_NAME) + val bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) + val alice = aliceNode.info.singleIdentity() aliceNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) bobNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) val attachment = fakeAttachment() diff --git a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt index d38e0fa841..944e7eaca5 100644 --- a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt @@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.Command import net.corda.core.contracts.StateAndContract import net.corda.core.contracts.requireThat +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.identity.excludeHostNode import net.corda.core.identity.groupAbstractPartyByWellKnownParty @@ -15,6 +16,7 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockServices +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test @@ -22,6 +24,10 @@ import kotlin.reflect.KClass import kotlin.test.assertFailsWith class CollectSignaturesFlowTests { + companion object { + private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + } + private lateinit var mockNet: MockNetwork private lateinit var aliceNode: StartedNode private lateinit var bobNode: StartedNode @@ -34,9 +40,9 @@ class CollectSignaturesFlowTests { @Before fun setup() { mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) - aliceNode = mockNet.createPartyNode(ALICE.name) - bobNode = mockNet.createPartyNode(BOB.name) - charlieNode = mockNet.createPartyNode(CHARLIE.name) + aliceNode = mockNet.createPartyNode(ALICE_NAME) + bobNode = mockNet.createPartyNode(BOB_NAME) + charlieNode = mockNet.createPartyNode(CHARLIE_NAME) alice = aliceNode.info.singleIdentity() bob = bobNode.info.singleIdentity() charlie = charlieNode.info.singleIdentity() @@ -129,7 +135,7 @@ class CollectSignaturesFlowTests { @Test fun `fails when not signed by initiator`() { val onePartyDummyContract = DummyContract.generateInitial(1337, notary, alice.ref(1)) - val miniCorpServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), MINI_CORP.name, MINI_CORP_KEY) + val miniCorpServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), miniCorp) val ptx = miniCorpServices.signInitialTransaction(onePartyDummyContract) val flow = aliceNode.services.startFlow(CollectSignaturesFlow(ptx, emptySet())) mockNet.runNetwork() diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt index 9e51829bdc..eb3b5609a5 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt @@ -24,13 +24,13 @@ import net.corda.testing.ALICE_NAME import net.corda.testing.BOB_NAME import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyContractV2 -import net.corda.testing.internal.RPCDriverDSL -import net.corda.testing.internal.rpcDriver -import net.corda.testing.internal.rpcTestUser -import net.corda.testing.internal.startRpcClient +import net.corda.testing.node.internal.RPCDriverDSL +import net.corda.testing.node.internal.rpcDriver +import net.corda.testing.node.internal.rpcTestUser +import net.corda.testing.node.internal.startRpcClient import net.corda.testing.node.MockNetwork import net.corda.testing.singleIdentity -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt index 07ac06b4cd..bd4be11c16 100644 --- a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt @@ -9,6 +9,7 @@ import net.corda.finance.issuedBy import net.corda.node.services.api.StartedNodeServices import net.corda.testing.* import net.corda.testing.node.MockNetwork +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test @@ -16,6 +17,10 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class FinalityFlowTests { + companion object { + private val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party + } + private lateinit var mockNet: MockNetwork private lateinit var aliceServices: StartedNodeServices private lateinit var bobServices: StartedNodeServices diff --git a/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt index 2fc6be8955..d90bf3e2e6 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ReceiveAllFlowTests.kt @@ -7,7 +7,7 @@ import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap import net.corda.testing.node.MockNetwork import net.corda.testing.singleIdentity -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Test diff --git a/core/src/test/kotlin/net/corda/core/identity/PartyTest.kt b/core/src/test/kotlin/net/corda/core/identity/PartyTest.kt index 707e5b159b..28d6fb1fa3 100644 --- a/core/src/test/kotlin/net/corda/core/identity/PartyTest.kt +++ b/core/src/test/kotlin/net/corda/core/identity/PartyTest.kt @@ -1,7 +1,7 @@ package net.corda.core.identity import net.corda.core.crypto.entropyToKeyPair -import net.corda.testing.ALICE +import net.corda.testing.ALICE_NAME import org.junit.Test import java.math.BigInteger import kotlin.test.assertEquals @@ -13,7 +13,7 @@ class PartyTest { val key = entropyToKeyPair(BigInteger.valueOf(20170207L)).public val differentKey = entropyToKeyPair(BigInteger.valueOf(7201702L)).public val anonymousParty = AnonymousParty(key) - val party = Party(ALICE.name, key) + val party = Party(ALICE_NAME, key) assertEquals(party, anonymousParty) assertEquals(anonymousParty, party) assertNotEquals(AnonymousParty(differentKey), anonymousParty) diff --git a/core/src/test/kotlin/net/corda/core/internal/AbstractAttachmentTest.kt b/core/src/test/kotlin/net/corda/core/internal/AbstractAttachmentTest.kt index 3c3f224091..955ff7d2b2 100644 --- a/core/src/test/kotlin/net/corda/core/internal/AbstractAttachmentTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/AbstractAttachmentTest.kt @@ -1,7 +1,7 @@ package net.corda.core.internal -import net.corda.testing.ALICE -import net.corda.testing.BOB +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.After import org.junit.AfterClass @@ -29,8 +29,8 @@ class AbstractAttachmentTest { @BeforeClass @JvmStatic fun beforeClass() { - execute("keytool", "-genkey", "-keystore", "_teststore", "-storepass", "storepass", "-keyalg", "RSA", "-alias", "alice", "-keypass", "alicepass", "-dname", ALICE.toString()) - execute("keytool", "-genkey", "-keystore", "_teststore", "-storepass", "storepass", "-keyalg", "RSA", "-alias", "bob", "-keypass", "bobpass", "-dname", BOB.toString()) + execute("keytool", "-genkey", "-keystore", "_teststore", "-storepass", "storepass", "-keyalg", "RSA", "-alias", "alice", "-keypass", "alicepass", "-dname", ALICE_NAME.toString()) + execute("keytool", "-genkey", "-keystore", "_teststore", "-storepass", "storepass", "-keyalg", "RSA", "-alias", "bob", "-keypass", "bobpass", "-dname", BOB_NAME.toString()) (dir / "_signable1").writeLines(listOf("signable1")) (dir / "_signable2").writeLines(listOf("signable2")) (dir / "_signable3").writeLines(listOf("signable3")) @@ -76,10 +76,10 @@ class AbstractAttachmentTest { fun `one signer`() { execute("jar", "cvf", "attachment.jar", "_signable1", "_signable2") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "alicepass", "attachment.jar", "alice") - assertEquals(listOf(ALICE.name), load("attachment.jar").signers.map { it.name }) // We only reused ALICE's distinguished name, so the keys will be different. + assertEquals(listOf(ALICE_NAME), load("attachment.jar").signers.map { it.name }) // We only reused ALICE's distinguished name, so the keys will be different. (dir / "my-dir").createDirectory() execute("jar", "uvf", "attachment.jar", "my-dir") - assertEquals(listOf(ALICE.name), load("attachment.jar").signers.map { it.name }) // Unsigned directory is irrelevant. + assertEquals(listOf(ALICE_NAME), load("attachment.jar").signers.map { it.name }) // Unsigned directory is irrelevant. } @Test @@ -87,17 +87,17 @@ class AbstractAttachmentTest { execute("jar", "cvf", "attachment.jar", "_signable1", "_signable2") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "alicepass", "attachment.jar", "alice") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "bobpass", "attachment.jar", "bob") - assertEquals(listOf(ALICE.name, BOB.name), load("attachment.jar").signers.map { it.name }) + assertEquals(listOf(ALICE_NAME, BOB_NAME), load("attachment.jar").signers.map { it.name }) } @Test fun `a party must sign all the files in the attachment to be a signer`() { execute("jar", "cvf", "attachment.jar", "_signable1") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "alicepass", "attachment.jar", "alice") - assertEquals(listOf(ALICE.name), load("attachment.jar").signers.map { it.name }) + assertEquals(listOf(ALICE_NAME), load("attachment.jar").signers.map { it.name }) execute("jar", "uvf", "attachment.jar", "_signable2") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "bobpass", "attachment.jar", "bob") - assertEquals(listOf(BOB.name), load("attachment.jar").signers.map { it.name }) // ALICE hasn't signed the new file. + assertEquals(listOf(BOB_NAME), load("attachment.jar").signers.map { it.name }) // ALICE hasn't signed the new file. execute("jar", "uvf", "attachment.jar", "_signable3") assertEquals(emptyList(), load("attachment.jar").signers) // Neither party has signed the new file. } @@ -107,7 +107,7 @@ class AbstractAttachmentTest { (dir / "volatile").writeLines(listOf("volatile")) execute("jar", "cvf", "attachment.jar", "volatile") execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "alicepass", "attachment.jar", "alice") - assertEquals(listOf(ALICE.name), load("attachment.jar").signers.map { it.name }) + assertEquals(listOf(ALICE_NAME), load("attachment.jar").signers.map { it.name }) (dir / "volatile").writeLines(listOf("garbage")) execute("jar", "uvf", "attachment.jar", "volatile", "_signable1") // ALICE's signature on volatile is now bad. execute("jarsigner", "-keystore", "_teststore", "-storepass", "storepass", "-keypass", "bobpass", "attachment.jar", "bob") diff --git a/core/src/test/kotlin/net/corda/core/internal/LegalNameValidatorTest.kt b/core/src/test/kotlin/net/corda/core/internal/LegalNameValidatorTest.kt index fa854b42e4..5db052fcc1 100644 --- a/core/src/test/kotlin/net/corda/core/internal/LegalNameValidatorTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/LegalNameValidatorTest.kt @@ -8,55 +8,94 @@ class LegalNameValidatorTest { @Test fun `no double spaces`() { assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Test Legal Name") + LegalNameValidator.validateOrganization("Test Legal Name", LegalNameValidator.Validation.FULL) } - LegalNameValidator.validateOrganization(LegalNameValidator.normalize("Test Legal Name")) + LegalNameValidator.validateOrganization(LegalNameValidator.normalize("Test Legal Name"), LegalNameValidator.Validation.FULL) } @Test fun `no trailing white space`() { assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Test ") + LegalNameValidator.validateOrganization("Test ", LegalNameValidator.Validation.FULL) } } @Test fun `no prefixed white space`() { assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization(" Test") + LegalNameValidator.validateOrganization(" Test", LegalNameValidator.Validation.FULL) } } @Test fun `blacklisted words`() { assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Test Server") + LegalNameValidator.validateOrganization("Test Server", LegalNameValidator.Validation.FULL) } } @Test fun `blacklisted characters`() { - LegalNameValidator.validateOrganization("Test") + LegalNameValidator.validateOrganization("Test", LegalNameValidator.Validation.FULL) assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("\$Test") + LegalNameValidator.validateOrganization("\$Test", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("\"Test") + LegalNameValidator.validateOrganization("\"Test", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("\'Test") + LegalNameValidator.validateOrganization("\'Test", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("=Test") + LegalNameValidator.validateOrganization("=Test", LegalNameValidator.Validation.FULL) } } @Test - fun `unicode range`() { - LegalNameValidator.validateOrganization("Test A") + fun `unicode range in organization`() { + LegalNameValidator.validateOrganization("The quick brown fox jumped over the lazy dog.1234567890", LegalNameValidator.Validation.FULL) + assertFailsWith(IllegalArgumentException::class) { + // Null + LegalNameValidator.validateOrganization("\u0000R3 Null", LegalNameValidator.Validation.FULL) + } + assertFailsWith(IllegalArgumentException::class) { + // Right to left direction override + LegalNameValidator.validateOrganization("\u202EdtL 3R", LegalNameValidator.Validation.FULL) + } assertFailsWith(IllegalArgumentException::class) { // Greek letter A. - LegalNameValidator.validateOrganization("Test Α") + LegalNameValidator.validateOrganization("Test \u0391", LegalNameValidator.Validation.FULL) + } + // Latin capital letter turned m + assertFailsWith { + LegalNameValidator.validateOrganization( "Test\u019CLtd", LegalNameValidator.Validation.FULL) + } + // Latin small letter turned e + assertFailsWith { + LegalNameValidator.validateOrganization("Test\u01ddLtd", LegalNameValidator.Validation.FULL) + } + } + + @Test + fun `unicode range in general attributes`() { + LegalNameValidator.validateNameAttribute("The quick brown fox jumped over the lazy dog.1234567890", LegalNameValidator.Validation.FULL) + assertFailsWith(IllegalArgumentException::class) { + // Right to left direction override + LegalNameValidator.validateNameAttribute("\u202EdtL 3R", LegalNameValidator.Validation.FULL) + } + // Right to left direction override is okay with minimal validation though + LegalNameValidator.validateNameAttribute("\u202EdtL 3R", LegalNameValidator.Validation.MINIMAL) + assertFailsWith(IllegalArgumentException::class) { + // Greek letter A. + LegalNameValidator.validateNameAttribute("Test \u0391", LegalNameValidator.Validation.FULL) + } + // Latin capital letter turned m + assertFailsWith { + LegalNameValidator.validateNameAttribute( "Test\u019CLtd", LegalNameValidator.Validation.FULL) + } + // Latin small letter turned e + assertFailsWith { + LegalNameValidator.validateNameAttribute("Test\u01ddLtd", LegalNameValidator.Validation.FULL) } } @@ -66,21 +105,21 @@ class LegalNameValidatorTest { while (longLegalName.length < 255) { longLegalName.append("A") } - LegalNameValidator.validateOrganization(longLegalName.toString()) + LegalNameValidator.validateOrganization(longLegalName.toString(), LegalNameValidator.Validation.FULL) assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization(longLegalName.append("A").toString()) + LegalNameValidator.validateOrganization(longLegalName.append("A").toString(), LegalNameValidator.Validation.FULL) } } @Test fun `legal name should be capitalized`() { - LegalNameValidator.validateOrganization("Good legal name") + LegalNameValidator.validateOrganization("Good legal name", LegalNameValidator.Validation.FULL) assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("bad name") + LegalNameValidator.validateOrganization("bad name", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("bad Name") + LegalNameValidator.validateOrganization("bad Name", LegalNameValidator.Validation.FULL) } } @@ -90,13 +129,13 @@ class LegalNameValidatorTest { assertEquals("Legal Name With Unicode Whitespaces", LegalNameValidator.normalize("Legal Name\u2004With\u0009Unicode\u0020Whitespaces")) assertEquals("Legal Name With Line Breaks", LegalNameValidator.normalize("Legal Name With\n\rLine\nBreaks")) assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Legal Name With\tTab") + LegalNameValidator.validateOrganization("Legal Name With\tTab", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Legal Name\u2004With\u0009Unicode\u0020Whitespaces") + LegalNameValidator.validateOrganization("Legal Name\u2004With\u0009Unicode\u0020Whitespaces", LegalNameValidator.Validation.FULL) } assertFailsWith(IllegalArgumentException::class) { - LegalNameValidator.validateOrganization("Legal Name With\n\rLine\nBreaks") + LegalNameValidator.validateOrganization("Legal Name With\n\rLine\nBreaks", LegalNameValidator.Validation.FULL) } } } \ No newline at end of file diff --git a/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt b/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt index b56c5add9a..5121a9f6e5 100644 --- a/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt @@ -3,17 +3,16 @@ package net.corda.core.internal import co.paralleluniverse.fibers.Suspendable import net.corda.core.crypto.SecureHash import net.corda.core.flows.* +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.sequence import net.corda.node.internal.StartedNode -import net.corda.testing.MEGA_CORP -import net.corda.testing.MINI_CORP import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.singleIdentity -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test @@ -40,8 +39,8 @@ class ResolveTransactionsFlowTest { fun setup() { mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) notaryNode = mockNet.defaultNotaryNode - megaCorpNode = mockNet.createPartyNode(MEGA_CORP.name) - miniCorpNode = mockNet.createPartyNode(MINI_CORP.name) + megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB")) + miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB")) megaCorpNode.registerInitiatedFlow(TestResponseFlow::class.java) miniCorpNode.registerInitiatedFlow(TestResponseFlow::class.java) notary = mockNet.defaultNotaryIdentity diff --git a/core/src/test/kotlin/net/corda/core/node/VaultUpdateTests.kt b/core/src/test/kotlin/net/corda/core/node/VaultUpdateTests.kt index fc5872ce18..dd4c993837 100644 --- a/core/src/test/kotlin/net/corda/core/node/VaultUpdateTests.kt +++ b/core/src/test/kotlin/net/corda/core/node/VaultUpdateTests.kt @@ -5,14 +5,18 @@ import net.corda.core.crypto.SecureHash import net.corda.core.identity.AbstractParty import net.corda.core.node.services.Vault import net.corda.core.transactions.LedgerTransaction -import net.corda.testing.DUMMY_NOTARY +import net.corda.testing.DUMMY_NOTARY_NAME +import net.corda.testing.TestIdentity import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith class VaultUpdateTests { - val DUMMY_PROGRAM_ID = "net.corda.core.node.VaultUpdateTests.DummyContract" + private companion object { + val DUMMY_PROGRAM_ID = "net.corda.core.node.VaultUpdateTests.DummyContract" + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + } object DummyContract : Contract { diff --git a/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt b/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt index ec5cac3898..8d9303db22 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/AttachmentSerializationTest.kt @@ -21,7 +21,7 @@ import net.corda.testing.BOB_NAME import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters import net.corda.testing.singleIdentity -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt b/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt index bfdc34d30a..ca795cf4f0 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/TransactionSerializationTests.kt @@ -3,6 +3,7 @@ package net.corda.core.serialization import net.corda.core.contracts.* import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.seconds @@ -19,6 +20,16 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class TransactionSerializationTests { + private companion object { + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val MINI_CORP = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")).party + val DUMMY_NOTARY get() = dummyNotary.party + val DUMMY_NOTARY_KEY get() = dummyNotary.key + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_KEY get() = megaCorp.key + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/core/src/test/kotlin/net/corda/core/transactions/CompatibleTransactionTests.kt b/core/src/test/kotlin/net/corda/core/transactions/CompatibleTransactionTests.kt index 5461d280a1..e83b05e8f3 100644 --- a/core/src/test/kotlin/net/corda/core/transactions/CompatibleTransactionTests.kt +++ b/core/src/test/kotlin/net/corda/core/transactions/CompatibleTransactionTests.kt @@ -18,6 +18,8 @@ class CompatibleTransactionTests { private companion object { val DUMMY_KEY_1 = generateKeyPair() val DUMMY_KEY_2 = generateKeyPair() + val BOB = TestIdentity(BOB_NAME, 80).party + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party } @Rule diff --git a/core/src/test/kotlin/net/corda/core/transactions/LedgerTransactionQueryTests.kt b/core/src/test/kotlin/net/corda/core/transactions/LedgerTransactionQueryTests.kt index d9a8e9bc10..b343a5ed2a 100644 --- a/core/src/test/kotlin/net/corda/core/transactions/LedgerTransactionQueryTests.kt +++ b/core/src/test/kotlin/net/corda/core/transactions/LedgerTransactionQueryTests.kt @@ -5,6 +5,7 @@ import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* @@ -19,13 +20,17 @@ import kotlin.test.assertFailsWith import kotlin.test.assertTrue class LedgerTransactionQueryTests { + companion object { + private val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() private val keyPair = generateKeyPair() private val services = MockServices(rigorousMock().also { doReturn(null).whenever(it).partyFromKey(keyPair.public) - }, MEGA_CORP.name, keyPair) + }, CordaX500Name("MegaCorp", "London", "GB"), keyPair) private val identity: Party = services.myInfo.singleIdentity() @Before diff --git a/core/src/test/kotlin/net/corda/core/transactions/TransactionEncumbranceTests.kt b/core/src/test/kotlin/net/corda/core/transactions/TransactionEncumbranceTests.kt index b4c824026d..1f487f6808 100644 --- a/core/src/test/kotlin/net/corda/core/transactions/TransactionEncumbranceTests.kt +++ b/core/src/test/kotlin/net/corda/core/transactions/TransactionEncumbranceTests.kt @@ -6,12 +6,14 @@ import net.corda.core.contracts.Contract import net.corda.core.contracts.ContractState import net.corda.core.contracts.requireThat import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.finance.DOLLARS import net.corda.finance.`issued by` import net.corda.finance.contracts.asset.Cash import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* import net.corda.testing.node.MockServices +import net.corda.testing.node.ledger import org.junit.Rule import org.junit.Test import java.time.Instant @@ -20,6 +22,14 @@ import java.time.temporal.ChronoUnit val TEST_TIMELOCK_ID = "net.corda.core.transactions.TransactionEncumbranceTests\$DummyTimeLock" class TransactionEncumbranceTests { + private companion object { + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val MINI_CORP = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")).party + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/core/src/test/kotlin/net/corda/core/transactions/TransactionTests.kt b/core/src/test/kotlin/net/corda/core/transactions/TransactionTests.kt index fadd968dd9..8280d688e6 100644 --- a/core/src/test/kotlin/net/corda/core/transactions/TransactionTests.kt +++ b/core/src/test/kotlin/net/corda/core/transactions/TransactionTests.kt @@ -6,7 +6,6 @@ import net.corda.core.crypto.CompositeKey import net.corda.core.identity.Party import net.corda.testing.* import net.corda.testing.contracts.DummyContract -import net.corda.testing.node.MockAttachment import org.junit.Rule import org.junit.Test import java.math.BigInteger @@ -20,6 +19,11 @@ class TransactionTests { val DUMMY_KEY_1 = generateKeyPair() val DUMMY_KEY_2 = generateKeyPair() val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) + val ALICE = TestIdentity(ALICE_NAME, 70).party + val BOB = TestIdentity(BOB_NAME, 80).party + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val DUMMY_NOTARY get() = dummyNotary.party + val DUMMY_NOTARY_KEY get() = dummyNotary.key } @Rule @@ -107,7 +111,7 @@ class TransactionTests { val inputs = emptyList>() val outputs = listOf(baseOutState, baseOutState.copy(notary = ALICE), baseOutState.copy(notary = BOB)) val commands = emptyList>() - val attachments = listOf(ContractAttachment(MockAttachment(), DummyContract.PROGRAM_ID)) + val attachments = listOf(ContractAttachment(rigorousMock(), DummyContract.PROGRAM_ID)) val id = SecureHash.randomSHA256() val timeWindow: TimeWindow? = null val privacySalt: PrivacySalt = PrivacySalt() diff --git a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt index 699789bea8..afd231e868 100644 --- a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt +++ b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt @@ -44,8 +44,8 @@ class IntegrationTestingTutorial : IntegrationTest() { invokeRpc(CordaRPCOps::networkMapFeed) )) val (alice, bob) = listOf( - startNode(providedName = ALICE.name, rpcUsers = listOf(aliceUser)), - startNode(providedName = BOB.name, rpcUsers = listOf(bobUser)) + startNode(providedName = ALICE_NAME, rpcUsers = listOf(aliceUser)), + startNode(providedName = BOB_NAME, rpcUsers = listOf(bobUser)) ).transpose().getOrThrow() // END 1 diff --git a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java index 6b24146635..b9356d1d9f 100644 --- a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java +++ b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.Set; import static net.corda.core.contracts.ContractsDSL.requireThat; -import static net.corda.testing.TestConstants.getALICE_KEY; +import static net.corda.core.crypto.Crypto.generateKeyPair; @SuppressWarnings("unused") public class FlowCookbookJava { @@ -107,9 +107,7 @@ public class FlowCookbookJava { @Override public Void call() throws FlowException { // We'll be using a dummy public key for demonstration purposes. - // These are built in to Corda, and are generally used for writing - // tests. - PublicKey dummyPubKey = getALICE_KEY().getPublic(); + PublicKey dummyPubKey = generateKeyPair().getPublic(); /*--------------------------- * IDENTIFYING OTHER NODES * diff --git a/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java b/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java index 07f96740a0..6c83cabfc6 100644 --- a/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java +++ b/docs/source/example-code/src/main/java/net/corda/docs/java/tutorial/testdsl/CommercialPaperTest.java @@ -2,47 +2,56 @@ package net.corda.docs.java.tutorial.testdsl; import kotlin.Unit; import net.corda.core.contracts.PartyAndReference; -import net.corda.core.utilities.OpaqueBytes; +import net.corda.core.identity.CordaX500Name; +import net.corda.core.identity.Party; import net.corda.finance.contracts.ICommercialPaperState; import net.corda.finance.contracts.JavaCommercialPaper; import net.corda.finance.contracts.asset.Cash; import net.corda.node.services.api.IdentityServiceInternal; import net.corda.testing.SerializationEnvironmentRule; import net.corda.testing.node.MockServices; +import net.corda.testing.TestIdentity; import org.junit.Rule; import org.junit.Test; +import java.security.PublicKey; import java.time.temporal.ChronoUnit; +import static net.corda.core.crypto.Crypto.generateKeyPair; import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.Currencies.issuedBy; import static net.corda.finance.contracts.JavaCommercialPaper.JCP_PROGRAM_ID; -import static net.corda.testing.CoreTestUtils.*; -import static net.corda.testing.NodeTestUtils.ledger; -import static net.corda.testing.NodeTestUtils.transaction; +import static net.corda.testing.node.NodeTestUtils.ledger; +import static net.corda.testing.node.NodeTestUtils.transaction; +import static net.corda.testing.CoreTestUtils.rigorousMock; import static net.corda.testing.TestConstants.*; import static org.mockito.Mockito.doReturn; public class CommercialPaperTest { + private static final TestIdentity ALICE = new TestIdentity(getALICE_NAME(), 70L); + private static final PublicKey BIG_CORP_PUBKEY = generateKeyPair().getPublic(); + private static final TestIdentity BOB = new TestIdentity(getBOB_NAME(), 80L); + private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); + private static final Party DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L).getParty(); @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); - private final OpaqueBytes defaultRef = new OpaqueBytes(new byte[]{123}); + private final byte[] defaultRef = {123}; private final MockServices ledgerServices; { IdentityServiceInternal identityService = rigorousMock(IdentityServiceInternal.class); - doReturn(getMEGA_CORP()).when(identityService).partyFromKey(getMEGA_CORP_PUBKEY()); - doReturn(null).when(identityService).partyFromKey(getBIG_CORP_PUBKEY()); - doReturn(null).when(identityService).partyFromKey(getALICE_PUBKEY()); - ledgerServices = new MockServices(identityService, getMEGA_CORP().getName()); + doReturn(MEGA_CORP.getParty()).when(identityService).partyFromKey(MEGA_CORP.getPubkey()); + doReturn(null).when(identityService).partyFromKey(BIG_CORP_PUBKEY); + doReturn(null).when(identityService).partyFromKey(ALICE.getPubkey()); + ledgerServices = new MockServices(identityService, MEGA_CORP.getName()); } // DOCSTART 1 private ICommercialPaperState getPaper() { return new JavaCommercialPaper.State( - getMEGA_CORP().ref(defaultRef), - getMEGA_CORP(), - issuedBy(DOLLARS(1000), getMEGA_CORP().ref(defaultRef)), + MEGA_CORP.ref(defaultRef), + MEGA_CORP.getParty(), + issuedBy(DOLLARS(1000), MEGA_CORP.ref(defaultRef)), getTEST_TX_TIME().plus(7, ChronoUnit.DAYS) ); } @@ -52,7 +61,7 @@ public class CommercialPaperTest { @Test public void simpleCP() { ICommercialPaperState inState = getPaper(); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.transaction(tx -> { tx.attachments(JCP_PROGRAM_ID); tx.input(JCP_PROGRAM_ID, inState); @@ -67,10 +76,10 @@ public class CommercialPaperTest { @Test public void simpleCPMove() { ICommercialPaperState inState = getPaper(); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.transaction(tx -> { tx.input(JCP_PROGRAM_ID, inState); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); tx.attachments(JCP_PROGRAM_ID); return tx.verifies(); }); @@ -83,10 +92,10 @@ public class CommercialPaperTest { @Test public void simpleCPMoveFails() { ICommercialPaperState inState = getPaper(); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.transaction(tx -> { tx.input(JCP_PROGRAM_ID, inState); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); tx.attachments(JCP_PROGRAM_ID); return tx.failsWith("the state is propagated"); }); @@ -99,13 +108,13 @@ public class CommercialPaperTest { @Test public void simpleCPMoveSuccess() { ICommercialPaperState inState = getPaper(); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.transaction(tx -> { tx.input(JCP_PROGRAM_ID, inState); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); tx.attachments(JCP_PROGRAM_ID); tx.failsWith("the state is propagated"); - tx.output(JCP_PROGRAM_ID, "alice's paper", inState.withOwner(getALICE())); + tx.output(JCP_PROGRAM_ID, "alice's paper", inState.withOwner(ALICE.getParty())); return tx.verifies(); }); return Unit.INSTANCE; @@ -116,16 +125,16 @@ public class CommercialPaperTest { // DOCSTART 6 @Test public void simpleIssuanceWithTweak() { - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.transaction(tx -> { tx.output(JCP_PROGRAM_ID, "paper", getPaper()); // Some CP is issued onto the ledger by MegaCorp. tx.attachments(JCP_PROGRAM_ID); tx.tweak(tw -> { - tw.command(getBIG_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue()); tw.timeWindow(getTEST_TX_TIME()); return tw.failsWith("output states are issued by a command signer"); }); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Issue()); tx.timeWindow(getTEST_TX_TIME()); return tx.verifies(); }); @@ -137,15 +146,15 @@ public class CommercialPaperTest { // DOCSTART 7 @Test public void simpleIssuanceWithTweakTopLevelTx() { - transaction(ledgerServices, getDUMMY_NOTARY(), tx -> { + transaction(ledgerServices, DUMMY_NOTARY, tx -> { tx.output(JCP_PROGRAM_ID, "paper", getPaper()); // Some CP is issued onto the ledger by MegaCorp. tx.attachments(JCP_PROGRAM_ID); tx.tweak(tw -> { - tw.command(getBIG_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue()); tw.timeWindow(getTEST_TX_TIME()); return tw.failsWith("output states are issued by a command signer"); }); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Issue()); tx.timeWindow(getTEST_TX_TIME()); return tx.verifies(); }); @@ -155,11 +164,11 @@ public class CommercialPaperTest { // DOCSTART 8 @Test public void chainCommercialPaper() { - PartyAndReference issuer = getMEGA_CORP().ref(defaultRef); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + PartyAndReference issuer = MEGA_CORP.ref(defaultRef); + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.unverifiedTransaction(tx -> { tx.output(Cash.PROGRAM_ID, "alice's $900", - new Cash.State(issuedBy(DOLLARS(900), issuer), getALICE())); + new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty())); tx.attachments(Cash.PROGRAM_ID); return Unit.INSTANCE; }); @@ -167,7 +176,7 @@ public class CommercialPaperTest { // Some CP is issued onto the ledger by MegaCorp. l.transaction("Issuance", tx -> { tx.output(JCP_PROGRAM_ID, "paper", getPaper()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); tx.timeWindow(getTEST_TX_TIME()); return tx.verifies(); @@ -176,11 +185,11 @@ public class CommercialPaperTest { l.transaction("Trade", tx -> { tx.input("paper"); tx.input("alice's $900"); - tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), getMEGA_CORP())); + tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty())); JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper"); - tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(getALICE())); - tx.command(getALICE_PUBKEY(), new Cash.Commands.Move()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty())); + tx.command(ALICE.getPubkey(), new Cash.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); return tx.verifies(); }); return Unit.INSTANCE; @@ -191,11 +200,11 @@ public class CommercialPaperTest { // DOCSTART 9 @Test public void chainCommercialPaperDoubleSpend() { - PartyAndReference issuer = getMEGA_CORP().ref(defaultRef); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + PartyAndReference issuer = MEGA_CORP.ref(defaultRef); + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.unverifiedTransaction(tx -> { tx.output(Cash.PROGRAM_ID, "alice's $900", - new Cash.State(issuedBy(DOLLARS(900), issuer), getALICE())); + new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty())); tx.attachments(Cash.PROGRAM_ID); return Unit.INSTANCE; }); @@ -203,7 +212,7 @@ public class CommercialPaperTest { // Some CP is issued onto the ledger by MegaCorp. l.transaction("Issuance", tx -> { tx.output(Cash.PROGRAM_ID, "paper", getPaper()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); tx.timeWindow(getTEST_TX_TIME()); return tx.verifies(); @@ -212,11 +221,11 @@ public class CommercialPaperTest { l.transaction("Trade", tx -> { tx.input("paper"); tx.input("alice's $900"); - tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), getMEGA_CORP())); + tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty())); JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper"); - tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(getALICE())); - tx.command(getALICE_PUBKEY(), new Cash.Commands.Move()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty())); + tx.command(ALICE.getPubkey(), new Cash.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); return tx.verifies(); }); @@ -224,8 +233,8 @@ public class CommercialPaperTest { tx.input("paper"); JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper"); // We moved a paper to other pubkey. - tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(getBOB())); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(BOB.getParty())); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); return tx.verifies(); }); l.fails(); @@ -237,11 +246,11 @@ public class CommercialPaperTest { // DOCSTART 10 @Test public void chainCommercialPaperTweak() { - PartyAndReference issuer = getMEGA_CORP().ref(defaultRef); - ledger(ledgerServices, getDUMMY_NOTARY(), l -> { + PartyAndReference issuer = MEGA_CORP.ref(defaultRef); + ledger(ledgerServices, DUMMY_NOTARY, l -> { l.unverifiedTransaction(tx -> { tx.output(Cash.PROGRAM_ID, "alice's $900", - new Cash.State(issuedBy(DOLLARS(900), issuer), getALICE())); + new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty())); tx.attachments(Cash.PROGRAM_ID); return Unit.INSTANCE; }); @@ -249,7 +258,7 @@ public class CommercialPaperTest { // Some CP is issued onto the ledger by MegaCorp. l.transaction("Issuance", tx -> { tx.output(Cash.PROGRAM_ID, "paper", getPaper()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Issue()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Issue()); tx.attachments(JCP_PROGRAM_ID); tx.timeWindow(getTEST_TX_TIME()); return tx.verifies(); @@ -258,11 +267,11 @@ public class CommercialPaperTest { l.transaction("Trade", tx -> { tx.input("paper"); tx.input("alice's $900"); - tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), getMEGA_CORP())); + tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty())); JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper"); - tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(getALICE())); - tx.command(getALICE_PUBKEY(), new Cash.Commands.Move()); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty())); + tx.command(ALICE.getPubkey(), new Cash.Commands.Move()); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); return tx.verifies(); }); @@ -271,8 +280,8 @@ public class CommercialPaperTest { tx.input("paper"); JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper"); // We moved a paper to another pubkey. - tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(getBOB())); - tx.command(getMEGA_CORP_PUBKEY(), new JavaCommercialPaper.Commands.Move()); + tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(BOB.getParty())); + tx.command(MEGA_CORP.getPubkey(), new JavaCommercialPaper.Commands.Move()); return tx.verifies(); }); lw.fails(); diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt index 954a67c239..685a10c4ad 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt @@ -18,7 +18,7 @@ import net.corda.finance.flows.CashPaymentFlow import net.corda.node.services.Permissions.Companion.invokeRpc import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User -import net.corda.testing.ALICE +import net.corda.testing.ALICE_NAME import net.corda.testing.driver.driver import org.graphstream.graph.Edge import org.graphstream.graph.Node @@ -49,7 +49,7 @@ fun main(args: Array) { invokeRpc(CordaRPCOps::nodeInfo) )) driver(driverDirectory = baseDirectory, extraCordappPackagesToScan = listOf("net.corda.finance"), waitForAllNodesToFinish = true) { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user)).get() + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)).get() // END 1 // START 2 diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt index 3718ec1bfe..81792eb864 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt @@ -6,6 +6,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash import net.corda.core.crypto.TransactionSignature +import net.corda.core.crypto.generateKeyPair import net.corda.core.flows.* import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party @@ -23,7 +24,6 @@ import net.corda.core.utilities.UntrustworthyData import net.corda.core.utilities.seconds import net.corda.core.utilities.unwrap import net.corda.finance.contracts.asset.Cash -import net.corda.testing.ALICE_PUBKEY import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyState import java.security.PublicKey @@ -87,9 +87,7 @@ class InitiatorFlow(val arg1: Boolean, val arg2: Int, private val counterparty: @Suspendable override fun call() { // We'll be using a dummy public key for demonstration purposes. - // These are built in to Corda, and are generally used for writing - // tests. - val dummyPubKey: PublicKey = ALICE_PUBKEY + val dummyPubKey: PublicKey = generateKeyPair().public /**-------------------------- * IDENTIFYING OTHER NODES * diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/mocknetwork/TutorialMockNetwork.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/mocknetwork/TutorialMockNetwork.kt index 595db4bb6e..911b7cefde 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/mocknetwork/TutorialMockNetwork.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/mocknetwork/TutorialMockNetwork.kt @@ -21,7 +21,7 @@ import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.MessagingServiceSpy import net.corda.testing.node.MockNetwork import net.corda.testing.node.setMessagingServiceSpy -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Rule diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/tearoffs/TutorialTearOffs.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/tearoffs/TutorialTearOffs.kt index c560c4f3f4..705f1f0bac 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/tearoffs/TutorialTearOffs.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/tearoffs/TutorialTearOffs.kt @@ -4,16 +4,16 @@ import net.corda.core.contracts.Command import net.corda.core.contracts.StateRef import net.corda.core.contracts.TimeWindow import net.corda.core.crypto.MerkleTreeException +import net.corda.core.identity.AbstractParty import net.corda.core.transactions.FilteredTransaction import net.corda.core.transactions.FilteredTransactionVerificationException import net.corda.core.transactions.SignedTransaction import net.corda.finance.contracts.Fix -import net.corda.testing.ALICE import java.util.function.Predicate fun main(args: Array) { // Typealias to make the example coherent. - val oracle = ALICE + val oracle = Any() as AbstractParty val stx = Any() as SignedTransaction // DOCSTART 1 diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/testdsl/TutorialTestDSL.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/testdsl/TutorialTestDSL.kt index eceadf55a7..6754a6082c 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/testdsl/TutorialTestDSL.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/tutorial/testdsl/TutorialTestDSL.kt @@ -2,6 +2,8 @@ package net.corda.docs.tutorial.testdsl import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever +import net.corda.core.crypto.generateKeyPair +import net.corda.core.identity.CordaX500Name import net.corda.core.utilities.days import net.corda.finance.DOLLARS import net.corda.finance.`issued by` @@ -13,10 +15,24 @@ import net.corda.finance.contracts.asset.Cash import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* import net.corda.testing.node.MockServices +import net.corda.testing.node.ledger +import net.corda.testing.node.transaction import org.junit.Rule import org.junit.Test class CommercialPaperTest { + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val BIG_CORP_PUBKEY = generateKeyPair().public + val BOB = TestIdentity(BOB_NAME, 80).party + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val ALICE get() = alice.party + val ALICE_PUBKEY get() = alice.pubkey + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt index ef2acb083b..f2ecb42a3f 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt @@ -10,7 +10,7 @@ import net.corda.finance.flows.CashIssueFlow import net.corda.node.internal.StartedNode import net.corda.testing.chooseIdentity import net.corda.testing.node.MockNetwork -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Assert import org.junit.Before diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt index c53fe8e175..5009779529 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt @@ -10,7 +10,7 @@ import net.corda.finance.flows.CashIssueFlow import net.corda.node.internal.StartedNode import net.corda.testing.chooseIdentity import net.corda.testing.node.MockNetwork -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt index d4fb476134..dca397eb98 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt @@ -12,6 +12,7 @@ import net.corda.core.utilities.getOrThrow import net.corda.node.services.api.StartedNodeServices import net.corda.testing.* import net.corda.testing.node.MockNetwork +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/docs/source/generating-a-node.rst b/docs/source/generating-a-node.rst index 614c8084ec..4a721e304d 100644 --- a/docs/source/generating-a-node.rst +++ b/docs/source/generating-a-node.rst @@ -50,17 +50,21 @@ The name must also obey the following constraints: * The country attribute is a valid ISO 3166-1 two letter code in upper-case -* The organisation field of the name obeys the following constraints: +* All attributes must obey the following constraints: * Upper-case first letter * Has at least two letters * No leading or trailing whitespace - * No double-spacing - * Does not contain the words "node" or "server" * Does not include the following characters: ``,`` , ``=`` , ``$`` , ``"`` , ``'`` , ``\`` * Is in NFKC normalization form + * Does not contain the null character * Only the latin, common and inherited unicode scripts are supported +* The organisation field of the name also obeys the following constraints: + + * No double-spacing + * Does not contain the words "node" or "server" + * This is to avoid right-to-left issues, debugging issues when we can't pronounce names over the phone, and character confusability attacks @@ -149,4 +153,4 @@ in the ``deployNodes`` task, plus a ``runnodes`` shell script (or batch file on for testing and development purposes. If you make any changes to your CorDapp source or ``deployNodes`` task, you will need to re-run the task to see the changes take effect. -You can now run the nodes by following the instructions in :doc:`Running a node `. \ No newline at end of file +You can now run the nodes by following the instructions in :doc:`Running a node `. diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt index e77ca43f4c..bb458188e6 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt @@ -2,9 +2,7 @@ package net.corda.finance.contracts.universal import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.identity.CordaX500Name -import net.corda.core.identity.Party import net.corda.finance.contracts.BusinessCalendar import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Frequency @@ -12,20 +10,20 @@ import net.corda.finance.contracts.Tenor import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* import net.corda.testing.node.MockServices -import net.corda.testing.node.makeTestIdentityService +import net.corda.testing.node.transaction import org.junit.Ignore import org.junit.Rule import org.junit.Test -import java.math.BigInteger import java.time.Instant import java.time.LocalDate +internal val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party fun transaction(script: TransactionDSL.() -> EnforceVerifyOrFail) = run { MockServices(listOf("net.corda.finance.contracts.universal"), rigorousMock().also { listOf(acmeCorp, highStreetBank, momAndPop).forEach { party -> doReturn(null).whenever(it).partyFromKey(party.owningKey) } - }, MEGA_CORP.name).transaction(DUMMY_NOTARY, script) + }, CordaX500Name("MegaCorp", "London", "GB")).transaction(DUMMY_NOTARY, script) } class Cap { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt index 7436161cd4..c9535fd109 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt @@ -2,7 +2,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Tenor -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Ignore import org.junit.Rule diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt index 75924ff0e0..112093b4b4 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt @@ -1,20 +1,17 @@ package net.corda.finance.contracts.universal import net.corda.core.crypto.generateKeyPair -import net.corda.core.identity.Party -import net.corda.testing.ALICE -import net.corda.testing.MEGA_CORP -import net.corda.testing.MINI_CORP +import net.corda.core.identity.CordaX500Name +import net.corda.testing.TestIdentity import org.junit.Test import java.util.* import kotlin.test.assertEquals import kotlin.test.assertTrue // Test parties -val acmeCorp = Party(ALICE.name, generateKeyPair().public) -val highStreetBank = Party(MEGA_CORP.name, generateKeyPair().public) -val momAndPop = Party(MINI_CORP.name, generateKeyPair().public) - +val acmeCorp = TestIdentity(CordaX500Name("Alice Corp", "Madrid", "ES")).party +val highStreetBank = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party +val momAndPop = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")).party val acmeCorporationHasDefaulted = TerminalEvent(acmeCorp, generateKeyPair().public) diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt index 1d05fe061a..380dd564d2 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt @@ -1,6 +1,5 @@ package net.corda.finance.contracts.universal -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Ignore import org.junit.Rule diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt index fc91215046..4dadb338c2 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt @@ -1,6 +1,5 @@ package net.corda.finance.contracts.universal -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Ignore import org.junit.Rule diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt index e2f0d4f942..ae88022c78 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt @@ -3,7 +3,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Frequency import net.corda.finance.contracts.Tenor -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Ignore import org.junit.Rule diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt index 34ba966a0c..185cebd57a 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt @@ -1,7 +1,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.Frequency -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Rule import org.junit.Test diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt index f80c3d5fd3..aa82468c30 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt @@ -2,7 +2,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.Frequency import net.corda.finance.contracts.Tenor -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Ignore import org.junit.Rule diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt index 2554b0c58b..10aee2e760 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt @@ -1,6 +1,5 @@ package net.corda.finance.contracts.universal -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.SerializationEnvironmentRule import org.junit.Rule import org.junit.Test diff --git a/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java b/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java index 5ab3569b25..ce7273f75b 100644 --- a/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java +++ b/finance/src/test/java/net/corda/finance/contracts/asset/CashTestsJava.java @@ -2,72 +2,76 @@ package net.corda.finance.contracts.asset; import net.corda.core.contracts.PartyAndReference; import net.corda.core.identity.AnonymousParty; -import net.corda.core.utilities.OpaqueBytes; +import net.corda.core.identity.CordaX500Name; +import net.corda.core.identity.Party; import net.corda.node.services.api.IdentityServiceInternal; import net.corda.testing.DummyCommandData; import net.corda.testing.SerializationEnvironmentRule; +import net.corda.testing.TestIdentity; import net.corda.testing.node.MockServices; import org.junit.Rule; import org.junit.Test; import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.Currencies.issuedBy; -import static net.corda.testing.CoreTestUtils.*; -import static net.corda.testing.NodeTestUtils.transaction; -import static net.corda.testing.TestConstants.getDUMMY_NOTARY; +import static net.corda.testing.node.NodeTestUtils.transaction; +import static net.corda.testing.CoreTestUtils.rigorousMock; +import static net.corda.testing.TestConstants.getDUMMY_NOTARY_NAME; import static org.mockito.Mockito.doReturn; /** * This is an incomplete Java replica of CashTests.kt to show how to use the Java test DSL */ public class CashTestsJava { - private final OpaqueBytes defaultRef = new OpaqueBytes(new byte[]{1}); - private final PartyAndReference defaultIssuer = getMEGA_CORP().ref(defaultRef); - private final Cash.State inState = new Cash.State(issuedBy(DOLLARS(1000), defaultIssuer), new AnonymousParty(getMEGA_CORP_PUBKEY())); - private final Cash.State outState = new Cash.State(inState.getAmount(), new AnonymousParty(getMINI_CORP_PUBKEY())); + private static final Party DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L).getParty(); + private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); + private static final TestIdentity MINI_CORP = new TestIdentity(new CordaX500Name("MiniCorp", "London", "GB")); + private final PartyAndReference defaultIssuer = MEGA_CORP.ref((byte) 1); + private final Cash.State inState = new Cash.State(issuedBy(DOLLARS(1000), defaultIssuer), new AnonymousParty(MEGA_CORP.getPubkey())); + private final Cash.State outState = new Cash.State(inState.getAmount(), new AnonymousParty(MINI_CORP.getPubkey())); @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); @Test public void trivial() { IdentityServiceInternal identityService = rigorousMock(IdentityServiceInternal.class); - doReturn(getMEGA_CORP()).when(identityService).partyFromKey(getMEGA_CORP_PUBKEY()); - doReturn(getMINI_CORP()).when(identityService).partyFromKey(getMINI_CORP_PUBKEY()); - transaction(new MockServices(identityService, getMEGA_CORP().getName()), getDUMMY_NOTARY(), tx -> { + doReturn(MEGA_CORP.getParty()).when(identityService).partyFromKey(MEGA_CORP.getPubkey()); + doReturn(MINI_CORP.getParty()).when(identityService).partyFromKey(MINI_CORP.getPubkey()); + transaction(new MockServices(identityService, MEGA_CORP.getName()), DUMMY_NOTARY, tx -> { tx.attachment(Cash.PROGRAM_ID); tx.input(Cash.PROGRAM_ID, inState); tx.tweak(tw -> { - tw.output(Cash.PROGRAM_ID, new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(getMINI_CORP_PUBKEY()))); - tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move()); + tw.output(Cash.PROGRAM_ID, new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(MINI_CORP.getPubkey()))); + tw.command(MEGA_CORP.getPubkey(), new Cash.Commands.Move()); return tw.failsWith("the amounts balance"); }); tx.tweak(tw -> { tw.output(Cash.PROGRAM_ID, outState); - tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE); + tw.command(MEGA_CORP.getPubkey(), DummyCommandData.INSTANCE); // Invalid command return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command"); }); tx.tweak(tw -> { tw.output(Cash.PROGRAM_ID, outState); - tw.command(getMINI_CORP_PUBKEY(), new Cash.Commands.Move()); + tw.command(MINI_CORP.getPubkey(), new Cash.Commands.Move()); return tw.failsWith("the owning keys are a subset of the signing keys"); }); tx.tweak(tw -> { tw.output(Cash.PROGRAM_ID, outState); // issuedBy() can't be directly imported because it conflicts with other identically named functions // with different overloads (for some reason). - tw.output(Cash.PROGRAM_ID, outState.issuedBy(getMINI_CORP())); - tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move()); + tw.output(Cash.PROGRAM_ID, outState.issuedBy(MINI_CORP.getParty())); + tw.command(MEGA_CORP.getPubkey(), new Cash.Commands.Move()); return tw.failsWith("at least one cash input"); }); // Simple reallocation works. return tx.tweak(tw -> { tw.output(Cash.PROGRAM_ID, outState); - tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move()); + tw.command(MEGA_CORP.getPubkey(), new Cash.Commands.Move()); return tw.verifies(); }); }); diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt index ff6d194737..71ae00d507 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt @@ -3,7 +3,7 @@ package net.corda.finance.contracts import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* -import net.corda.core.crypto.entropyToKeyPair +import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AnonymousParty import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party @@ -21,12 +21,13 @@ import net.corda.testing.* import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices +import net.corda.testing.node.ledger import net.corda.testing.node.makeTestIdentityService +import net.corda.testing.node.transaction import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized -import java.math.BigInteger import java.time.Instant import java.util.* import kotlin.test.assertFailsWith @@ -42,6 +43,11 @@ interface ICommercialPaperTestTemplate { fun getContract(): ContractClassName } +private val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) +private val MEGA_CORP get() = megaCorp.party +private val MEGA_CORP_IDENTITY get() = megaCorp.identity +private val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + class JavaCommercialPaperTest : ICommercialPaperTestTemplate { override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State( MEGA_CORP.ref(123), @@ -91,9 +97,21 @@ class CommercialPaperTestsGeneric { @JvmStatic fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest()) - private val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) - private val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), DUMMY_CASH_ISSUER_KEY.public)) - private val DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.party.ref(1) + private val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) + private val DUMMY_CASH_ISSUER_IDENTITY get() = dummyCashIssuer.identity + private val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1) + private val alice = TestIdentity(ALICE_NAME, 70) + private val BIG_CORP_KEY = generateKeyPair() + private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + private val ALICE get() = alice.party + private val ALICE_KEY get() = alice.key + private val ALICE_PUBKEY get() = alice.pubkey + private val DUMMY_NOTARY get() = dummyNotary.party + private val DUMMY_NOTARY_IDENTITY get() = dummyNotary.identity + private val MINI_CORP get() = miniCorp.party + private val MINI_CORP_IDENTITY get() = miniCorp.identity + private val MINI_CORP_PUBKEY get() = miniCorp.pubkey } @Parameterized.Parameter @@ -242,8 +260,8 @@ class CommercialPaperTestsGeneric { private lateinit var aliceServices: MockServices private lateinit var aliceVaultService: VaultService private lateinit var alicesVault: Vault - private val notaryServices = MockServices(rigorousMock(), MEGA_CORP.name, DUMMY_NOTARY_KEY) - private val issuerServices = MockServices(listOf("net.corda.finance.contracts"), rigorousMock(), MEGA_CORP.name, DUMMY_CASH_ISSUER_KEY) + private val notaryServices = MockServices(rigorousMock(), MEGA_CORP.name, dummyNotary.key) + private val issuerServices = MockServices(listOf("net.corda.finance.contracts"), rigorousMock(), MEGA_CORP.name, dummyCashIssuer.key) private lateinit var moveTX: SignedTransaction @Test fun `issue move and then redeem`() { @@ -257,7 +275,7 @@ class CommercialPaperTestsGeneric { aliceVaultService = aliceServices.vaultService databaseAlice.transaction { - alicesVault = VaultFiller(aliceServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(9000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) + alicesVault = VaultFiller(aliceServices, dummyNotary, rngFactory = ::Random).fillWithSomeTestCash(9000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) aliceVaultService = aliceServices.vaultService } val bigCorpDatabaseAndServices = makeTestDatabaseAndMockServices( @@ -270,7 +288,7 @@ class CommercialPaperTestsGeneric { bigCorpVaultService = bigCorpServices.vaultService databaseBigCorp.transaction { - bigCorpVault = VaultFiller(bigCorpServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(13000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) + bigCorpVault = VaultFiller(bigCorpServices, dummyNotary, rngFactory = ::Random).fillWithSomeTestCash(13000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) bigCorpVaultService = bigCorpServices.vaultService } diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt index 261ee64b95..760aab4aea 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt @@ -3,7 +3,6 @@ package net.corda.finance.contracts.asset import com.nhaarman.mockito_kotlin.* import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.* import net.corda.core.node.ServiceHub @@ -25,24 +24,46 @@ import net.corda.testing.contracts.DummyState import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices +import net.corda.testing.node.ledger import net.corda.testing.node.makeTestIdentityService +import net.corda.testing.node.transaction import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import java.math.BigInteger import java.util.* import kotlin.test.* class CashTests { - companion object { - private val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), entropyToKeyPair(BigInteger.valueOf(10)).public)) + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val BOB_PUBKEY = TestIdentity(BOB_NAME, 80).pubkey + val charlie = TestIdentity(CHARLIE_NAME, 90) + val DUMMY_CASH_ISSUER_IDENTITY = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10).identity + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val ALICE get() = alice.party + val ALICE_PUBKEY get() = alice.pubkey + val CHARLIE get() = charlie.party + val CHARLIE_IDENTITY get() = charlie.identity + val DUMMY_NOTARY get() = dummyNotary.party + val DUMMY_NOTARY_IDENTITY get() = dummyNotary.identity + val DUMMY_NOTARY_KEY get() = dummyNotary.key + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_IDENTITY get() = megaCorp.identity + val MEGA_CORP_KEY get() = megaCorp.key + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MINI_CORP get() = miniCorp.party + val MINI_CORP_IDENTITY get() = miniCorp.identity + val MINI_CORP_KEY get() = miniCorp.key + val MINI_CORP_PUBKEY get() = miniCorp.pubkey } @Rule @JvmField val testSerialization = SerializationEnvironmentRule() - private val defaultRef = OpaqueBytes(ByteArray(1, { 1 })) + private val defaultRef = OpaqueBytes.of(1) private val defaultIssuer = MEGA_CORP.ref(defaultRef) private val inState = Cash.State( amount = 1000.DOLLARS `issued by` defaultIssuer, @@ -94,7 +115,7 @@ class CashTests { // Create some cash. Any attempt to spend >$500 will require multiple issuers to be involved. database.transaction { - val vaultFiller = VaultFiller(ourServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random) + val vaultFiller = VaultFiller(ourServices, dummyNotary, rngFactory = ::Random) vaultFiller.fillWithSomeTestCash(100.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity) vaultFiller.fillWithSomeTestCash(400.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity) vaultFiller.fillWithSomeTestCash(80.DOLLARS, miniCorpServices, 1, MINI_CORP.ref(1), ourIdentity) diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt index 803954541f..2670b0674f 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt @@ -5,12 +5,10 @@ import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.crypto.NullKeys.NULL_PARTY import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.sha256 import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.CordaX500Name -import net.corda.core.identity.Party import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.OpaqueBytes @@ -25,9 +23,10 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyState import net.corda.testing.node.MockServices +import net.corda.testing.node.ledger +import net.corda.testing.node.transaction import org.junit.Rule import org.junit.Test -import java.math.BigInteger import java.time.Instant import java.time.temporal.ChronoUnit import java.util.* @@ -37,8 +36,23 @@ import kotlin.test.assertNotEquals import kotlin.test.assertTrue class ObligationTests { - companion object { - private val DUMMY_OBLIGATION_ISSUER = Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), entropyToKeyPair(BigInteger.valueOf(10)).public) + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val bob = TestIdentity(BOB_NAME, 80) + val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val DUMMY_OBLIGATION_ISSUER = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10).party + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val ALICE get() = alice.party + val ALICE_PUBKEY get() = alice.pubkey + val BOB get() = bob.party + val BOB_PUBKEY get() = bob.pubkey + val DUMMY_NOTARY get() = dummyNotary.party + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MINI_CORP get() = miniCorp.party + val MINI_CORP_PUBKEY get() = miniCorp.pubkey } @Rule @@ -62,8 +76,8 @@ class ObligationTests { beneficiary = CHARLIE ) private val outState = inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) - private val miniCorpServices = MockServices(listOf("net.corda.finance.contracts.asset"), rigorousMock(), MINI_CORP.name, MINI_CORP_KEY) - private val notaryServices = MockServices(rigorousMock(), MEGA_CORP.name, DUMMY_NOTARY_KEY) + private val miniCorpServices = MockServices(listOf("net.corda.finance.contracts.asset"), rigorousMock(), miniCorp) + private val notaryServices = MockServices(rigorousMock(), MEGA_CORP.name, dummyNotary.key) private val identityService = rigorousMock().also { doReturn(null).whenever(it).partyFromKey(ALICE_PUBKEY) doReturn(null).whenever(it).partyFromKey(BOB_PUBKEY) diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/asset/cash/selection/CashSelectionH2ImplTest.kt b/finance/src/test/kotlin/net/corda/finance/contracts/asset/cash/selection/CashSelectionH2ImplTest.kt index c044387f00..faba806b2a 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/asset/cash/selection/CashSelectionH2ImplTest.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/asset/cash/selection/CashSelectionH2ImplTest.kt @@ -10,7 +10,7 @@ import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.After import org.junit.Test diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt index bead3cefde..5bb058c5ac 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt @@ -11,7 +11,7 @@ import net.corda.testing.BOC_NAME import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt index 7a8fa93377..98df506c31 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt @@ -11,7 +11,7 @@ import net.corda.testing.BOC_NAME import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt index 26b9ab267d..1c046752a2 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt @@ -14,6 +14,7 @@ import net.corda.testing.* import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.Test diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt index 3d1bbf8e9b..f3a24002cd 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt @@ -4,6 +4,7 @@ import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.node.ServicesForResolution import net.corda.core.serialization.deserialize @@ -13,12 +14,17 @@ import net.corda.core.transactions.TransactionBuilder import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.internal.cordapp.CordappProviderImpl import net.corda.testing.* -import net.corda.testing.node.MockAttachmentStorage +import net.corda.testing.services.MockAttachmentStorage import org.junit.Assert.* import org.junit.Rule import org.junit.Test class AttachmentsClassLoaderStaticContractTests { + private companion object { + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val MEGA_CORP = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt index 4f98293c53..1d624a32f3 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt @@ -4,6 +4,7 @@ import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash +import net.corda.core.identity.CordaX500Name import net.corda.core.internal.declaredField import net.corda.core.internal.toWireTransaction import net.corda.core.node.ServiceHub @@ -18,7 +19,7 @@ import net.corda.nodeapi.internal.serialization.SerializeAsTokenContextImpl import net.corda.nodeapi.internal.serialization.attachmentsClassLoaderEnabledPropertyName import net.corda.nodeapi.internal.serialization.withTokenContext import net.corda.testing.* -import net.corda.testing.node.MockAttachmentStorage +import net.corda.testing.services.MockAttachmentStorage import org.apache.commons.io.IOUtils import org.junit.Assert.* import org.junit.Rule @@ -35,7 +36,8 @@ class AttachmentsClassLoaderTests { companion object { val ISOLATED_CONTRACTS_JAR_PATH: URL = AttachmentsClassLoaderTests::class.java.getResource("isolated.jar") private const val ISOLATED_CONTRACT_CLASS_NAME = "net.corda.finance.contracts.isolated.AnotherDummyContract" - + private val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + private val MEGA_CORP = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party private fun SerializationContext.withAttachmentStorage(attachmentStorage: AttachmentStorage): SerializationContext { val serviceHub = rigorousMock() doReturn(attachmentStorage).whenever(serviceHub).attachments diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/crypto/X509UtilitiesTest.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/crypto/X509UtilitiesTest.kt index ca4d2b2e7e..30c8004659 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/crypto/X509UtilitiesTest.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/crypto/X509UtilitiesTest.kt @@ -17,10 +17,7 @@ import net.corda.nodeapi.internal.serialization.AllWhitelist import net.corda.nodeapi.internal.serialization.SerializationContextImpl import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1 -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.BOB_PUBKEY -import net.corda.testing.MEGA_CORP +import net.corda.testing.* import org.bouncycastle.asn1.x500.X500Name import org.bouncycastle.asn1.x509.BasicConstraints import org.bouncycastle.asn1.x509.Extension @@ -49,6 +46,14 @@ import kotlin.concurrent.thread import kotlin.test.* class X509UtilitiesTest { + private companion object { + val ALICE = TestIdentity(ALICE_NAME, 70).party + val bob = TestIdentity(BOB_NAME, 80) + val MEGA_CORP = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party + val BOB get() = bob.party + val BOB_PUBKEY get() = bob.pubkey + } + @Rule @JvmField val tempFolder: TemporaryFolder = TemporaryFolder() diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/ContractAttachmentSerializerTest.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/ContractAttachmentSerializerTest.kt index c542330ebd..80ee09701a 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/ContractAttachmentSerializerTest.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/ContractAttachmentSerializerTest.kt @@ -1,6 +1,7 @@ package net.corda.nodeapi.internal.serialization import net.corda.core.contracts.ContractAttachment +import net.corda.core.identity.CordaX500Name import net.corda.core.serialization.* import net.corda.testing.* import net.corda.testing.contracts.DummyContract @@ -22,7 +23,7 @@ class ContractAttachmentSerializerTest { private lateinit var factory: SerializationFactory private lateinit var context: SerializationContext private lateinit var contextWithToken: SerializationContext - private val mockServices = MockServices(rigorousMock(), MEGA_CORP.name) + private val mockServices = MockServices(rigorousMock(), CordaX500Name("MegaCorp", "London", "GB")) @Before fun setup() { factory = testSerialization.env.serializationFactory diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolverTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolverTests.kt index 155229a5bc..654bf323e3 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolverTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolverTests.kt @@ -12,7 +12,7 @@ import net.corda.nodeapi.internal.AttachmentsClassLoader import net.corda.nodeapi.internal.AttachmentsClassLoaderTests import net.corda.nodeapi.internal.serialization.kryo.CordaKryo import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1 -import net.corda.testing.node.MockAttachmentStorage +import net.corda.testing.services.MockAttachmentStorage import net.corda.testing.rigorousMock import org.junit.Rule import org.junit.Test diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/KryoTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/KryoTests.kt index 6eee1230be..508a40f7c6 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/KryoTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/KryoTests.kt @@ -14,8 +14,9 @@ import net.corda.core.utilities.sequence import net.corda.node.serialization.KryoServerSerializationScheme import net.corda.node.services.persistence.NodeAttachmentService import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1 -import net.corda.testing.ALICE_PUBKEY +import net.corda.testing.ALICE_NAME import net.corda.testing.SerializationEnvironmentRule +import net.corda.testing.TestIdentity import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Before @@ -31,6 +32,10 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue class KryoTests { + companion object { + private val ALICE_PUBKEY = TestIdentity(ALICE_NAME, 70).pubkey + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt index 9a987f1b8a..68bc1a5786 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt @@ -9,6 +9,7 @@ import net.corda.core.crypto.SecureHash import net.corda.core.crypto.secureRandomBytes import net.corda.core.flows.FlowException import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.core.internal.AbstractAttachment import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.MissingAttachmentsException @@ -19,11 +20,8 @@ import net.corda.nodeapi.internal.serialization.AllWhitelist import net.corda.nodeapi.internal.serialization.EmptyWhitelist import net.corda.nodeapi.internal.serialization.GeneratedAttachment import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory.Companion.isPrimitive -import net.corda.testing.BOB_IDENTITY -import net.corda.testing.MEGA_CORP -import net.corda.testing.MEGA_CORP_PUBKEY +import net.corda.testing.* import net.corda.testing.contracts.DummyContract -import net.corda.testing.withTestSerialization import org.apache.activemq.artemis.api.core.SimpleString import org.apache.qpid.proton.amqp.* import org.apache.qpid.proton.codec.DecoderImpl @@ -46,6 +44,16 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue class SerializationOutputTests { + private companion object { + val BOB_IDENTITY = TestIdentity(BOB_NAME, 80).identity + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MINI_CORP get() = miniCorp.party + val MINI_CORP_PUBKEY get() = miniCorp.pubkey + } + data class Foo(val bar: String, val pub: Int) data class testFloat(val f: Float) diff --git a/node/src/integration-test/kotlin/net/corda/node/BootTests.kt b/node/src/integration-test/kotlin/net/corda/node/BootTests.kt index b431bbdcaf..05a4a88cc1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/BootTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/BootTests.kt @@ -11,6 +11,7 @@ import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User import net.corda.testing.ALICE import net.corda.testing.* +import net.corda.testing.ALICE_NAME import net.corda.testing.common.internal.ProjectStructure.projectRootDir import net.corda.testing.driver.driver import org.assertj.core.api.Assertions.assertThat @@ -43,12 +44,12 @@ class BootTests : IntegrationTest() { val logConfigFile = projectRootDir / "config" / "dev" / "log4j2.xml" assertThat(logConfigFile).isRegularFile() driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) { - val alice = startNode(providedName = ALICE.name).get() + val alice = startNode(providedName = ALICE_NAME).get() val logFolder = alice.configuration.baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME val logFile = logFolder.toFile().listFiles { _, name -> name.endsWith(".log") }.single() // Start second Alice, should fail assertThatThrownBy { - startNode(providedName = ALICE.name).getOrThrow() + startNode(providedName = ALICE_NAME).getOrThrow() } // We count the number of nodes that wrote into the logfile by counting "Logs can be found in" val numberOfNodesThatLogged = Files.lines(logFile.toPath()).filter { NodeStartup.LOGS_CAN_BE_FOUND_IN_STRING in it }.count() diff --git a/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt b/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt index b9a0a86535..90bebe9448 100644 --- a/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt @@ -13,6 +13,7 @@ import net.corda.testing.ALICE import net.corda.testing.BOB import net.corda.testing.chooseIdentity import net.corda.testing.* +import net.corda.testing.* import net.corda.testing.driver.driver import org.assertj.core.api.Assertions.assertThat import org.junit.ClassRule @@ -30,8 +31,8 @@ class CordappScanningDriverTest : IntegrationTest() { // The driver will automatically pick up the annotated flows below driver { val (alice, bob) = listOf( - startNode(providedName = ALICE.name, rpcUsers = listOf(user)), - startNode(providedName = BOB.name)).transpose().getOrThrow() + startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)), + startNode(providedName = BOB_NAME)).transpose().getOrThrow() val initiatedFlowClass = alice.rpcClientToNode() .start(user.username, user.password) .proxy diff --git a/node/src/integration-test/kotlin/net/corda/node/NodePerformanceTests.kt b/node/src/integration-test/kotlin/net/corda/node/NodePerformanceTests.kt index 81b16eb203..eceec2f04b 100644 --- a/node/src/integration-test/kotlin/net/corda/node/NodePerformanceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/NodePerformanceTests.kt @@ -16,14 +16,15 @@ import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User import net.corda.testing.DUMMY_NOTARY import net.corda.testing.* +import net.corda.testing.DUMMY_NOTARY_NAME import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver -import net.corda.testing.internal.InternalDriverDSL +import net.corda.testing.node.internal.InternalDriverDSL import net.corda.testing.internal.performance.div -import net.corda.testing.internal.performance.startPublishingFixedRateInjector -import net.corda.testing.internal.performance.startReporter -import net.corda.testing.internal.performance.startTightLoopInjector +import net.corda.testing.node.internal.performance.startPublishingFixedRateInjector +import net.corda.testing.node.internal.performance.startReporter +import net.corda.testing.node.internal.performance.startTightLoopInjector import net.corda.testing.node.NotarySpec import org.junit.Before import org.junit.ClassRule @@ -128,7 +129,7 @@ class NodePerformanceTests : IntegrationTest() { fun `self pay rate`() { val user = User("A", "A", setOf(startFlow(), startFlow())) driver( - notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name, rpcUsers = listOf(user))), + notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, rpcUsers = listOf(user))), startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.finance"), portAllocation = PortAllocation.Incremental(20000) diff --git a/node/src/integration-test/kotlin/net/corda/node/SSHServerTest.kt b/node/src/integration-test/kotlin/net/corda/node/SSHServerTest.kt index 853af7cab9..ce961af9e0 100644 --- a/node/src/integration-test/kotlin/net/corda/node/SSHServerTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/SSHServerTest.kt @@ -11,19 +11,18 @@ import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.toHex import net.corda.core.utilities.unwrap import net.corda.nodeapi.internal.config.User -import net.corda.testing.ALICE import net.corda.testing.driver.driver import org.bouncycastle.util.io.Streams import org.junit.Test import net.corda.node.services.Permissions.Companion.startFlow import net.corda.testing.* +import net.corda.testing.ALICE_NAME import java.net.ConnectException import kotlin.test.assertTrue import kotlin.test.fail import org.assertj.core.api.Assertions.assertThat import org.junit.ClassRule import java.util.regex.Pattern -import kotlin.reflect.jvm.jvmName class SSHServerTest : IntegrationTest() { companion object { @@ -35,8 +34,8 @@ class SSHServerTest : IntegrationTest() { fun `ssh server does not start be default`() { val user = User("u", "p", setOf()) // The driver will automatically pick up the annotated flows below - driver() { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user)) + driver { + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)) node.getOrThrow() val session = JSch().getSession("u", "localhost", 2222) @@ -57,7 +56,7 @@ class SSHServerTest : IntegrationTest() { val user = User("u", "p", setOf()) // The driver will automatically pick up the annotated flows below driver { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user), + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), customOverrides = mapOf("sshd" to mapOf("port" to 2222))) node.getOrThrow() @@ -77,7 +76,7 @@ class SSHServerTest : IntegrationTest() { val user = User("u", "p", setOf()) // The driver will automatically pick up the annotated flows below driver { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user), + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), customOverrides = mapOf("sshd" to mapOf("port" to 2222))) node.getOrThrow() @@ -100,7 +99,7 @@ class SSHServerTest : IntegrationTest() { val user = User("u", "p", setOf(startFlow())) // The driver will automatically pick up the annotated flows below driver(isDebug = true) { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user), + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), customOverrides = mapOf("sshd" to mapOf("port" to 2222))) node.getOrThrow() @@ -112,7 +111,7 @@ class SSHServerTest : IntegrationTest() { assertTrue(session.isConnected) val channel = session.openChannel("exec") as ChannelExec - channel.setCommand("start FlowICannotRun otherParty: \"O=Alice Corp,L=Madrid,C=ES\"") + channel.setCommand("start FlowICannotRun otherParty: \"${ALICE_NAME}\"") channel.connect() val response = String(Streams.readAll(channel.inputStream)) @@ -130,7 +129,7 @@ class SSHServerTest : IntegrationTest() { val user = User("u", "p", setOf(startFlow())) // The driver will automatically pick up the annotated flows below driver(isDebug = true) { - val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user), + val node = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), customOverrides = mapOf("sshd" to mapOf("port" to 2222))) node.getOrThrow() diff --git a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt index 0f7ebfbbd6..b9f6305dc1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt @@ -24,7 +24,7 @@ import net.corda.testing.* import net.corda.testing.driver.DriverDSL import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.driver -import net.corda.testing.node.MockAttachmentStorage +import net.corda.testing.services.MockAttachmentStorage import org.junit.Assert.assertEquals import org.junit.ClassRule import org.junit.Test @@ -53,7 +53,8 @@ class AttachmentLoadingTests : IntegrationTest() { val flowInitiatorClass: Class> = Class.forName("net.corda.finance.contracts.isolated.IsolatedDummyFlow\$Initiator", true, URLClassLoader(arrayOf(isolatedJAR))) .asSubclass(FlowLogic::class.java) - + val DUMMY_BANK_A = TestIdentity(DUMMY_BANK_A_NAME, 40).party + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party private fun DriverDSL.createTwoNodes(): List { return listOf( startNode(providedName = bankAName), diff --git a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt index 1908e4b82e..624590fab8 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt @@ -33,6 +33,7 @@ import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Before import org.junit.ClassRule diff --git a/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt index 155565cfca..efd3173e89 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt @@ -46,9 +46,9 @@ class DistributedServiceTests : IntegrationTest() { driver( extraCordappPackagesToScan = listOf("net.corda.finance.contracts"), - notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name, rpcUsers = listOf(testUser), cluster = ClusterSpec.Raft(clusterSize = 3)))) + notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, rpcUsers = listOf(testUser), cluster = ClusterSpec.Raft(clusterSize = 3)))) { - alice = startNode(providedName = ALICE.name, rpcUsers = listOf(testUser)).getOrThrow() + alice = startNode(providedName = ALICE_NAME, rpcUsers = listOf(testUser)).getOrThrow() raftNotaryIdentity = defaultNotaryIdentity notaryNodes = defaultNotaryHandle.nodeHandles.getOrThrow().map { it as NodeHandle.OutOfProcess } diff --git a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt index 53f59c1e13..c9efaad16a 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt @@ -16,6 +16,8 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.driver +import net.corda.testing.dummyCommand +import net.corda.testing.node.startFlow import net.corda.testing.node.ClusterSpec import net.corda.testing.node.NotarySpec import org.junit.ClassRule @@ -39,8 +41,7 @@ class RaftNotaryServiceTests : IntegrationTest() { extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))) { - val bankA = startNode(providedName = DUMMY_BANK_A.name).map { (it as NodeHandle.InProcess).node }.getOrThrow() - + val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as NodeHandle.InProcess).node }.getOrThrow() val inputState = issueState(bankA, defaultNotaryIdentity) val firstTxBuilder = TransactionBuilder(defaultNotaryIdentity) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/UserAuthServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/UserAuthServiceTests.kt index 263fce9f75..6418fd22d6 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/UserAuthServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/UserAuthServiceTests.kt @@ -16,7 +16,7 @@ import net.corda.node.services.config.SecurityConfiguration import net.corda.node.services.config.AuthDataSourceType import net.corda.nodeapi.internal.config.User import net.corda.nodeapi.internal.config.toConfig -import net.corda.testing.internal.NodeBasedTest +import net.corda.testing.node.internal.NodeBasedTest import net.corda.testing.* import org.apache.activemq.artemis.api.core.ActiveMQSecurityException import org.junit.After diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt index 8cd555f231..faa30be62b 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt @@ -2,12 +2,12 @@ package net.corda.node.services.network import net.corda.core.node.NodeInfo import net.corda.core.utilities.seconds -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.internal.CompatibilityZoneParams +import net.corda.testing.node.internal.CompatibilityZoneParams +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.PortAllocation -import net.corda.testing.internal.internalDriver +import net.corda.testing.node.internal.internalDriver import net.corda.testing.node.network.NetworkMapServer import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -37,9 +37,8 @@ class NetworkMapTest { @Test fun `nodes can see each other using the http network map`() { internalDriver(portAllocation = portAllocation, compatibilityZone = compatibilityZone) { - val alice = startNode(providedName = ALICE.name) - val bob = startNode(providedName = BOB.name) - + val alice = startNode(providedName = ALICE_NAME) + val bob = startNode(providedName = BOB_NAME) val notaryNode = defaultNotaryNode.get() val aliceNode = alice.get() val bobNode = bob.get() @@ -53,14 +52,13 @@ class NetworkMapTest { @Test fun `nodes process network map add updates correctly when adding new node to network map`() { internalDriver(portAllocation = portAllocation, compatibilityZone = compatibilityZone) { - val alice = startNode(providedName = ALICE.name) + val alice = startNode(providedName = ALICE_NAME) val notaryNode = defaultNotaryNode.get() val aliceNode = alice.get() notaryNode.onlySees(notaryNode.nodeInfo, aliceNode.nodeInfo) aliceNode.onlySees(notaryNode.nodeInfo, aliceNode.nodeInfo) - - val bob = startNode(providedName = BOB.name) + val bob = startNode(providedName = BOB_NAME) val bobNode = bob.get() // Wait for network map client to poll for the next update. @@ -75,9 +73,8 @@ class NetworkMapTest { @Test fun `nodes process network map remove updates correctly`() { internalDriver(portAllocation = portAllocation, compatibilityZone = compatibilityZone) { - val alice = startNode(providedName = ALICE.name) - val bob = startNode(providedName = BOB.name) - + val alice = startNode(providedName = ALICE_NAME) + val bob = startNode(providedName = BOB_NAME) val notaryNode = defaultNotaryNode.get() val aliceNode = alice.get() val bobNode = bob.get() diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/NodeInfoWatcherTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/NodeInfoWatcherTest.kt index 72068d73fe..8977afda78 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/NodeInfoWatcherTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/NodeInfoWatcherTest.kt @@ -9,7 +9,6 @@ import net.corda.core.internal.div import net.corda.core.node.NodeInfo import net.corda.core.node.services.KeyManagementService import net.corda.core.serialization.serialize -import net.corda.node.services.identity.InMemoryIdentityService import net.corda.nodeapi.internal.NodeInfoFilesCopier import net.corda.testing.* import net.corda.testing.node.MockKeyManagementService @@ -28,8 +27,9 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue class NodeInfoWatcherTest { - companion object { - val nodeInfo = NodeInfo(listOf(), listOf(getTestPartyAndCertificate(ALICE)), 0, 0) + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val nodeInfo = NodeInfo(listOf(), listOf(alice.identity), 0, 0) } @Rule @@ -49,7 +49,7 @@ class NodeInfoWatcherTest { @Before fun start() { val identityService = makeTestIdentityService() - keyManagementService = MockKeyManagementService(identityService, ALICE_KEY) + keyManagementService = MockKeyManagementService(identityService, alice.key) nodeInfoWatcher = NodeInfoWatcher(tempFolder.root.toPath(), scheduler) nodeInfoPath = tempFolder.root.toPath() / CordformNode.NODE_INFO_DIRECTORY } diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt index 702b894ebc..09b5225c30 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/PersistentNetworkMapCacheTest.kt @@ -8,6 +8,11 @@ import net.corda.node.internal.Node import net.corda.node.internal.StartedNode import net.corda.testing.* import net.corda.testing.internal.NodeBasedTest +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME +import net.corda.testing.TestIdentity +import net.corda.testing.chooseIdentity +import net.corda.testing.node.internal.NodeBasedTest import org.junit.Before import org.junit.ClassRule import org.junit.Test @@ -15,6 +20,10 @@ import kotlin.test.assertEquals class PersistentNetworkMapCacheTest : NodeBasedTest() { companion object { + val ALICE = TestIdentity(ALICE_NAME, 70).party + val BOB = TestIdentity(BOB_NAME, 80).party + val DUMMY_REGULATOR = TestIdentity(CordaX500Name("Regulator A", "Paris", "FR"), 100).party + @ClassRule @JvmField val databaseSchemas = IntegrationTestSchemas(*listOf(DUMMY_REGULATOR, ALICE, BOB).map { it.toDatabaseSchemaName() }.toTypedArray()) } diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt index 9c48d2c2c0..04e97bd7a3 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/FlowVersioningTest.kt @@ -7,6 +7,10 @@ import net.corda.core.flows.InitiatingFlow import net.corda.core.identity.Party import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.unwrap +import net.corda.testing.chooseIdentity +import net.corda.testing.node.internal.NodeBasedTest +import net.corda.testing.node.startFlow +import net.corda.testing.* import net.corda.testing.* import net.corda.testing.internal.NodeBasedTest import org.assertj.core.api.Assertions.assertThat @@ -21,8 +25,8 @@ class FlowVersioningTest : NodeBasedTest() { @Test fun `getFlowContext returns the platform version for core flows`() { - val alice = startNode(ALICE.name, platformVersion = 2) - val bob = startNode(BOB.name, platformVersion = 3) + val alice = startNode(ALICE_NAME, platformVersion = 2) + val bob = startNode(BOB_NAME, platformVersion = 3) bob.internals.installCoreFlow(PretendInitiatingCoreFlow::class, ::PretendInitiatedCoreFlow) val (alicePlatformVersionAccordingToBob, bobPlatformVersionAccordingToAlice) = alice.services.startFlow( PretendInitiatingCoreFlow(bob.info.chooseIdentity())).resultFuture.getOrThrow() diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt index da2c989a96..6b087a95c4 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt @@ -23,6 +23,10 @@ import kotlin.test.assertEquals */ class LargeTransactionsTest : IntegrationTest() { companion object { + private companion object { + val BOB = TestIdentity(BOB_NAME, 80).party + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + } @ClassRule @JvmField val databaseSchemas = IntegrationTestSchemas(*listOf(ALICE, BOB, DUMMY_NOTARY).map { it.toDatabaseSchemaName() }.toTypedArray()) } diff --git a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt index 6cd0058792..2acd637b5d 100644 --- a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt @@ -1,6 +1,5 @@ package net.corda.node.utilities.registration -import com.google.common.net.HostAndPort import net.corda.core.crypto.Crypto import net.corda.core.identity.CordaX500Name import net.corda.core.internal.cert @@ -15,9 +14,9 @@ import net.corda.nodeapi.internal.crypto.X509Utilities import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_CLIENT_CA import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_INTERMEDIATE_CA import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_ROOT_CA -import net.corda.testing.internal.CompatibilityZoneParams +import net.corda.testing.node.internal.CompatibilityZoneParams import net.corda.testing.driver.PortAllocation -import net.corda.testing.internal.internalDriver +import net.corda.testing.node.internal.internalDriver import net.corda.testing.node.network.NetworkMapServer import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt index fc2c15c746..94eb96a7a8 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityAsNodeTest.kt @@ -1,14 +1,13 @@ package net.corda.services.messaging import net.corda.core.crypto.Crypto +import net.corda.core.identity.CordaX500Name import net.corda.core.internal.* import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.NODE_USER import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.PEER_USER import net.corda.nodeapi.RPCApi import net.corda.nodeapi.internal.config.SSLConfiguration import net.corda.nodeapi.internal.crypto.* -import net.corda.testing.MEGA_CORP -import net.corda.testing.MINI_CORP import net.corda.testing.messaging.SimpleMQClient import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration import org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException @@ -86,7 +85,7 @@ class MQSecurityAsNodeTest : MQSecurityTest() { override val trustStorePassword: String get() = "trustpass" init { - val legalName = MEGA_CORP.name + val legalName = CordaX500Name("MegaCorp", "London", "GB") certificatesDirectory.createDirectories() if (!trustStoreFile.exists()) { javaClass.classLoader.getResourceAsStream("certificates/cordatruststore.jks").copyTo(trustStoreFile) @@ -106,7 +105,7 @@ class MQSecurityAsNodeTest : MQSecurityTest() { intermediateCA.keyPair, legalName, clientKey.public, nameConstraints = nameConstraints) val tlsKey = Crypto.generateKeyPair(X509Utilities.DEFAULT_TLS_SIGNATURE_SCHEME) // Using different x500 name in the TLS cert which is not allowed in the name constraints. - val clientTLSCert = X509Utilities.createCertificate(CertificateType.TLS, clientCACert, clientKey, MINI_CORP.name, tlsKey.public) + val clientTLSCert = X509Utilities.createCertificate(CertificateType.TLS, clientCACert, clientKey, CordaX500Name("MiniCorp", "London", "GB"), tlsKey.public) val keyPass = keyStorePassword.toCharArray() val clientCAKeystore = loadOrCreateKeyStore(nodeKeystore, keyStorePassword) clientCAKeystore.addOrReplaceKey( diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt index 2b3b9dbef7..938a5b7742 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/MQSecurityTest.kt @@ -9,6 +9,7 @@ import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowSession import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatingFlow +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.messaging.CordaRPCOps import net.corda.core.utilities.NetworkHostAndPort @@ -25,8 +26,9 @@ import net.corda.nodeapi.RPCApi import net.corda.nodeapi.internal.config.User import net.corda.nodeapi.internal.config.SSLConfiguration import net.corda.testing.* -import net.corda.testing.internal.NodeBasedTest +import net.corda.testing.node.internal.NodeBasedTest import net.corda.testing.messaging.SimpleMQClient +import net.corda.testing.node.startFlow import org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException import org.apache.activemq.artemis.api.core.ActiveMQSecurityException import org.apache.activemq.artemis.api.core.SimpleString @@ -53,7 +55,7 @@ abstract class MQSecurityTest : NodeBasedTest() { override fun setUp() { super.init() super.setUp() - alice = startNode(ALICE.name, rpcUsers = extraRPCUsers + rpcUser) + alice = startNode(ALICE_NAME, rpcUsers = extraRPCUsers + rpcUser) attacker = createAttacker() startAttacker(attacker) } @@ -89,7 +91,7 @@ abstract class MQSecurityTest : NodeBasedTest() { @Test fun `create queue for peer which has not been communicated with`() { - val bob = startNode(BOB.name) + val bob = startNode(BOB_NAME) assertAllQueueCreationAttacksFail("$PEERS_PREFIX${bob.info.chooseIdentity().owningKey.toBase58String()}") } @@ -139,7 +141,7 @@ abstract class MQSecurityTest : NodeBasedTest() { assertAllQueueCreationAttacksFail(randomQueue) } - fun clientTo(target: NetworkHostAndPort, sslConfiguration: SSLConfiguration? = configureTestSSL()): SimpleMQClient { + fun clientTo(target: NetworkHostAndPort, sslConfiguration: SSLConfiguration? = configureTestSSL(CordaX500Name("MegaCorp", "London", "GB"))): SimpleMQClient { val client = SimpleMQClient(target, sslConfiguration) clients += client return client @@ -212,7 +214,7 @@ abstract class MQSecurityTest : NodeBasedTest() { } private fun startBobAndCommunicateWithAlice(): Party { - val bob = startNode(BOB.name) + val bob = startNode(BOB_NAME) bob.registerInitiatedFlow(ReceiveFlow::class.java) val bobParty = bob.info.chooseIdentity() // Perform a protocol exchange to force the peer queue to be created diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PMessagingTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PMessagingTest.kt index 83e4ad4afa..4169c8b6b5 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PMessagingTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PMessagingTest.kt @@ -19,6 +19,8 @@ import net.corda.node.services.messaging.ReceivedMessage import net.corda.node.services.messaging.send import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.testing.* +import net.corda.testing.ALICE_NAME +import net.corda.testing.chooseIdentity import net.corda.testing.driver.DriverDSL import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.driver @@ -120,7 +122,7 @@ class P2PMessagingTest : IntegrationTest() { } private fun DriverDSL.startAlice(): StartedNode { - return startNode(providedName = ALICE.name, customOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)) + return startNode(providedName = ALICE_NAME, customOverrides = mapOf("messageRedeliveryDelaySeconds" to 1)) .map { (it as NodeHandle.InProcess).node } .getOrThrow() } diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index f8a19ddb5f..b71fc7db16 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -8,7 +8,6 @@ import net.corda.core.crypto.CryptoUtils; import net.corda.core.identity.AbstractParty; import net.corda.core.identity.CordaX500Name; import net.corda.core.identity.Party; -import net.corda.core.identity.PartyAndCertificate; import net.corda.core.messaging.DataFeed; import net.corda.core.node.services.Vault; import net.corda.core.node.services.VaultQueryException; @@ -17,7 +16,6 @@ import net.corda.core.node.services.vault.*; import net.corda.core.node.services.vault.QueryCriteria.LinearStateQueryCriteria; import net.corda.core.node.services.vault.QueryCriteria.VaultCustomQueryCriteria; import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria; -import net.corda.core.utilities.OpaqueBytes; import net.corda.finance.contracts.DealState; import net.corda.finance.contracts.asset.Cash; import net.corda.finance.schemas.CashSchemaV1; @@ -25,6 +23,7 @@ import net.corda.node.services.api.IdentityServiceInternal; import net.corda.nodeapi.internal.persistence.CordaPersistence; import net.corda.nodeapi.internal.persistence.DatabaseTransaction; import net.corda.testing.SerializationEnvironmentRule; +import net.corda.testing.TestIdentity; import net.corda.testing.contracts.DummyLinearContract; import net.corda.testing.contracts.VaultFiller; import net.corda.testing.node.MockServices; @@ -36,30 +35,31 @@ import rx.Observable; import java.io.IOException; import java.lang.reflect.Field; -import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; -import java.security.KeyPair; import java.security.cert.CertificateException; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import static net.corda.core.crypto.CryptoUtils.entropyToKeyPair; import static net.corda.core.node.services.vault.QueryCriteriaUtils.DEFAULT_PAGE_NUM; import static net.corda.core.node.services.vault.QueryCriteriaUtils.MAX_PAGE_SIZE; import static net.corda.core.utilities.ByteArrays.toHexString; -import static net.corda.testing.CoreTestUtils.*; -import static net.corda.testing.TestConstants.*; +import static net.corda.testing.CoreTestUtils.rigorousMock; +import static net.corda.testing.TestConstants.getBOC_NAME; +import static net.corda.testing.TestConstants.getCHARLIE_NAME; +import static net.corda.testing.TestConstants.getDUMMY_NOTARY_NAME; import static net.corda.testing.node.MockServices.makeTestDatabaseAndMockServices; import static net.corda.testing.node.MockServicesKt.makeTestIdentityService; import static org.assertj.core.api.Assertions.assertThat; public class VaultQueryJavaTests { - private static final CordaX500Name DUMMY_CASH_ISSUER_NAME = new CordaX500Name("Snake Oil Issuer", "London", "GB"); - private static final KeyPair DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)); - private static final PartyAndCertificate DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(new Party(DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY.getPublic())); - private static final PartyAndReference DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.getParty().ref((byte) 1); + private static final TestIdentity BOC = new TestIdentity(getBOC_NAME()); + private static final Party CHARLIE = new TestIdentity(getCHARLIE_NAME(), 90L).getParty(); + private static final TestIdentity DUMMY_CASH_ISSUER_INFO = new TestIdentity(new CordaX500Name("Snake Oil Issuer", "London", "GB"), 10L); + private static final PartyAndReference DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_INFO.ref((byte) 1); + private static final TestIdentity DUMMY_NOTARY = new TestIdentity(getDUMMY_NOTARY_NAME(), 20L); + private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB")); @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); private VaultFiller vaultFiller; @@ -70,16 +70,16 @@ public class VaultQueryJavaTests { @Before public void setUp() throws CertificateException, InvalidAlgorithmParameterException { List cordappPackages = Arrays.asList("net.corda.testing.contracts", "net.corda.finance.contracts.asset", CashSchemaV1.class.getPackage().getName()); - IdentityServiceInternal identitySvc = makeTestIdentityService(Arrays.asList(getMEGA_CORP_IDENTITY(), DUMMY_CASH_ISSUER_IDENTITY, getDUMMY_NOTARY_IDENTITY())); + IdentityServiceInternal identitySvc = makeTestIdentityService(Arrays.asList(MEGA_CORP.getIdentity(), DUMMY_CASH_ISSUER_INFO.getIdentity(), DUMMY_NOTARY.getIdentity())); Pair databaseAndServices = makeTestDatabaseAndMockServices( - Arrays.asList(getMEGA_CORP_KEY(), getDUMMY_NOTARY_KEY()), + Arrays.asList(MEGA_CORP.getKey(), DUMMY_NOTARY.getKey()), identitySvc, cordappPackages, - getMEGA_CORP().getName()); - issuerServices = new MockServices(cordappPackages, rigorousMock(IdentityServiceInternal.class), DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY, getBOC_KEY()); + MEGA_CORP.getName()); + issuerServices = new MockServices(cordappPackages, rigorousMock(IdentityServiceInternal.class), DUMMY_CASH_ISSUER_INFO, BOC.getKey()); database = databaseAndServices.getFirst(); MockServices services = databaseAndServices.getSecond(); - vaultFiller = new VaultFiller(services, getDUMMY_NOTARY(), getDUMMY_NOTARY_KEY()); + vaultFiller = new VaultFiller(services, DUMMY_NOTARY); vaultService = services.getVaultService(); } @@ -153,7 +153,7 @@ public class VaultQueryJavaTests { return tx; }); database.transaction(tx -> { - vaultFiller.consumeCash(amount, getCHARLIE()); + vaultFiller.consumeCash(amount, CHARLIE); return tx; }); database.transaction(tx -> { @@ -306,7 +306,7 @@ public class VaultQueryJavaTests { QueryCriteria vaultCriteria = new VaultQueryCriteria(Vault.StateStatus.UNCONSUMED, contractStateTypes); List linearIds = Collections.singletonList(uid); - List dealParty = Collections.singletonList(getMEGA_CORP()); + List dealParty = Collections.singletonList(MEGA_CORP.getParty()); QueryCriteria dealCriteria = new LinearStateQueryCriteria(dealParty, null, dealIds); QueryCriteria linearCriteria = new LinearStateQueryCriteria(dealParty, linearIds, Vault.StateStatus.UNCONSUMED, null); QueryCriteria dealOrLinearIdCriteria = dealCriteria.or(linearCriteria); @@ -448,9 +448,9 @@ public class VaultQueryJavaTests { Amount pounds300 = new Amount<>(300, Currency.getInstance("GBP")); Amount pounds400 = new Amount<>(400, Currency.getInstance("GBP")); vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, DUMMY_CASH_ISSUER); - vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getBOC().ref(new OpaqueBytes("1".getBytes()))); + vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, BOC.ref((byte) '1')); vaultFiller.fillWithSomeTestCash(pounds300, issuerServices, 3, DUMMY_CASH_ISSUER); - vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, 4, getBOC().ref(new OpaqueBytes("1".getBytes()))); + vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, 4, BOC.ref((byte) '1')); return tx; }); database.transaction(tx -> { @@ -466,16 +466,16 @@ public class VaultQueryJavaTests { assertThat(results.getOtherResults()).hasSize(12); assertThat(results.getOtherResults().get(0)).isEqualTo(400L); - assertThat(results.getOtherResults().get(1)).isEqualTo(CryptoUtils.toStringShort(getBOC_PUBKEY())); + assertThat(results.getOtherResults().get(1)).isEqualTo(CryptoUtils.toStringShort(BOC.getPubkey())); assertThat(results.getOtherResults().get(2)).isEqualTo("GBP"); assertThat(results.getOtherResults().get(3)).isEqualTo(300L); - assertThat(results.getOtherResults().get(4)).isEqualTo(CryptoUtils.toStringShort(DUMMY_CASH_ISSUER_KEY.getPublic())); + assertThat(results.getOtherResults().get(4)).isEqualTo(CryptoUtils.toStringShort(DUMMY_CASH_ISSUER_INFO.getPubkey())); assertThat(results.getOtherResults().get(5)).isEqualTo("GBP"); assertThat(results.getOtherResults().get(6)).isEqualTo(200L); - assertThat(results.getOtherResults().get(7)).isEqualTo(CryptoUtils.toStringShort(getBOC_PUBKEY())); + assertThat(results.getOtherResults().get(7)).isEqualTo(CryptoUtils.toStringShort(BOC.getPubkey())); assertThat(results.getOtherResults().get(8)).isEqualTo("USD"); assertThat(results.getOtherResults().get(9)).isEqualTo(100L); - assertThat(results.getOtherResults().get(10)).isEqualTo(CryptoUtils.toStringShort(DUMMY_CASH_ISSUER_KEY.getPublic())); + assertThat(results.getOtherResults().get(10)).isEqualTo(CryptoUtils.toStringShort(DUMMY_CASH_ISSUER_INFO.getPubkey())); assertThat(results.getOtherResults().get(11)).isEqualTo("USD"); } catch (NoSuchFieldException e) { diff --git a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt index a579538eab..ec6086fb7e 100644 --- a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt @@ -37,6 +37,7 @@ import net.corda.testing.* import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.testActor import org.apache.commons.io.IOUtils import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.After diff --git a/node/src/test/kotlin/net/corda/node/InteractiveShellTest.kt b/node/src/test/kotlin/net/corda/node/InteractiveShellTest.kt index 242536a172..d2caa2f214 100644 --- a/node/src/test/kotlin/net/corda/node/InteractiveShellTest.kt +++ b/node/src/test/kotlin/net/corda/node/InteractiveShellTest.kt @@ -6,6 +6,7 @@ import net.corda.core.contracts.Amount import net.corda.core.crypto.SecureHash import net.corda.core.flows.FlowLogic import net.corda.core.flows.StateMachineRunId +import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.internal.concurrent.openFuture import net.corda.core.messaging.FlowProgressHandleImpl @@ -13,8 +14,7 @@ import net.corda.core.utilities.ProgressTracker import net.corda.nodeapi.internal.persistence.DatabaseConfig import net.corda.node.shell.InteractiveShell import net.corda.node.internal.configureDatabase -import net.corda.testing.MEGA_CORP -import net.corda.testing.MEGA_CORP_IDENTITY +import net.corda.testing.TestIdentity import net.corda.testing.node.MockServices import net.corda.testing.node.makeTestIdentityService import net.corda.testing.rigorousMock @@ -26,6 +26,10 @@ import java.util.* import kotlin.test.assertEquals class InteractiveShellTest { + companion object { + private val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + } + @Before fun setup() { InteractiveShell.database = configureDatabase(MockServices.makeTestDataSourceProperties(), DatabaseConfig(), rigorousMock()) @@ -48,7 +52,7 @@ class InteractiveShellTest { override fun call() = a } - private val ids = makeTestIdentityService(listOf(MEGA_CORP_IDENTITY)) + private val ids = makeTestIdentityService(listOf(megaCorp.identity)) private val om = JacksonSupport.createInMemoryMapper(ids, YAMLFactory()) private fun check(input: String, expected: String) { @@ -90,5 +94,5 @@ class InteractiveShellTest { fun flowTooManyParams() = check("b: 12, c: Yo, d: Bar", "") @Test - fun party() = check("party: \"${MEGA_CORP.name}\"", MEGA_CORP.name.toString()) + fun party() = check("party: \"${megaCorp.name}\"", megaCorp.name.toString()) } diff --git a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt index af830013d4..8526b36bcd 100644 --- a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt +++ b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt @@ -1,7 +1,7 @@ package net.corda.node.internal.cordapp import net.corda.core.node.services.AttachmentStorage -import net.corda.testing.node.MockAttachmentStorage +import net.corda.testing.services.MockAttachmentStorage import org.junit.Assert import org.junit.Before import org.junit.Test diff --git a/testing/node-driver/src/test/java/net/corda/node/internal/security/PasswordTest.kt b/node/src/test/kotlin/net/corda/node/internal/security/PasswordTest.kt similarity index 100% rename from testing/node-driver/src/test/java/net/corda/node/internal/security/PasswordTest.kt rename to node/src/test/kotlin/net/corda/node/internal/security/PasswordTest.kt diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index c020b3380f..8feafba9a3 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -72,6 +72,10 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @JvmStatic @Parameterized.Parameters(name = "Anonymous = {0}") fun data(): Collection = listOf(true, false) + + private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + private val MEGA_CORP = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party + private val DUMMY_NOTARY get() = dummyNotary.party } private lateinit var mockNet: MockNetwork @@ -111,7 +115,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() bobNode.database.transaction { - VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, cashIssuer) + VaultFiller(bobNode.services, dummyNotary, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, cashIssuer) } val alicesFakePaper = aliceNode.database.transaction { @@ -162,7 +166,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() val cashStates = bobNode.database.transaction { - VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, issuer) + VaultFiller(bobNode.services, dummyNotary, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, issuer) } val alicesFakePaper = aliceNode.database.transaction { @@ -223,7 +227,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { val issuer = bank.ref(1, 2, 3) bobNode.database.transaction { - VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, issuer) + VaultFiller(bobNode.services, dummyNotary, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, issuer) } val alicesFakePaper = aliceNode.database.transaction { fillUpForSeller(false, issuer, alice, diff --git a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt index 78539f9c39..a2b321391d 100644 --- a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt @@ -18,6 +18,7 @@ import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.NotarySpec import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.After import org.junit.Before @@ -38,16 +39,16 @@ class NotaryChangeTests { @Before fun setUp() { - val oldNotaryName = DUMMY_REGULATOR.name + val oldNotaryName = CordaX500Name("Regulator A", "Paris", "FR") mockNet = MockNetwork( - notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name), NotarySpec(oldNotaryName)), + notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME), NotarySpec(oldNotaryName)), cordappPackages = listOf("net.corda.testing.contracts") ) clientNodeA = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME)) clientNodeB = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) clientA = clientNodeA.info.singleIdentity() oldNotaryNode = mockNet.notaryNodes[1] - newNotaryParty = clientNodeA.services.networkMapCache.getNotary(DUMMY_NOTARY.name)!! + newNotaryParty = clientNodeA.services.networkMapCache.getNotary(DUMMY_NOTARY_NAME)!! oldNotaryParty = clientNodeA.services.networkMapCache.getNotary(oldNotaryName)!! } diff --git a/node/src/test/kotlin/net/corda/node/services/config/NodeConfigurationImplTest.kt b/node/src/test/kotlin/net/corda/node/services/config/NodeConfigurationImplTest.kt index f6fffd581b..04fcc39223 100644 --- a/node/src/test/kotlin/net/corda/node/services/config/NodeConfigurationImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/config/NodeConfigurationImplTest.kt @@ -1,8 +1,7 @@ package net.corda.node.services.config import net.corda.core.utilities.NetworkHostAndPort -import net.corda.nodeapi.internal.persistence.DatabaseConfig -import net.corda.testing.ALICE +import net.corda.testing.ALICE_NAME import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Test @@ -34,11 +33,11 @@ class NodeConfigurationImplTest { private val testConfiguration = NodeConfigurationImpl( baseDirectory = Paths.get("."), - myLegalName = ALICE.name, + myLegalName = ALICE_NAME, emailAddress = "", keyStorePassword = "cordacadevpass", trustStorePassword = "trustpass", - dataSourceProperties = makeTestDataSourceProperties(ALICE.name.organisation), + dataSourceProperties = makeTestDataSourceProperties(ALICE_NAME.organisation), rpcUsers = emptyList(), verifierType = VerifierType.InMemory, useHTTPS = false, diff --git a/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt index 2fc758926a..fddea92a22 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt @@ -16,6 +16,7 @@ import net.corda.core.node.NodeInfo import net.corda.core.node.ServiceHub import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.transactions.TransactionBuilder +import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.days import net.corda.node.internal.FlowStarterImpl import net.corda.node.internal.cordapp.CordappLoader @@ -36,6 +37,7 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.node.* import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties +import net.corda.testing.services.MockAttachmentStorage import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Before @@ -50,9 +52,11 @@ import java.util.concurrent.TimeUnit import kotlin.test.assertTrue class NodeSchedulerServiceTest : SingletonSerializeAsToken() { - companion object { - private val DUMMY_IDENTITY_1 = getTestPartyAndCertificate(Party(CordaX500Name("Dummy", "Madrid", "ES"), generateKeyPair().public)) - private val myInfo = NodeInfo(listOf(MOCK_HOST_AND_PORT), listOf(DUMMY_IDENTITY_1), 1, serial = 1L) + private companion object { + val ALICE_KEY = TestIdentity(ALICE_NAME, 70).key + val DUMMY_IDENTITY_1 = getTestPartyAndCertificate(Party(CordaX500Name("Dummy", "Madrid", "ES"), generateKeyPair().public)) + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val myInfo = NodeInfo(listOf(NetworkHostAndPort("mockHost", 30000)), listOf(DUMMY_IDENTITY_1), 1, serial = 1L) } @Rule diff --git a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt index af4a80e3b2..d963030134 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt @@ -24,6 +24,7 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Assert.* import org.junit.Before diff --git a/node/src/test/kotlin/net/corda/node/services/identity/InMemoryIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/identity/InMemoryIdentityServiceTests.kt index 5ffac70560..46a5dc9db0 100644 --- a/node/src/test/kotlin/net/corda/node/services/identity/InMemoryIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/identity/InMemoryIdentityServiceTests.kt @@ -22,8 +22,16 @@ import kotlin.test.assertNull * Tests for the in memory identity service. */ class InMemoryIdentityServiceTests { - companion object { - private fun createService(vararg identities: PartyAndCertificate) = InMemoryIdentityService(identities.toSet(), DEV_TRUST_ROOT) + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val bob = TestIdentity(BOB_NAME, 80) + val ALICE get() = alice.party + val ALICE_IDENTITY get() = alice.identity + val ALICE_PUBKEY get() = alice.pubkey + val BOB get() = bob.party + val BOB_IDENTITY get() = bob.identity + val BOB_PUBKEY get() = bob.pubkey + fun createService(vararg identities: PartyAndCertificate) = InMemoryIdentityService(identities.toSet(), DEV_TRUST_ROOT) } @Test diff --git a/node/src/test/kotlin/net/corda/node/services/identity/PersistentIdentityServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/identity/PersistentIdentityServiceTests.kt index 0df6386b8b..9b50b7f5b0 100644 --- a/node/src/test/kotlin/net/corda/node/services/identity/PersistentIdentityServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/identity/PersistentIdentityServiceTests.kt @@ -30,6 +30,17 @@ import kotlin.test.assertNull * Tests for the in memory identity service. */ class PersistentIdentityServiceTests { + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val bob = TestIdentity(BOB_NAME, 80) + val ALICE get() = alice.party + val ALICE_IDENTITY get() = alice.identity + val ALICE_PUBKEY get() = alice.pubkey + val BOB get() = bob.party + val BOB_IDENTITY get() = bob.identity + val BOB_PUBKEY get() = bob.pubkey + } + private lateinit var database: CordaPersistence private lateinit var identityService: IdentityService diff --git a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt index a56bd76955..35eb3810a3 100644 --- a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt @@ -21,6 +21,7 @@ import net.corda.nodeapi.internal.persistence.DatabaseConfig import net.corda.testing.* import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties +import net.corda.testing.node.testNodeConfiguration import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.After @@ -66,7 +67,7 @@ class ArtemisMessagingTests { securityManager = RPCSecurityManagerImpl.fromUserList(users = emptyList(), id = AuthServiceId("TEST")) config = testNodeConfiguration( baseDirectory = temporaryFolder.root.toPath(), - myLegalName = ALICE.name) + myLegalName = ALICE_NAME) LogHelper.setLevel(PersistentUniquenessProvider::class) database = configureDatabase(makeTestDataSourceProperties(), DatabaseConfig(), rigorousMock()) networkMapCache = NetworkMapCacheImpl(PersistentNetworkMapCache(database, emptyList()), rigorousMock()) diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt index f955fd92d0..e495f12f72 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt @@ -23,6 +23,11 @@ import java.util.concurrent.TimeUnit import kotlin.test.assertEquals class DBTransactionStorageTests { + private companion object { + val ALICE_PUBKEY = TestIdentity(ALICE_NAME, 70).pubkey + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt index 58666e4204..e323c98851 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt @@ -6,7 +6,6 @@ import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef import net.corda.core.contracts.TransactionState import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AbstractParty import net.corda.core.identity.CordaX500Name @@ -48,7 +47,6 @@ import org.assertj.core.api.Assertions.assertThat import org.hibernate.SessionFactory import org.junit.* import java.math.BigDecimal -import java.math.BigInteger import java.time.Instant import java.util.* import javax.persistence.EntityManager @@ -57,9 +55,13 @@ import javax.persistence.criteria.CriteriaBuilder class HibernateConfigurationTest { private companion object { - val DUMMY_CASH_ISSUER_NAME = CordaX500Name("Snake Oil Issuer", "London", "GB") - val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) - val DUMMY_CASH_ISSUER = Party(DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY.public) + val ALICE = TestIdentity(ALICE_NAME, 70).party + val bankOfCorda = TestIdentity(BOC_NAME) + val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party + val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val BOC get() = bankOfCorda.party + val BOC_KEY get() = bankOfCorda.key } @Rule @@ -92,15 +94,15 @@ class HibernateConfigurationTest { fun setUp() { val cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts.asset") bankServices = MockServices(cordappPackages, rigorousMock(), BOC.name, BOC_KEY) - issuerServices = MockServices(cordappPackages, rigorousMock(), DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) - notaryServices = MockServices(cordappPackages, rigorousMock(), DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) + issuerServices = MockServices(cordappPackages, rigorousMock(), dummyCashIssuer) + notaryServices = MockServices(cordappPackages, rigorousMock(), dummyNotary) notary = notaryServices.myInfo.singleIdentity() val dataSourceProps = makeTestDataSourceProperties() val identityService = rigorousMock().also { mock -> doReturn(null).whenever(mock).wellKnownPartyFromAnonymous(any()) - listOf(DUMMY_CASH_ISSUER, DUMMY_NOTARY).forEach { - doReturn(it).whenever(mock).wellKnownPartyFromAnonymous(it) - doReturn(it).whenever(mock).wellKnownPartyFromX500Name(it.name) + listOf(dummyCashIssuer, dummyNotary).forEach { + doReturn(it.party).whenever(mock).wellKnownPartyFromAnonymous(it.party) + doReturn(it.party).whenever(mock).wellKnownPartyFromX500Name(it.name) } } val schemaService = NodeSchemaService() @@ -110,7 +112,7 @@ class HibernateConfigurationTest { // `consumeCash` expects we can self-notarise transactions services = object : MockServices(cordappPackages, rigorousMock().also { doNothing().whenever(it).justVerifyAndRegisterIdentity(argThat { name == BOB_NAME }) - }, BOB_NAME, generateKeyPair(), DUMMY_NOTARY_KEY) { + }, BOB_NAME, generateKeyPair(), dummyNotary.key) { override val vaultService = makeVaultService(database.hibernateConfig, schemaService) override fun recordTransactions(statesToRecord: StatesToRecord, txs: Iterable) { for (stx in txs) { @@ -122,7 +124,7 @@ class HibernateConfigurationTest { override fun jdbcSession() = database.createSession() } - vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random) + vaultFiller = VaultFiller(services, dummyNotary, notary, ::Random) hibernatePersister = services.hibernatePersister } diff --git a/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt b/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt index 5f12128d53..16fa18453a 100644 --- a/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/schema/HibernateObserverTests.kt @@ -6,6 +6,7 @@ import net.corda.core.contracts.StateRef import net.corda.core.contracts.TransactionState import net.corda.core.crypto.SecureHash import net.corda.core.identity.AbstractParty +import net.corda.core.identity.CordaX500Name import net.corda.core.node.services.Vault import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState @@ -15,7 +16,7 @@ import net.corda.node.internal.configureDatabase import net.corda.nodeapi.internal.persistence.DatabaseConfig import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager import net.corda.testing.LogHelper -import net.corda.testing.MEGA_CORP +import net.corda.testing.TestIdentity import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import net.corda.testing.rigorousMock @@ -68,6 +69,7 @@ class HibernateObserverTests { val database = configureDatabase(makeTestDataSourceProperties(), DatabaseConfig(), rigorousMock(), schemaService) HibernateObserver.install(rawUpdatesPublisher, database.hibernateConfig, schemaService) database.transaction { + val MEGA_CORP = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party rawUpdatesPublisher.onNext(Vault.Update(emptySet(), setOf(StateAndRef(TransactionState(TestState(), DummyContract.PROGRAM_ID, MEGA_CORP), StateRef(SecureHash.sha256("dummy"), 0))))) val parentRowCountResult = DatabaseTransactionManager.current().connection.prepareStatement("select count(*) from Parents").executeQuery() parentRowCountResult.next() diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index ca84d944c3..a4737f44fa 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -38,6 +38,7 @@ import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode import net.corda.testing.node.MockNodeParameters import net.corda.testing.node.pumpReceive +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt index 734d046401..70cbc90835 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt @@ -20,7 +20,7 @@ import net.corda.testing.dummyCommand import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters import net.corda.testing.singleIdentity -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Before diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt index 75f7b88fd4..1c26932b19 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/PersistentUniquenessProviderTests.kt @@ -1,6 +1,7 @@ package net.corda.node.services.transactions import net.corda.core.crypto.SecureHash +import net.corda.core.identity.CordaX500Name import net.corda.core.node.services.UniquenessException import net.corda.node.internal.configureDatabase import net.corda.nodeapi.internal.persistence.CordaPersistence @@ -18,8 +19,7 @@ class PersistentUniquenessProviderTests { @Rule @JvmField val testSerialization = SerializationEnvironmentRule() - - private val identity = MEGA_CORP + private val identity = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")).party private val txID = SecureHash.randomSHA256() private lateinit var database: CordaPersistence diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt index 42a754ce01..ad56bfa5bc 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt @@ -5,6 +5,7 @@ import net.corda.core.contracts.Command import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef import net.corda.core.crypto.TransactionSignature +import net.corda.core.crypto.generateKeyPair import net.corda.core.flows.NotaryError import net.corda.core.flows.NotaryException import net.corda.core.flows.NotaryFlow @@ -19,6 +20,7 @@ import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.startFlow import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Before @@ -68,7 +70,7 @@ class ValidatingNotaryServiceTests { @Test fun `should report error for missing signatures`() { - val expectedMissingKey = MEGA_CORP_KEY.public + val expectedMissingKey = generateKeyPair().public val stx = run { val inputState = issueState(aliceServices, alice) diff --git a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt index d40bc86126..0a281f0713 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt @@ -6,7 +6,6 @@ import com.nhaarman.mockito_kotlin.doNothing import com.nhaarman.mockito_kotlin.whenever import net.corda.core.contracts.* import net.corda.core.crypto.NullKeys -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.* import net.corda.core.internal.packageName @@ -43,7 +42,6 @@ import org.junit.Rule import org.junit.Test import rx.observers.TestSubscriber import java.math.BigDecimal -import java.math.BigInteger import java.util.* import java.util.concurrent.CountDownLatch import java.util.concurrent.Executors @@ -54,10 +52,23 @@ import kotlin.test.assertTrue class NodeVaultServiceTest { private companion object { val cordappPackages = listOf("net.corda.finance.contracts.asset", CashSchemaV1::class.packageName) - val DUMMY_CASH_ISSUER_NAME = CordaX500Name("Snake Oil Issuer", "London", "GB") - val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) - val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY.public)) - val DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.party.ref(1) + val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) + val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1) + val bankOfCorda = TestIdentity(BOC_NAME) + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val BOC get() = bankOfCorda.party + val BOC_IDENTITY get() = bankOfCorda.identity + val DUMMY_CASH_ISSUER_IDENTITY get() = dummyCashIssuer.identity + val DUMMY_NOTARY get() = dummyNotary.party + val DUMMY_NOTARY_IDENTITY get() = dummyNotary.identity + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_KEY get() = megaCorp.key + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MEGA_CORP_IDENTITY get() = megaCorp.identity + val MINI_CORP get() = miniCorp.party + val MINI_CORP_IDENTITY get() = miniCorp.identity } @Rule @@ -81,11 +92,11 @@ class NodeVaultServiceTest { MEGA_CORP.name) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) + vaultFiller = VaultFiller(services, dummyNotary) // This is safe because MockServices only ever have a single identity identity = services.myInfo.singleIdentityAndCert() - issuerServices = MockServices(cordappPackages, rigorousMock(), DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) - bocServices = MockServices(cordappPackages, rigorousMock(), BOC_NAME, BOC_KEY) + issuerServices = MockServices(cordappPackages, rigorousMock(), dummyCashIssuer) + bocServices = MockServices(cordappPackages, rigorousMock(), bankOfCorda) services.identityService.verifyAndRegisterIdentity(DUMMY_CASH_ISSUER_IDENTITY) services.identityService.verifyAndRegisterIdentity(BOC_IDENTITY) } diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 14f8480444..1c5568a01d 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -2,12 +2,9 @@ package net.corda.node.services.vault import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.toStringShort import net.corda.core.identity.CordaX500Name -import net.corda.core.identity.Party -import net.corda.core.identity.PartyAndCertificate import net.corda.core.internal.packageName import net.corda.core.node.services.* import net.corda.core.node.services.vault.* @@ -39,8 +36,6 @@ import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.* import org.junit.rules.ExpectedException import java.lang.Thread.sleep -import java.math.BigInteger -import java.security.KeyPair import java.time.Instant import java.time.LocalDate import java.time.ZoneOffset @@ -49,10 +44,40 @@ import java.util.* open class VaultQueryTests { private companion object { - val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) - val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), DUMMY_CASH_ISSUER_KEY.public)) - val DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.party.ref(1) - val DUMMY_OBLIGATION_ISSUER = Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), entropyToKeyPair(BigInteger.valueOf(10)).public) + val alice = TestIdentity(ALICE_NAME, 70) + val bankOfCorda = TestIdentity(BOC_NAME) + val bigCorp = TestIdentity(CordaX500Name("BigCorporation", "New York", "US")) + val bob = TestIdentity(BOB_NAME, 80) + val cashNotary = TestIdentity(CordaX500Name("Cash Notary Service", "Zurich", "CH"), 21) + val charlie = TestIdentity(CHARLIE_NAME, 90) + val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) + val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1) + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val DUMMY_OBLIGATION_ISSUER = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10).party + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val ALICE get() = alice.party + val ALICE_IDENTITY get() = alice.identity + val BIG_CORP get() = bigCorp.party + val BIG_CORP_IDENTITY get() = bigCorp.identity + val BOB get() = bob.party + val BOB_IDENTITY get() = bob.identity + val BOC get() = bankOfCorda.party + val BOC_IDENTITY get() = bankOfCorda.identity + val BOC_KEY get() = bankOfCorda.key + val BOC_PUBKEY get() = bankOfCorda.pubkey + val CASH_NOTARY get() = cashNotary.party + val CASH_NOTARY_IDENTITY get() = cashNotary.identity + val CHARLIE get() = charlie.party + val CHARLIE_IDENTITY get() = charlie.identity + val DUMMY_NOTARY get() = dummyNotary.party + val DUMMY_NOTARY_KEY get() = dummyNotary.key + val MEGA_CORP_IDENTITY get() = megaCorp.identity + val MEGA_CORP_PUBKEY get() = megaCorp.pubkey + val MEGA_CORP_KEY get() = megaCorp.key + val MEGA_CORP get() = megaCorp.party + val MINI_CORP_IDENTITY get() = miniCorp.identity + val MINI_CORP get() = miniCorp.party } @Rule @JvmField @@ -74,25 +99,19 @@ open class VaultQueryTests { private val vaultService: VaultService get() = services.vaultService private lateinit var identitySvc: IdentityService private lateinit var database: CordaPersistence - - // test cash notary - private val CASH_NOTARY_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(21)) } - private val CASH_NOTARY: Party get() = Party(CordaX500Name(organisation = "Cash Notary Service", locality = "Zurich", country = "CH"), CASH_NOTARY_KEY.public) - private val CASH_NOTARY_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(CASH_NOTARY.nameOrNull(), CASH_NOTARY_KEY.public) - @Before open fun setUp() { // register additional identities val databaseAndServices = makeTestDatabaseAndMockServices( listOf(MEGA_CORP_KEY, DUMMY_NOTARY_KEY), - makeTestIdentityService(listOf(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, DUMMY_CASH_ISSUER_IDENTITY, DUMMY_NOTARY_IDENTITY)), + makeTestIdentityService(listOf(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity)), cordappPackages, MEGA_CORP.name) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) - vaultFillerCashNotary = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, CASH_NOTARY) - notaryServices = MockServices(cordappPackages, rigorousMock(), DUMMY_NOTARY.name, DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) + vaultFiller = VaultFiller(services, dummyNotary) + vaultFillerCashNotary = VaultFiller(services, dummyNotary, CASH_NOTARY) + notaryServices = MockServices(cordappPackages, rigorousMock(), dummyNotary, dummyCashIssuer.key, BOC_KEY, MEGA_CORP_KEY) identitySvc = services.identityService // Register all of the identities we're going to use (notaryServices.myInfo.legalIdentitiesAndCerts + BOC_IDENTITY + CASH_NOTARY_IDENTITY + MINI_CORP_IDENTITY + MEGA_CORP_IDENTITY).forEach { identity -> diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt index 0163cc210b..66f4973877 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt @@ -30,7 +30,7 @@ import net.corda.testing.chooseIdentity import net.corda.testing.node.MockNetwork import net.corda.testing.rigorousMock import net.corda.testing.node.MockNodeParameters -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import org.junit.After import org.junit.Test import java.util.* diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 2bed2fd84e..34ef9e5203 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -1,7 +1,6 @@ package net.corda.node.services.vault import net.corda.core.contracts.* -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AnonymousParty import net.corda.core.identity.CordaX500Name @@ -32,7 +31,6 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import java.math.BigInteger import java.util.concurrent.Executors import kotlin.test.assertEquals import kotlin.test.fail @@ -42,10 +40,17 @@ import kotlin.test.fail class VaultWithCashTest { private companion object { val cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts.asset", CashSchemaV1::class.packageName) - val DUMMY_CASH_ISSUER_NAME = CordaX500Name("Snake Oil Issuer", "London", "GB") - val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) - val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY.public)) - val DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.party.ref(1) + val BOB = TestIdentity(BOB_NAME, 80).party + val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) + val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1) + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) + val DUMMY_NOTARY get() = dummyNotary.party + val MEGA_CORP get() = megaCorp.party + val MEGA_CORP_IDENTITY get() = megaCorp.identity + val MEGA_CORP_KEY get() = megaCorp.key + val MINI_CORP_IDENTITY get() = miniCorp.identity } @Rule @@ -63,15 +68,15 @@ class VaultWithCashTest { fun setUp() { LogHelper.setLevel(VaultWithCashTest::class) val databaseAndServices = makeTestDatabaseAndMockServices( - listOf(generateKeyPair(), DUMMY_NOTARY_KEY), - makeTestIdentityService(listOf(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, DUMMY_CASH_ISSUER_IDENTITY, DUMMY_NOTARY_IDENTITY)), + listOf(generateKeyPair(), dummyNotary.key), + makeTestIdentityService(listOf(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity)), cordappPackages, MEGA_CORP.name) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) - issuerServices = MockServices(cordappPackages, rigorousMock(), DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) - notaryServices = MockServices(cordappPackages, rigorousMock(), DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) + vaultFiller = VaultFiller(services, dummyNotary) + issuerServices = MockServices(cordappPackages, rigorousMock(), dummyCashIssuer, MEGA_CORP_KEY) + notaryServices = MockServices(cordappPackages, rigorousMock(), dummyNotary) notary = notaryServices.myInfo.legalIdentitiesAndCerts.single().party } diff --git a/node/src/test/kotlin/net/corda/node/utilities/TLSAuthenticationTests.kt b/node/src/test/kotlin/net/corda/node/utilities/TLSAuthenticationTests.kt index a493f4d885..98ff559fe8 100644 --- a/node/src/test/kotlin/net/corda/node/utilities/TLSAuthenticationTests.kt +++ b/node/src/test/kotlin/net/corda/node/utilities/TLSAuthenticationTests.kt @@ -78,8 +78,7 @@ class TLSAuthenticationTests { client2TLSScheme = Crypto.ECDSA_SECP256R1_SHA256 ) - val (serverSocket, clientSocket) = - buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) + val (serverSocket, clientSocket) = buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) testConnect(serverSocket, clientSocket, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") } @@ -95,12 +94,27 @@ class TLSAuthenticationTests { client2TLSScheme = Crypto.RSA_SHA256 ) - val (serverSocket, clientSocket) = - buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) + val (serverSocket, clientSocket) = buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) testConnect(serverSocket, clientSocket, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256") } + @Test + fun `All EC K1`() { + val (serverSocketFactory, clientSocketFactory) = buildTLSFactories( + rootCAScheme = Crypto.ECDSA_SECP256K1_SHA256, + intermediateCAScheme = Crypto.ECDSA_SECP256K1_SHA256, + client1CAScheme = Crypto.ECDSA_SECP256K1_SHA256, + client1TLSScheme = Crypto.ECDSA_SECP256K1_SHA256, + client2CAScheme = Crypto.ECDSA_SECP256K1_SHA256, + client2TLSScheme = Crypto.ECDSA_SECP256K1_SHA256 + ) + + val (serverSocket, clientSocket) = buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) + + testConnect(serverSocket, clientSocket, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") + } + // Server's public key type is the one selected if users use different key types (e.g RSA and EC R1). @Test fun `Server RSA - Client EC R1 - CAs all EC R1`() { @@ -113,8 +127,7 @@ class TLSAuthenticationTests { client2TLSScheme = Crypto.ECDSA_SECP256R1_SHA256 ) - val (serverSocket, clientSocket) = - buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) + val (serverSocket, clientSocket) = buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) testConnect(serverSocket, clientSocket, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256") // Server's key type is selected. } @@ -148,6 +161,22 @@ class TLSAuthenticationTests { testConnect(serverSocket, clientSocket, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") } + @Test + fun `Server EC K1 - Client EC R1 - CAs all RSA`() { + val (serverSocketFactory, clientSocketFactory) = buildTLSFactories( + rootCAScheme = Crypto.RSA_SHA256, + intermediateCAScheme = Crypto.RSA_SHA256, + client1CAScheme = Crypto.RSA_SHA256, + client1TLSScheme = Crypto.ECDSA_SECP256K1_SHA256, + client2CAScheme = Crypto.RSA_SHA256, + client2TLSScheme = Crypto.ECDSA_SECP256R1_SHA256 + ) + + val (serverSocket, clientSocket) = buildTLSSockets(serverSocketFactory, clientSocketFactory, 0, 0) + testConnect(serverSocket, clientSocket, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") + } + + @Test fun `Server EC R1 - Client RSA - Mixed CAs`() { val (serverSocketFactory, clientSocketFactory) = buildTLSFactories( @@ -155,7 +184,7 @@ class TLSAuthenticationTests { intermediateCAScheme = Crypto.RSA_SHA256, client1CAScheme = Crypto.RSA_SHA256, client1TLSScheme = Crypto.ECDSA_SECP256R1_SHA256, - client2CAScheme = Crypto.ECDSA_SECP256R1_SHA256, + client2CAScheme = Crypto.ECDSA_SECP256K1_SHA256, client2TLSScheme = Crypto.RSA_SHA256 ) diff --git a/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelperTest.kt b/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelperTest.kt index 8c76a0ad82..ec8d1c961d 100644 --- a/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelperTest.kt +++ b/node/src/test/kotlin/net/corda/node/utilities/registration/NetworkRegistrationHelperTest.kt @@ -9,11 +9,13 @@ import net.corda.core.crypto.SecureHash import net.corda.core.identity.CordaX500Name import net.corda.core.internal.* import net.corda.node.services.config.NodeConfiguration -import net.corda.node.services.config.createKeystoreForCordaNode import net.corda.nodeapi.internal.crypto.* -import net.corda.testing.ALICE +import net.corda.nodeapi.internal.crypto.X509Utilities +import net.corda.nodeapi.internal.crypto.getX509Certificate +import net.corda.nodeapi.internal.crypto.loadKeyStore +import net.corda.testing.ALICE_NAME import net.corda.testing.rigorousMock -import net.corda.testing.testNodeConfiguration +import net.corda.testing.node.testNodeConfiguration import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Before import org.junit.Rule @@ -43,7 +45,7 @@ class NetworkRegistrationHelperTest { @Before fun init() { - config = testNodeConfiguration(baseDirectory = tempFolder.root.toPath(), myLegalName = ALICE.name) + config = testNodeConfiguration(baseDirectory = tempFolder.root.toPath(), myLegalName = ALICE_NAME) } @Test diff --git a/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt b/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt index 884fa333ea..90104b02d9 100644 --- a/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt +++ b/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt @@ -8,6 +8,8 @@ import net.corda.nodeapi.internal.config.User import net.corda.testing.DUMMY_BANK_A import net.corda.testing.DUMMY_BANK_B import net.corda.testing.* +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver import org.junit.ClassRule @@ -36,8 +38,8 @@ class AttachmentDemoTest : IntegrationTest() { invokeRpc(CordaRPCOps::internalVerifiedTransactionsFeed) ))) val (nodeA, nodeB) = listOf( - startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser, maximumHeapSize = "1g"), - startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser, maximumHeapSize = "1g") + startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser, maximumHeapSize = "1g"), + startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = demoUser, maximumHeapSize = "1g") ).map { it.getOrThrow() } startWebserver(nodeB).getOrThrow() diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt index e048bc791e..38e051f1b6 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt @@ -23,9 +23,9 @@ import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.getOrThrow -import net.corda.testing.DUMMY_BANK_B -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.internal.poll +import net.corda.testing.node.internal.poll +import net.corda.testing.DUMMY_BANK_B_NAME +import net.corda.testing.DUMMY_NOTARY_NAME import java.io.InputStream import java.net.HttpURLConnection import java.net.URL @@ -88,9 +88,8 @@ fun sender(rpc: CordaRPCOps, numOfClearBytes: Int = 1024) { // default size 1K. private fun sender(rpc: CordaRPCOps, inputStream: InputStream, hash: SecureHash.SHA256, executor: ScheduledExecutorService) { // Get the identity key of the other side (the recipient). - val notaryFuture: CordaFuture = poll(executor, DUMMY_NOTARY.name.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_NOTARY.name) } - val otherSideFuture: CordaFuture = poll(executor, DUMMY_BANK_B.name.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_BANK_B.name) } - + val notaryFuture: CordaFuture = poll(executor, DUMMY_NOTARY_NAME.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_NOTARY_NAME) } + val otherSideFuture: CordaFuture = poll(executor, DUMMY_BANK_B_NAME.toString()) { rpc.wellKnownPartyFromX500Name(DUMMY_BANK_B_NAME) } // Make sure we have the file in storage if (!rpc.attachmentExists(hash)) { inputStream.use { diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt index 9c3b8a2304..9f8c834519 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt @@ -2,8 +2,8 @@ package net.corda.attachmentdemo import net.corda.core.internal.div import net.corda.nodeapi.internal.config.User -import net.corda.testing.DUMMY_BANK_A -import net.corda.testing.DUMMY_BANK_B +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import net.corda.testing.driver.driver /** @@ -13,7 +13,7 @@ import net.corda.testing.driver.driver fun main(args: Array) { val demoUser = listOf(User("demo", "demo", setOf("StartFlow.net.corda.flows.FinalityFlow"))) driver(isDebug = true, driverDirectory = "build" / "attachment-demo-nodes", waitForAllNodesToFinish = true) { - startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser) - startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser) + startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser) + startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = demoUser) } } diff --git a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt index ce33e34030..90bb37a6b7 100644 --- a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt +++ b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaCordformTest.kt @@ -3,7 +3,7 @@ package net.corda.bank import net.corda.finance.DOLLARS import net.corda.finance.POUNDS import net.corda.testing.* -import net.corda.testing.internal.demorun.deployNodesThen +import net.corda.testing.node.internal.demorun.deployNodesThen import org.junit.ClassRule import org.junit.Test diff --git a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt index 88d7fc0347..d51bc7887a 100644 --- a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt +++ b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt @@ -4,6 +4,7 @@ import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow import net.corda.core.node.services.Vault import net.corda.core.node.services.vault.QueryCriteria +import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.getOrThrow import net.corda.finance.DOLLARS import net.corda.finance.contracts.asset.Cash @@ -35,7 +36,7 @@ class BankOfCordaRPCClientTest : IntegrationTest() { startFlow()) + commonPermissions) val bigCorpCFO = User("bigCorpCFO", "password2", permissions = emptySet() + commonPermissions) val (nodeBankOfCorda, nodeBigCorporation) = listOf( - startNode(providedName = BOC.name, rpcUsers = listOf(bocManager)), + startNode(providedName = BOC_NAME, rpcUsers = listOf(bocManager)), startNode(providedName = BIGCORP_NAME, rpcUsers = listOf(bigCorpCFO)) ).map { it.getOrThrow() } @@ -59,7 +60,7 @@ class BankOfCordaRPCClientTest : IntegrationTest() { // Kick-off actual Issuer Flow val anonymous = true bocProxy.startFlow(::CashIssueAndPaymentFlow, - 1000.DOLLARS, BIG_CORP_PARTY_REF, + 1000.DOLLARS, OpaqueBytes.of(1), bigCorporation, anonymous, defaultNotaryIdentity).returnValue.getOrThrow() diff --git a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaCordform.kt b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaCordform.kt index 0e286a14a0..b135d7baa1 100644 --- a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaCordform.kt +++ b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaCordform.kt @@ -13,8 +13,8 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.node.services.Permissions.Companion.all import net.corda.node.services.config.NotaryConfig import net.corda.nodeapi.internal.config.User -import net.corda.testing.BOC -import net.corda.testing.internal.demorun.* +import net.corda.testing.node.internal.demorun.* +import net.corda.testing.BOC_NAME import java.util.* import kotlin.system.exitProcess @@ -33,7 +33,7 @@ class BankOfCordaCordform : CordformDefinition() { rpcPort(10003) } node { - name(CordaX500Name(organisation = "BankOfCorda", locality = "London", country = "GB")) + name(BOC_NAME) extraConfig = mapOf("issuableCurrencies" to listOf("USD")) p2pPort(10005) rpcPort(BOC_RPC_PORT) @@ -101,7 +101,7 @@ object IssueCash { } private fun createParams(amount: Amount, notaryName: CordaX500Name): IssueRequestParams { - return IssueRequestParams(amount, BIGCORP_NAME, "1", BOC.name, notaryName) + return IssueRequestParams(amount, BIGCORP_NAME, "1", BOC_NAME, notaryName) } private fun printHelp(parser: OptionParser) { diff --git a/samples/irs-demo/README.md b/samples/irs-demo/README.md index b6576f192a..12af545191 100644 --- a/samples/irs-demo/README.md +++ b/samples/irs-demo/README.md @@ -21,8 +21,8 @@ To run from the command line in Windows: ``samples\irs-demo\build`` 2. Run ``gradlew.bat samples:irs-demo:web:deployWebapps`` to install configs and tools for running webservers 3. Run ``cd samples\irs-demo`` to change current working directory -4. Run ``cordapp\build\nodes\runnodes`` to open up several 3 terminals for each nodes -5. Run ``web\build\webapps\webapps`` to open up several 3 terminals for each nodes' webservers +4. Run ``cordapp\build\nodes\runnodes.bat`` to open up several 3 terminals for each nodes +5. Run ``web\build\webapps\webapps.bat`` to open up several 3 terminals for each nodes' webservers This demo also has a web app. To use this, run nodes and then navigate to http://localhost:10007/ and http://localhost:10010/ to see each node's view of the ledger. @@ -33,4 +33,4 @@ view it. *Note:* The IRS web UI currently has a bug when changing the clock time where it may show no numbers or apply fixings inconsistently. The issues will be addressed in a future milestone release. Meanwhile, you can take a look at a simpler -oracle example here: https://github.com/corda/oracle-example. \ No newline at end of file +oracle example here: https://github.com/corda/oracle-example. diff --git a/samples/irs-demo/cordapp/build.gradle b/samples/irs-demo/cordapp/build.gradle index 26f7839d04..3b5dbd4c08 100644 --- a/samples/irs-demo/cordapp/build.gradle +++ b/samples/irs-demo/cordapp/build.gradle @@ -53,7 +53,9 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) { "StartFlow.net.corda.irs.flows.UpdateBusinessDayFlow\$Broadcast", "StartFlow.net.corda.irs.api.NodeInterestRates\$UploadFixesFlow", "InvokeRpc.vaultQueryBy", - "InvokeRpc.networkMapSnapshot" + "InvokeRpc.networkMapSnapshot", + "InvokeRpc.currentNodeTime", + "InvokeRpc.wellKnownPartyFromX500Name" ]] ] diff --git a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/Main.kt b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/Main.kt index 91315e3e9f..976126a8c8 100644 --- a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/Main.kt +++ b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/Main.kt @@ -1,8 +1,8 @@ package net.corda.irs import net.corda.core.utilities.getOrThrow -import net.corda.testing.DUMMY_BANK_A -import net.corda.testing.DUMMY_BANK_B +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import net.corda.testing.driver.driver /** @@ -12,8 +12,8 @@ import net.corda.testing.driver.driver fun main(args: Array) { driver(useTestClock = true, isDebug = true, waitForAllNodesToFinish = true) { val (nodeA, nodeB) = listOf( - startNode(providedName = DUMMY_BANK_A.name), - startNode(providedName = DUMMY_BANK_B.name) + startNode(providedName = DUMMY_BANK_A_NAME), + startNode(providedName = DUMMY_BANK_B_NAME) ).map { it.getOrThrow() } val controller = defaultNotaryNode.getOrThrow() diff --git a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt index ad45bbfbc6..11d6e8ac1b 100644 --- a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt +++ b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt @@ -33,6 +33,14 @@ import kotlin.test.assertFailsWith import kotlin.test.assertFalse class NodeInterestRatesTest { + private companion object { + val alice = TestIdentity(ALICE_NAME, 70) + val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party + val MEGA_CORP_KEY = generateKeyPair() + val ALICE get() = alice.party + val ALICE_PUBKEY get() = alice.pubkey + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() @@ -44,10 +52,8 @@ class NodeInterestRatesTest { EURIBOR 2016-03-15 1M = 0.123 EURIBOR 2016-03-15 2M = 0.111 """.trimIndent()) - - private val DUMMY_CASH_ISSUER_KEY = generateKeyPair() - private val DUMMY_CASH_ISSUER = Party(CordaX500Name(organisation = "Cash issuer", locality = "London", country = "GB"), DUMMY_CASH_ISSUER_KEY.public) - private val services = MockServices(listOf("net.corda.finance.contracts.asset"), rigorousMock(), DUMMY_CASH_ISSUER.name, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) + private val dummyCashIssuer = TestIdentity(CordaX500Name("Cash issuer", "London", "GB")) + private val services = MockServices(listOf("net.corda.finance.contracts.asset"), rigorousMock(), dummyCashIssuer, MEGA_CORP_KEY) // This is safe because MockServices only ever have a single identity private val identity = services.myInfo.singleIdentity() @@ -244,7 +250,7 @@ class NodeInterestRatesTest { } private fun makePartialTX() = TransactionBuilder(DUMMY_NOTARY).withItems( - TransactionState(1000.DOLLARS.CASH issuedBy DUMMY_CASH_ISSUER ownedBy ALICE, Cash.PROGRAM_ID, DUMMY_NOTARY)) + TransactionState(1000.DOLLARS.CASH issuedBy dummyCashIssuer.party ownedBy ALICE, Cash.PROGRAM_ID, DUMMY_NOTARY)) private fun makeFullTx() = makePartialTX().withItems(dummyCommand()) } diff --git a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/contract/IRSTests.kt b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/contract/IRSTests.kt index 5e0f0971bb..262681c0c6 100644 --- a/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/contract/IRSTests.kt +++ b/samples/irs-demo/cordapp/src/test/kotlin/net/corda/irs/contract/IRSTests.kt @@ -26,6 +26,8 @@ import net.corda.finance.contracts.Tenor import net.corda.node.services.api.IdentityServiceInternal import net.corda.testing.* import net.corda.testing.node.MockServices +import net.corda.testing.node.ledger +import net.corda.testing.node.transaction import org.junit.Rule import org.junit.Test import java.math.BigDecimal @@ -34,6 +36,17 @@ import java.util.* import kotlin.test.assertEquals private val DUMMY_PARTY = Party(CordaX500Name("Dummy", "Madrid", "ES"), generateKeyPair().public) +private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) +private val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) +private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) +private val ORACLE_PUBKEY = TestIdentity(CordaX500Name("Oracle", "London", "GB")).pubkey +private val DUMMY_NOTARY get() = dummyNotary.party +private val DUMMY_NOTARY_KEY get() = dummyNotary.key +private val MEGA_CORP get() = megaCorp.party +private val MEGA_CORP_KEY get() = megaCorp.key +private val MEGA_CORP_PUBKEY get() = megaCorp.pubkey +private val MINI_CORP get() = miniCorp.party +private val MINI_CORP_KEY get() = miniCorp.key fun createDummyIRS(irsSelect: Int): InterestRateSwap.State { return when (irsSelect) { 1 -> { diff --git a/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt b/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt index 4ca7816dd2..36199da563 100644 --- a/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt +++ b/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt @@ -52,13 +52,13 @@ class IRSDemoTest : IntegrationTest() { fun `runs IRS demo`() { springDriver( useTestClock = true, - notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name, rpcUsers = rpcUsers)), + notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, rpcUsers = rpcUsers)), isDebug = true, extraCordappPackagesToScan = listOf("net.corda.irs") ) { val (nodeA, nodeB) = listOf( - startNode(providedName = DUMMY_BANK_A.name, rpcUsers = rpcUsers), - startNode(providedName = DUMMY_BANK_B.name, rpcUsers = rpcUsers) + startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = rpcUsers), + startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = rpcUsers) ).map { it.getOrThrow() } val controller = defaultNotaryNode.getOrThrow() diff --git a/samples/irs-demo/src/integration-test/kotlin/net/corda/test/spring/SpringDriver.kt b/samples/irs-demo/src/integration-test/kotlin/net/corda/test/spring/SpringDriver.kt index a55e1a3a5c..c7d7a57ffd 100644 --- a/samples/irs-demo/src/integration-test/kotlin/net/corda/test/spring/SpringDriver.kt +++ b/samples/irs-demo/src/integration-test/kotlin/net/corda/test/spring/SpringDriver.kt @@ -7,8 +7,8 @@ import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.WebserverHandle -import net.corda.testing.internal.* import net.corda.testing.node.NotarySpec +import net.corda.testing.node.internal.* import okhttp3.OkHttpClient import okhttp3.Request import java.net.ConnectException diff --git a/samples/irs-demo/web/src/test/resources/scripts/runwebapps.sh b/samples/irs-demo/web/src/test/resources/scripts/runwebapps.sh index c87f95821c..23da672eba 100755 --- a/samples/irs-demo/web/src/test/resources/scripts/runwebapps.sh +++ b/samples/irs-demo/web/src/test/resources/scripts/runwebapps.sh @@ -2,13 +2,13 @@ function run_webapp() { if [ ! -z "$TMUX" ]; then - tmux new-window -n $1 $2; [ $? -eq 0 -o $? -eq 143 ] || sh + tmux new-window -n $1 "$2"; [ $? -eq 0 -o $? -eq 143 ] || sh else - xterm -T $1 -e $2; [ $? -eq 0 -o $? -eq 143 ] || sh + xterm -T $1 -e "$2"; [ $? -eq 0 -o $? -eq 143 ] || sh fi; } -run_webapp "NotaryService" "cd \"#DIR#\" && java -Dspring.profiles.active=NotaryService -jar #JAR_PATH#" -run_webapp "BankA" "cd \"#DIR#\" && java -Dspring.profiles.active=BankA -jar #JAR_PATH#" -run_webapp "BankB" "cd \"#DIR#\" && java -Dspring.profiles.active=BankB -jar #JAR_PATH#" +run_webapp "NotaryService" "cd \"#DIR#\" && java -Dspring.profiles.active=NotaryService -jar #JAR_PATH#" & +run_webapp "BankA" "cd \"#DIR#\" && java -Dspring.profiles.active=BankA -jar #JAR_PATH#" & +run_webapp "BankB" "cd \"#DIR#\" && java -Dspring.profiles.active=BankB -jar #JAR_PATH#" & diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/IRSSimulation.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/IRSSimulation.kt index af8525a222..02fc5ca84d 100644 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/IRSSimulation.kt +++ b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/IRSSimulation.kt @@ -24,7 +24,7 @@ import net.corda.irs.flows.FixingFlow import net.corda.testing.chooseIdentity import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.makeTestIdentityService -import net.corda.testing.startFlow +import net.corda.testing.node.startFlow import rx.Observable import java.time.LocalDate import java.util.* diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt index 175047ad33..83558cd9ef 100644 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt +++ b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt @@ -9,7 +9,7 @@ import net.corda.finance.utils.CityDatabase import net.corda.irs.api.NodeInterestRates import net.corda.node.internal.StartedNode import net.corda.node.services.statemachine.StateMachineManager -import net.corda.testing.DUMMY_REGULATOR +import net.corda.testing.TestIdentity import net.corda.testing.node.* import net.corda.testing.node.MockNetwork.MockNode import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties @@ -35,11 +35,12 @@ internal val MockNetwork.MockNode.place get() = configuration.myLegalName.locali abstract class Simulation(val networkSendManuallyPumped: Boolean, runAsync: Boolean, latencyInjector: InMemoryMessagingNetwork.LatencyCalculator?) { - companion object { - private val defaultParams // The get() is necessary so that entropyRoot isn't shared. + private companion object { + val defaultParams // The get() is necessary so that entropyRoot isn't shared. get() = MockNodeParameters(configOverrides = { doReturn(makeTestDataSourceProperties(it.myLegalName.organisation)).whenever(it).dataSourceProperties }) + val DUMMY_REGULATOR = TestIdentity(CordaX500Name("Regulator A", "Paris", "FR"), 100).party } init { diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/BFTNotaryCordform.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/BFTNotaryCordform.kt index 6735271686..eb11a9b443 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/BFTNotaryCordform.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/BFTNotaryCordform.kt @@ -11,9 +11,9 @@ import net.corda.node.services.config.NotaryConfig import net.corda.node.services.transactions.BFTNonValidatingNotaryService import net.corda.node.services.transactions.minCorrectReplicas import net.corda.nodeapi.internal.ServiceIdentityGenerator -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.internal.demorun.* +import net.corda.testing.node.internal.demorun.* +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME import java.nio.file.Paths fun main(args: Array) = BFTNotaryCordform().deployNodes() @@ -29,13 +29,13 @@ class BFTNotaryCordform : CordformDefinition() { init { nodesDirectory = Paths.get("build", "nodes", "nodesBFT") node { - name(ALICE.name) + name(ALICE_NAME) p2pPort(10002) rpcPort(10003) rpcUsers(notaryDemoUser) } node { - name(BOB.name) + name(BOB_NAME) p2pPort(10005) rpcPort(10006) } diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Clean.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Clean.kt index 7ab6fff629..91aa5ba967 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Clean.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Clean.kt @@ -1,6 +1,6 @@ package net.corda.notarydemo -import net.corda.testing.internal.demorun.clean +import net.corda.testing.node.internal.demorun.clean fun main(args: Array) { listOf(SingleNotaryCordform(), RaftNotaryCordform(), BFTNotaryCordform()).forEach { diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/CustomNotaryCordform.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/CustomNotaryCordform.kt index 8117ef9a60..91dc8c5f39 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/CustomNotaryCordform.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/CustomNotaryCordform.kt @@ -3,10 +3,8 @@ package net.corda.notarydemo import net.corda.cordform.CordformContext import net.corda.cordform.CordformDefinition import net.corda.node.services.config.NotaryConfig -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.internal.demorun.* +import net.corda.testing.node.internal.demorun.* +import net.corda.testing.* import java.nio.file.Paths fun main(args: Array) = CustomNotaryCordform().deployNodes() @@ -15,18 +13,18 @@ class CustomNotaryCordform : CordformDefinition() { init { nodesDirectory = Paths.get("build", "nodes", "nodesCustom") node { - name(ALICE.name) + name(ALICE_NAME) p2pPort(10002) rpcPort(10003) rpcUsers(notaryDemoUser) } node { - name(BOB.name) + name(BOB_NAME) p2pPort(10005) rpcPort(10006) } node { - name(DUMMY_NOTARY.name) + name(DUMMY_NOTARY_NAME) p2pPort(10009) rpcPort(10010) notary(NotaryConfig(validating = true, custom = true)) diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt index cabacf9476..6a59809cf6 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/Notarise.kt @@ -10,7 +10,7 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.notarydemo.flows.DummyIssueAndMove import net.corda.notarydemo.flows.RPCStartableNotaryFlowClient -import net.corda.testing.BOB +import net.corda.testing.BOB_NAME import java.util.concurrent.Future fun main(args: Array) { @@ -31,7 +31,7 @@ private class NotaryDemoClientApi(val rpc: CordaRPCOps) { private val counterparty by lazy { val parties = rpc.networkMapSnapshot() parties.fold(ArrayList()) { acc, elem -> - acc.addAll(elem.legalIdentitiesAndCerts.filter { it.name == BOB.name }) + acc.addAll(elem.legalIdentitiesAndCerts.filter { it.name == BOB_NAME }) acc }.single().party } diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/RaftNotaryCordform.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/RaftNotaryCordform.kt index 4ba0b53210..cfc21fa060 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/RaftNotaryCordform.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/RaftNotaryCordform.kt @@ -4,16 +4,15 @@ import net.corda.cordform.CordformContext import net.corda.cordform.CordformDefinition import net.corda.cordform.CordformNode import net.corda.core.identity.CordaX500Name -import net.corda.core.internal.div import net.corda.core.node.services.NotaryService import net.corda.core.utilities.NetworkHostAndPort import net.corda.node.services.config.NotaryConfig import net.corda.node.services.config.RaftConfig import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.nodeapi.internal.ServiceIdentityGenerator -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.internal.demorun.* +import net.corda.testing.node.internal.demorun.* +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME import java.nio.file.Paths fun main(args: Array) = RaftNotaryCordform().deployNodes() @@ -30,13 +29,13 @@ class RaftNotaryCordform : CordformDefinition() { init { nodesDirectory = Paths.get("build", "nodes", "nodesRaft") node { - name(ALICE.name) + name(ALICE_NAME) p2pPort(10002) rpcPort(10003) rpcUsers(notaryDemoUser) } node { - name(BOB.name) + name(BOB_NAME) p2pPort(10005) rpcPort(10006) } diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/SingleNotaryCordform.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/SingleNotaryCordform.kt index ea2366c953..4910a57d3e 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/SingleNotaryCordform.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/SingleNotaryCordform.kt @@ -5,10 +5,8 @@ import net.corda.cordform.CordformDefinition import net.corda.node.services.Permissions.Companion.all import net.corda.node.services.config.NotaryConfig import net.corda.nodeapi.internal.config.User -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.internal.demorun.* +import net.corda.testing.node.internal.demorun.* +import net.corda.testing.* import java.nio.file.Paths fun main(args: Array) = SingleNotaryCordform().deployNodes() @@ -21,18 +19,18 @@ class SingleNotaryCordform : CordformDefinition() { init { nodesDirectory = Paths.get("build", "nodes", "nodesSingle") node { - name(ALICE.name) + name(ALICE_NAME) p2pPort(10002) rpcPort(10003) rpcUsers(notaryDemoUser) } node { - name(BOB.name) + name(BOB_NAME) p2pPort(10005) rpcPort(10006) } node { - name(DUMMY_NOTARY.name) + name(DUMMY_NOTARY_NAME) p2pPort(10009) rpcPort(10010) notary(NotaryConfig(validating = true)) diff --git a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt index 33a110c2ad..6ad3688bc0 100644 --- a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt +++ b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt @@ -4,6 +4,8 @@ import com.opengamma.strata.product.common.BuySell import net.corda.core.identity.CordaX500Name import net.corda.core.utilities.getOrThrow import net.corda.testing.* +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import net.corda.testing.driver.driver import net.corda.testing.http.HttpApi import net.corda.vega.api.PortfolioApi @@ -20,8 +22,8 @@ class SimmValuationTest : IntegrationTest() { private companion object { // SIMM demo can only currently handle one valuation date due to a lack of market data or a market data source. val valuationDate: LocalDate = LocalDate.parse("2016-06-06") - val nodeALegalName = DUMMY_BANK_A.name - val nodeBLegalName = DUMMY_BANK_B.name + val nodeALegalName = DUMMY_BANK_A_NAME + val nodeBLegalName = DUMMY_BANK_B_NAME val testTradeId = "trade1" @ClassRule @JvmField diff --git a/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt b/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt index 41d82323bd..3bf26cef2a 100644 --- a/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt +++ b/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt @@ -1,9 +1,7 @@ package net.corda.vega import net.corda.core.utilities.getOrThrow -import net.corda.testing.DUMMY_BANK_A -import net.corda.testing.DUMMY_BANK_B -import net.corda.testing.DUMMY_BANK_C +import net.corda.testing.* import net.corda.testing.driver.driver /** @@ -14,9 +12,9 @@ import net.corda.testing.driver.driver fun main(args: Array) { driver(isDebug = true, waitForAllNodesToFinish = true) { val (nodeA, nodeB, nodeC) = listOf( - startNode(providedName = DUMMY_BANK_A.name), - startNode(providedName = DUMMY_BANK_B.name), - startNode(providedName = DUMMY_BANK_C.name) + startNode(providedName = DUMMY_BANK_A_NAME), + startNode(providedName = DUMMY_BANK_B_NAME), + startNode(providedName = DUMMY_BANK_C_NAME) ).map { it.getOrThrow() } startWebserver(nodeA) diff --git a/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt b/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt index 1c4d862fa2..b2e1e3e84e 100644 --- a/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt +++ b/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt @@ -14,9 +14,10 @@ import net.corda.testing.DUMMY_BANK_A import net.corda.testing.DUMMY_BANK_B import net.corda.testing.chooseIdentity import net.corda.testing.* +import net.corda.testing.* import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.driver -import net.corda.testing.internal.poll +import net.corda.testing.node.internal.poll import net.corda.traderdemo.flow.BuyerFlow import net.corda.traderdemo.flow.CommercialPaperIssueFlow import net.corda.traderdemo.flow.SellerFlow @@ -41,9 +42,9 @@ class TraderDemoTest : IntegrationTest() { all())) driver(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.finance")) { val (nodeA, nodeB, bankNode) = listOf( - startNode(providedName = DUMMY_BANK_A.name, rpcUsers = listOf(demoUser)), - startNode(providedName = DUMMY_BANK_B.name, rpcUsers = listOf(demoUser)), - startNode(providedName = BOC.name, rpcUsers = listOf(bankUser)) + startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = listOf(demoUser)), + startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)), + startNode(providedName = BOC_NAME, rpcUsers = listOf(bankUser)) ).map { (it.getOrThrow() as NodeHandle.InProcess).node } nodeA.registerInitiatedFlow(BuyerFlow::class.java) val (nodeARpc, nodeBRpc) = listOf(nodeA, nodeB).map { diff --git a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemo.kt b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemo.kt index e519481e3a..7766be2a19 100644 --- a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemo.kt +++ b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemo.kt @@ -5,8 +5,8 @@ import net.corda.client.rpc.CordaRPCClient import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.contextLogger import net.corda.finance.DOLLARS -import net.corda.testing.DUMMY_BANK_A -import net.corda.testing.DUMMY_BANK_B +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import kotlin.system.exitProcess /** @@ -24,8 +24,8 @@ private class TraderDemo { companion object { private val logger = contextLogger() - val buyerName = DUMMY_BANK_A.name - val sellerName = DUMMY_BANK_B.name + val buyerName = DUMMY_BANK_A_NAME + val sellerName = DUMMY_BANK_B_NAME val sellerRpcPort = 10009 val bankRpcPort = 10012 } diff --git a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt index b59890ab61..c3314ff155 100644 --- a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt +++ b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt @@ -5,9 +5,9 @@ import net.corda.finance.flows.CashIssueFlow import net.corda.node.services.Permissions.Companion.all import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User -import net.corda.testing.BOC -import net.corda.testing.DUMMY_BANK_A -import net.corda.testing.DUMMY_BANK_B +import net.corda.testing.BOC_NAME +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_BANK_B_NAME import net.corda.testing.driver.driver import net.corda.traderdemo.flow.CommercialPaperIssueFlow import net.corda.traderdemo.flow.SellerFlow @@ -26,8 +26,8 @@ fun main(args: Array) { val user = User("user1", "test", permissions = setOf(startFlow(), startFlow(), startFlow())) - startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser) - startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser) - startNode(providedName = BOC.name, rpcUsers = listOf(user)) + startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser) + startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = demoUser) + startNode(providedName = BOC_NAME, rpcUsers = listOf(user)) } } diff --git a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/TransactionGraphSearchTests.kt b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/TransactionGraphSearchTests.kt index dea21d50d3..7f73c6f306 100644 --- a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/TransactionGraphSearchTests.kt +++ b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/TransactionGraphSearchTests.kt @@ -2,6 +2,7 @@ package net.corda.traderdemo import net.corda.core.contracts.CommandData import net.corda.core.crypto.newSecureRandom +import net.corda.core.identity.CordaX500Name import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.WireTransaction @@ -15,6 +16,11 @@ import org.junit.Test import kotlin.test.assertEquals class TransactionGraphSearchTests { + private companion object { + val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) + val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) + } + @Rule @JvmField val testSerialization = SerializationEnvironmentRule() @@ -36,18 +42,17 @@ class TransactionGraphSearchTests { * @param signer signer for the two transactions and their commands. */ fun buildTransactions(command: CommandData): GraphTransactionStorage { - val megaCorpServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), MEGA_CORP.name, MEGA_CORP_KEY) - val notaryServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) - val originBuilder = TransactionBuilder(DUMMY_NOTARY) + val megaCorpServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), megaCorp) + val notaryServices = MockServices(listOf("net.corda.testing.contracts"), rigorousMock(), dummyNotary) + val originBuilder = TransactionBuilder(dummyNotary.party) .addOutputState(DummyState(random31BitValue()), DummyContract.PROGRAM_ID) - .addCommand(command, MEGA_CORP_PUBKEY) + .addCommand(command, megaCorp.pubkey) val originPtx = megaCorpServices.signInitialTransaction(originBuilder) val originTx = notaryServices.addSignature(originPtx) - - val inputBuilder = TransactionBuilder(DUMMY_NOTARY) + val inputBuilder = TransactionBuilder(dummyNotary.party) .addInputState(originTx.tx.outRef(0)) - .addCommand(dummyCommand(MEGA_CORP_PUBKEY)) + .addCommand(dummyCommand(megaCorp.pubkey)) val inputPtx = megaCorpServices.signInitialTransaction(inputBuilder) val inputTx = megaCorpServices.addSignature(inputPtx) diff --git a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt index 411787bcff..0933439473 100644 --- a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt +++ b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt @@ -1,53 +1,45 @@ package net.corda.testing.driver import net.corda.core.concurrent.CordaFuture -import net.corda.core.internal.copyTo +import net.corda.core.identity.CordaX500Name import net.corda.core.internal.div import net.corda.core.internal.list import net.corda.core.internal.readLines import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow -import net.corda.core.utilities.seconds import net.corda.node.internal.NodeStartup import net.corda.nodeapi.internal.crypto.X509Utilities import net.corda.nodeapi.internal.crypto.getX509Certificate import net.corda.nodeapi.internal.crypto.loadOrCreateKeyStore import net.corda.testing.* import net.corda.testing.common.internal.ProjectStructure.projectRootDir +import net.corda.testing.node.internal.addressMustBeBound +import net.corda.testing.node.internal.addressMustNotBeBound +import net.corda.testing.node.internal.internalDriver +import net.corda.testing.DUMMY_BANK_A_NAME +import net.corda.testing.DUMMY_NOTARY_NAME import net.corda.testing.http.HttpApi -import net.corda.testing.internal.CompatibilityZoneParams -import net.corda.testing.internal.addressMustBeBound -import net.corda.testing.internal.addressMustNotBeBound -import net.corda.testing.internal.internalDriver import net.corda.testing.node.NotarySpec -import net.corda.testing.node.network.NetworkMapServer import org.assertj.core.api.Assertions.assertThat import org.json.simple.JSONObject import org.junit.Rule import org.junit.ClassRule import org.junit.Test -import org.junit.rules.TemporaryFolder -import java.net.URL import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService -import javax.ws.rs.GET -import javax.ws.rs.POST -import javax.ws.rs.Path -import javax.ws.rs.core.Response -import javax.ws.rs.core.Response.ok - class DriverTests : IntegrationTest() { companion object { - private val executorService: ScheduledExecutorService = Executors.newScheduledThreadPool(2) + val DUMMY_REGULATOR_NAME = CordaX500Name("Regulator A", "Paris", "FR") + val executorService: ScheduledExecutorService = Executors.newScheduledThreadPool(2) - private fun nodeMustBeUp(handleFuture: CordaFuture) = handleFuture.getOrThrow().apply { + fun nodeMustBeUp(handleFuture: CordaFuture) = handleFuture.getOrThrow().apply { val hostAndPort = nodeInfo.addresses.first() // Check that the port is bound addressMustBeBound(executorService, hostAndPort, (this as? NodeHandle.OutOfProcess)?.process) } - private fun nodeMustBeDown(handle: NodeHandle) { + fun nodeMustBeDown(handle: NodeHandle) { val hostAndPort = handle.nodeInfo.addresses.first() // Check that the port is bound addressMustNotBeBound(executorService, hostAndPort) @@ -61,7 +53,7 @@ class DriverTests : IntegrationTest() { @Test fun `simple node startup and shutdown`() { val handle = driver { - val regulator = startNode(providedName = DUMMY_REGULATOR.name) + val regulator = startNode(providedName = DUMMY_REGULATOR_NAME) nodeMustBeUp(regulator) } nodeMustBeDown(handle) @@ -70,7 +62,7 @@ class DriverTests : IntegrationTest() { @Test fun `random free port allocation`() { val nodeHandle = driver(portAllocation = PortAllocation.RandomFree) { - val nodeInfo = startNode(providedName = DUMMY_BANK_A.name) + val nodeInfo = startNode(providedName = DUMMY_BANK_A_NAME) nodeMustBeUp(nodeInfo) } nodeMustBeDown(nodeHandle) @@ -82,7 +74,7 @@ class DriverTests : IntegrationTest() { val logConfigFile = projectRootDir / "config" / "dev" / "log4j2.xml" assertThat(logConfigFile).isRegularFile() driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) { - val baseDirectory = startNode(providedName = DUMMY_BANK_A.name).getOrThrow().configuration.baseDirectory + val baseDirectory = startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow().configuration.baseDirectory val logFile = (baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME).list { it.sorted().findFirst().get() } val debugLinesPresent = logFile.readLines { lines -> lines.anyMatch { line -> line.startsWith("[DEBUG]") } } assertThat(debugLinesPresent).isTrue() @@ -93,8 +85,7 @@ class DriverTests : IntegrationTest() { fun `monitoring mode enables jolokia exporting of JMX metrics via HTTP JSON`() { driver(jmxPolicy = JmxPolicy(true)) { // start another node so we gain access to node JMX metrics - startNode(providedName = DUMMY_REGULATOR.name).getOrThrow() - + startNode(providedName = DUMMY_REGULATOR_NAME).getOrThrow() val webAddress = NetworkHostAndPort("localhost", 7006) // request access to some JMX metrics via Jolokia HTTP/JSON val api = HttpApi.fromHostAndPort(webAddress, "/jolokia/") @@ -112,8 +103,8 @@ class DriverTests : IntegrationTest() { assertThat(baseDirectory / "process-id").exists() } - val baseDirectory = internalDriver(notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name))) { - baseDirectory(DUMMY_NOTARY.name) + val baseDirectory = internalDriver(notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME))) { + baseDirectory(DUMMY_NOTARY_NAME) } assertThat(baseDirectory / "process-id").doesNotExist() } diff --git a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/FlowStackSnapshotTest.kt b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/FlowStackSnapshotTest.kt similarity index 99% rename from testing/node-driver/src/integration-test/kotlin/net/corda/testing/FlowStackSnapshotTest.kt rename to testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/FlowStackSnapshotTest.kt index c6e01c4193..8c3636ffc1 100644 --- a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/FlowStackSnapshotTest.kt +++ b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/FlowStackSnapshotTest.kt @@ -1,4 +1,4 @@ -package net.corda.testing +package net.corda.testing.node import co.paralleluniverse.fibers.Suspendable import net.corda.client.jackson.JacksonSupport @@ -11,7 +11,6 @@ import net.corda.core.serialization.CordaSerializable import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User import net.corda.testing.driver.driver -import net.corda.testing.node.MockNetwork import org.junit.Ignore import org.junit.Test import java.nio.file.Path diff --git a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/internal/ProcessUtilitiesTests.kt b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/internal/ProcessUtilitiesTests.kt similarity index 96% rename from testing/node-driver/src/integration-test/kotlin/net/corda/testing/internal/ProcessUtilitiesTests.kt rename to testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/internal/ProcessUtilitiesTests.kt index 0e6b8a6961..a1822d0e3a 100644 --- a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/internal/ProcessUtilitiesTests.kt +++ b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/node/internal/ProcessUtilitiesTests.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import org.apache.commons.io.FileUtils import org.junit.Rule diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt index 1279969c67..3797c75b64 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -14,10 +14,10 @@ import net.corda.node.internal.StartedNode import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.VerifierType import net.corda.nodeapi.internal.config.User -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.internal.DriverDSLImpl -import net.corda.testing.internal.genericDriver -import net.corda.testing.internal.getTimestampAsDirectoryName +import net.corda.testing.node.internal.DriverDSLImpl +import net.corda.testing.node.internal.genericDriver +import net.corda.testing.node.internal.getTimestampAsDirectoryName +import net.corda.testing.DUMMY_NOTARY_NAME import net.corda.testing.node.NotarySpec import java.net.InetSocketAddress import java.net.ServerSocket @@ -229,7 +229,7 @@ data class DriverParameters( val initialiseSerialization: Boolean = true, val startNodesInProcess: Boolean = false, val waitForAllNodesToFinish: Boolean = false, - val notarySpecs: List = listOf(NotarySpec(DUMMY_NOTARY.name)), + val notarySpecs: List = listOf(NotarySpec(DUMMY_NOTARY_NAME)), val extraCordappPackagesToScan: List = emptyList(), val jmxPolicy: JmxPolicy = JmxPolicy() ) { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt index 2e907b8a9f..dfda6b82fe 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -40,20 +40,17 @@ import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.ServiceIdentityGenerator import net.corda.nodeapi.internal.NotaryInfo -import net.corda.testing.DUMMY_NOTARY import net.corda.nodeapi.internal.NetworkParametersCopier import net.corda.testing.common.internal.testNetworkParameters +import net.corda.testing.DUMMY_NOTARY_NAME import net.corda.testing.internal.testThreadFactory import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import net.corda.testing.node.MockServices.Companion.makeTestDatabaseProperties import net.corda.testing.setGlobalSerialization -import net.corda.testing.testNodeConfiguration import org.apache.activemq.artemis.utils.ReusableLatch import org.apache.sshd.common.util.security.SecurityUtils import rx.internal.schedulers.CachedThreadScheduler -import org.slf4j.Logger -import java.io.Closeable import java.math.BigInteger import java.nio.file.Path import java.security.KeyPair @@ -129,7 +126,7 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy, private val defaultFactory: (MockNodeArgs) -> MockNode = defaultParameters.defaultFactory, initialiseSerialization: Boolean = defaultParameters.initialiseSerialization, - private val notarySpecs: List = listOf(NotarySpec(DUMMY_NOTARY.name)), + private val notarySpecs: List = listOf(NotarySpec(DUMMY_NOTARY_NAME)), private val cordappPackages: List = defaultParameters.cordappPackages) { /** Helper constructor for creating a [MockNetwork] with custom parameters from Java. */ constructor(parameters: MockNetworkParameters) : this(defaultParameters = parameters) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt index 1696cd9a5e..79cc9d361a 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt @@ -47,6 +47,8 @@ import net.corda.testing.database.DatabaseConstants.DATA_SOURCE_URL import net.corda.testing.database.DatabaseConstants.DATA_SOURCE_USER import net.corda.testing.database.DatabaseConstants.SCHEMA import net.corda.testing.database.DatabaseConstants.TRANSACTION_ISOLATION_LEVEL +import net.corda.testing.services.MockAttachmentStorage +import net.corda.testing.services.MockCordappProvider import org.bouncycastle.operator.ContentSigner import rx.Observable import rx.subjects.PublishSubject @@ -67,7 +69,7 @@ open class MockServices private constructor( override val validatedTransactions: WritableTransactionStorage, override val identityService: IdentityServiceInternal, private val initialIdentityName: CordaX500Name, - vararg val keys: KeyPair + val keys: Array ) : ServiceHub, StateLoader by validatedTransactions { companion object { @JvmStatic @@ -157,7 +159,7 @@ open class MockServices private constructor( val schemaService = NodeSchemaService(cordappLoader.cordappSchemas) val database = configureDatabase(dataSourceProps, makeTestDatabaseProperties(initialIdentityName.organisation), identityService, schemaService) val mockService = database.transaction { - object : MockServices(cordappLoader, identityService, initialIdentityName, *(keys.toTypedArray())) { + object : MockServices(cordappLoader, identityService, initialIdentityName, keys.toTypedArray()) { override val vaultService: VaultServiceInternal = makeVaultService(database.hibernateConfig, schemaService) override fun recordTransactions(statesToRecord: StatesToRecord, txs: Iterable) { @@ -173,8 +175,9 @@ open class MockServices private constructor( } } - private constructor(cordappLoader: CordappLoader, identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name, vararg keys: KeyPair) : this(cordappLoader, MockTransactionStorage(), identityService, initialIdentityName, *keys) - constructor(cordappPackages: List, identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name, vararg keys: KeyPair) : this(CordappLoader.createWithTestPackages(cordappPackages), identityService, initialIdentityName, *keys) + private constructor(cordappLoader: CordappLoader, identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name, keys: Array) : this(cordappLoader, MockTransactionStorage(), identityService, initialIdentityName, keys) + constructor(cordappPackages: List, identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name, vararg keys: KeyPair) : this(CordappLoader.createWithTestPackages(cordappPackages), identityService, initialIdentityName, keys) + constructor(cordappPackages: List, identityService: IdentityServiceInternal, initialIdentity: TestIdentity, vararg moreKeys: KeyPair) : this(CordappLoader.createWithTestPackages(cordappPackages), identityService, initialIdentity.name, arrayOf(initialIdentity.key) + moreKeys) constructor(identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name, vararg keys: KeyPair) : this(emptyList(), identityService, initialIdentityName, *keys) constructor(identityService: IdentityServiceInternal, initialIdentityName: CordaX500Name) : this(identityService, initialIdentityName, generateKeyPair()) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeTestUtils.kt similarity index 98% rename from testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeTestUtils.kt index b964655a52..fcb923affd 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeTestUtils.kt @@ -1,6 +1,6 @@ @file:JvmName("NodeTestUtils") -package net.corda.testing +package net.corda.testing.node import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever @@ -19,6 +19,7 @@ import net.corda.core.utilities.seconds import net.corda.node.services.api.StartedNodeServices import net.corda.node.services.config.* import net.corda.nodeapi.internal.config.User +import net.corda.testing.* import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import net.corda.testing.node.makeTestIdentityService import net.corda.testing.node.MockServices.Companion.makeTestDatabaseProperties diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt similarity index 99% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/DriverDSLImpl.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index 09ad8aa7ac..fb92e5b085 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import com.google.common.collect.HashMultimap import com.google.common.util.concurrent.ThreadFactoryBuilder @@ -42,16 +42,14 @@ import net.corda.nodeapi.internal.crypto.X509Utilities import net.corda.nodeapi.internal.crypto.addOrReplaceCertificate import net.corda.nodeapi.internal.crypto.loadOrCreateKeyStore import net.corda.nodeapi.internal.crypto.save -import net.corda.testing.ALICE -import net.corda.testing.BOB -import net.corda.testing.DUMMY_BANK_A import net.corda.testing.common.internal.testNetworkParameters +import net.corda.testing.* import net.corda.testing.driver.* -import net.corda.testing.internal.DriverDSLImpl.ClusterType.NON_VALIDATING_RAFT -import net.corda.testing.internal.DriverDSLImpl.ClusterType.VALIDATING_RAFT import net.corda.testing.node.ClusterSpec import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO import net.corda.testing.node.NotarySpec +import net.corda.testing.node.internal.DriverDSLImpl.ClusterType.NON_VALIDATING_RAFT +import net.corda.testing.node.internal.DriverDSLImpl.ClusterType.VALIDATING_RAFT import net.corda.testing.setGlobalSerialization import okhttp3.OkHttpClient import okhttp3.Request @@ -585,13 +583,7 @@ class DriverDSLImpl( internal val log = contextLogger() private val defaultRpcUserList = listOf(User("default", "default", setOf("ALL")).toConfig().root().unwrapped()) - - private val names = arrayOf( - ALICE.name, - BOB.name, - DUMMY_BANK_A.name - ) - + private val names = arrayOf(ALICE_NAME, BOB_NAME, DUMMY_BANK_A_NAME) /** * A sub-set of permissions that grant most of the essential operations used in the unit/integration tests as well as * in demo application like NodeExplorer. diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/InternalTestUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt similarity index 98% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/InternalTestUtils.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt index b24db80a3f..7a5bfc4f71 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/InternalTestUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import net.corda.core.CordaException import net.corda.core.concurrent.CordaFuture diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/NodeBasedTest.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt similarity index 98% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/NodeBasedTest.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt index 4d62b97c39..ba69cbdc3f 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/NodeBasedTest.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import net.corda.core.identity.CordaX500Name import net.corda.core.internal.concurrent.fork @@ -18,6 +18,7 @@ import net.corda.testing.IntegrationTest import net.corda.testing.SerializationEnvironmentRule import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.getFreeLocalPorts +import net.corda.testing.internal.testThreadFactory import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO import org.apache.logging.log4j.Level import org.junit.After diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/ProcessUtilities.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ProcessUtilities.kt similarity index 98% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/ProcessUtilities.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ProcessUtilities.kt index 4c30aaeae6..f8d4a01f98 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/ProcessUtilities.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ProcessUtilities.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import net.corda.core.internal.div import net.corda.core.internal.exists diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/RPCDriver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt similarity index 99% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/RPCDriver.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt index 9684db5450..f851d7fb8d 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/RPCDriver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import net.corda.client.mock.Generator import net.corda.client.rpc.internal.KryoClientSerializationScheme diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/ShutdownManager.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ShutdownManager.kt similarity index 98% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/ShutdownManager.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ShutdownManager.kt index 022569b958..57114425f6 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/ShutdownManager.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/ShutdownManager.kt @@ -1,4 +1,4 @@ -package net.corda.testing.internal +package net.corda.testing.node.internal import net.corda.core.concurrent.CordaFuture import net.corda.core.internal.ThreadBox diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/CordformUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/CordformUtils.kt similarity index 93% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/CordformUtils.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/CordformUtils.kt index 9e566a0867..25ab1bed6b 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/CordformUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/CordformUtils.kt @@ -1,6 +1,6 @@ @file:JvmName("CordformUtils") -package net.corda.testing.internal.demorun +package net.corda.testing.node.internal.demorun import net.corda.cordform.CordformDefinition import net.corda.cordform.CordformNode diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/DemoRunner.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/DemoRunner.kt similarity index 93% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/DemoRunner.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/DemoRunner.kt index a13badccd4..185a851e99 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/demorun/DemoRunner.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/demorun/DemoRunner.kt @@ -1,6 +1,6 @@ @file:JvmName("DemoRunner") -package net.corda.testing.internal.demorun +package net.corda.testing.node.internal.demorun import net.corda.cordform.CordformDefinition import net.corda.cordform.CordformNode @@ -8,7 +8,7 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.testing.driver.JmxPolicy import net.corda.testing.driver.PortAllocation -import net.corda.testing.internal.internalDriver +import net.corda.testing.node.internal.internalDriver fun CordformDefinition.clean() { System.err.println("Deleting: $nodesDirectory") @@ -40,7 +40,7 @@ private fun CordformDefinition.runNodes(waitForAllNodesToFinish: Boolean, block: .max()!! internalDriver( isDebug = true, - jmxPolicy = JmxPolicy(true), + jmxPolicy = JmxPolicy(true), driverDirectory = nodesDirectory, extraCordappPackagesToScan = cordappPackages, // Notaries are manually specified in Cordform so we don't want the driver automatically starting any diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Injectors.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Injectors.kt similarity index 95% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Injectors.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Injectors.kt index b4b0f9f33d..0e73bbf070 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Injectors.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Injectors.kt @@ -1,9 +1,10 @@ -package net.corda.testing.internal.performance +package net.corda.testing.node.internal.performance import com.codahale.metrics.Gauge import com.codahale.metrics.MetricRegistry import com.google.common.base.Stopwatch -import net.corda.testing.internal.ShutdownManager +import net.corda.testing.internal.performance.Rate +import net.corda.testing.node.internal.ShutdownManager import java.time.Duration import java.util.* import java.util.concurrent.CountDownLatch diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Reporter.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Reporter.kt similarity index 92% rename from testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Reporter.kt rename to testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Reporter.kt index 5446165087..00efdb38bf 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/internal/performance/Reporter.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/performance/Reporter.kt @@ -1,9 +1,9 @@ -package net.corda.testing.internal.performance +package net.corda.testing.node.internal.performance import com.codahale.metrics.ConsoleReporter import com.codahale.metrics.JmxReporter import com.codahale.metrics.MetricRegistry -import net.corda.testing.internal.ShutdownManager +import net.corda.testing.node.internal.ShutdownManager import java.util.concurrent.TimeUnit import javax.management.ObjectName import kotlin.concurrent.thread diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt index a6dc7f1c09..5b58e65086 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt @@ -6,6 +6,7 @@ package net.corda.testing import net.corda.core.contracts.StateRef import net.corda.core.crypto.Crypto import net.corda.core.crypto.SecureHash +import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party @@ -14,7 +15,6 @@ import net.corda.core.internal.cert import net.corda.core.internal.x500Name import net.corda.core.node.NodeInfo import net.corda.core.utilities.NetworkHostAndPort -import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.loggerFor import net.corda.node.services.config.configureDevKeyAndTrustStores import net.corda.nodeapi.internal.config.SSLConfiguration @@ -30,8 +30,8 @@ import org.bouncycastle.cert.X509CertificateHolder import org.mockito.Mockito.mock import org.mockito.internal.stubbing.answers.ThrowsException import java.lang.reflect.Modifier +import java.math.BigInteger import java.nio.file.Files -import java.security.KeyPair import java.security.PublicKey import java.util.* import java.util.concurrent.atomic.AtomicInteger @@ -54,40 +54,6 @@ import java.util.concurrent.atomic.AtomicInteger * - The Int.DOLLARS syntax doesn't work from Java. Use the DOLLARS(int) function instead. */ -// TODO: Refactor these dummies to work with the new identities framework. - -// A few dummy values for testing. -val MEGA_CORP_KEY: KeyPair by lazy { generateKeyPair() } -val MEGA_CORP_PUBKEY: PublicKey get() = MEGA_CORP_KEY.public - -val MINI_CORP_KEY: KeyPair by lazy { generateKeyPair() } -val MINI_CORP_PUBKEY: PublicKey get() = MINI_CORP_KEY.public - -val ORACLE_KEY: KeyPair by lazy { generateKeyPair() } -val ORACLE_PUBKEY: PublicKey get() = ORACLE_KEY.public - -val ALICE_PUBKEY: PublicKey get() = ALICE_KEY.public -val BOB_PUBKEY: PublicKey get() = BOB_KEY.public -val MEGA_CORP_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(CordaX500Name(organisation = "MegaCorp", locality = "London", country = "GB"), MEGA_CORP_PUBKEY) -val MEGA_CORP: Party get() = MEGA_CORP_IDENTITY.party -val MINI_CORP_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(CordaX500Name(organisation = "MiniCorp", locality = "London", country = "GB"), MINI_CORP_PUBKEY) -val MINI_CORP: Party get() = MINI_CORP_IDENTITY.party - -val BOC_NAME: CordaX500Name = CordaX500Name(organisation = "BankOfCorda", locality = "London", country = "GB") -val BOC_KEY: KeyPair by lazy { generateKeyPair() } -val BOC_PUBKEY: PublicKey get() = BOC_KEY.public -val BOC_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(BOC_NAME, BOC_PUBKEY) -val BOC: Party get() = BOC_IDENTITY.party - -val BIG_CORP_KEY: KeyPair by lazy { generateKeyPair() } -val BIG_CORP_PUBKEY: PublicKey get() = BIG_CORP_KEY.public -val BIG_CORP_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(CordaX500Name(organisation = "BigCorporation", locality = "New York", country = "US"), BIG_CORP_PUBKEY) -val BIG_CORP: Party get() = BIG_CORP_IDENTITY.party -val BIG_CORP_PARTY_REF = BIG_CORP.ref(OpaqueBytes.of(1)).reference - -val ALL_TEST_KEYS: List get() = listOf(MEGA_CORP_KEY, MINI_CORP_KEY, ALICE_KEY, BOB_KEY, DUMMY_NOTARY_KEY) -val MOCK_HOST_AND_PORT = NetworkHostAndPort("mockHost", 30000) - fun generateStateRef() = StateRef(SecureHash.randomSHA256(), 0) private val freePortCounter = AtomicInteger(30000) @@ -118,8 +84,7 @@ fun getFreeLocalPorts(hostName: String, numberToAlloc: Int): List T.kryoSpecific(reason: String, function: () -> Unit) = if (!AMQP_ENABLED) { function() diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt index 5e671729d8..fc4ee20cd4 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt @@ -4,66 +4,24 @@ package net.corda.testing import net.corda.core.contracts.Command import net.corda.core.contracts.TypeOnlyCommandData -import net.corda.core.crypto.Crypto -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.CordaX500Name -import net.corda.core.identity.Party -import net.corda.core.identity.PartyAndCertificate import net.corda.core.internal.toX509CertHolder -import net.corda.core.internal.x500Name import net.corda.nodeapi.internal.crypto.* -import org.bouncycastle.asn1.x509.GeneralName -import org.bouncycastle.asn1.x509.GeneralSubtree -import org.bouncycastle.asn1.x509.NameConstraints import org.bouncycastle.cert.X509CertificateHolder -import java.math.BigInteger -import java.security.KeyPair import java.security.PublicKey -import java.security.Security import java.time.Instant // A dummy time at which we will be pretending test transactions are created. val TEST_TX_TIME: Instant get() = Instant.parse("2015-04-17T12:00:00.00Z") -val DUMMY_NOTARY_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(20)) } -/** Dummy notary identity for tests and simulations */ -val DUMMY_NOTARY_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(DUMMY_NOTARY) -val DUMMY_NOTARY: Party get() = Party(CordaX500Name(organisation = "Notary Service", locality = "Zurich", country = "CH"), DUMMY_NOTARY_KEY.public) - -val DUMMY_BANK_A_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(40)) } -/** Dummy bank identity for tests and simulations */ -val DUMMY_BANK_A: Party get() = Party(CordaX500Name(organisation = "Bank A", locality = "London", country = "GB"), DUMMY_BANK_A_KEY.public) - -val DUMMY_BANK_B_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(50)) } -/** Dummy bank identity for tests and simulations */ -val DUMMY_BANK_B: Party get() = Party(CordaX500Name(organisation = "Bank B", locality = "New York", country = "US"), DUMMY_BANK_B_KEY.public) - -val DUMMY_BANK_C_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(60)) } -/** Dummy bank identity for tests and simulations */ -val DUMMY_BANK_C: Party get() = Party(CordaX500Name(organisation = "Bank C", locality = "Tokyo", country = "JP"), DUMMY_BANK_C_KEY.public) - -val ALICE_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(70)) } -/** Dummy individual identity for tests and simulations */ -val ALICE_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(ALICE) -val ALICE_NAME = CordaX500Name(organisation = "Alice Corp", locality = "Madrid", country = "ES") -val ALICE: Party get() = Party(ALICE_NAME, ALICE_KEY.public) - -val BOB_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(80)) } -/** Dummy individual identity for tests and simulations */ -val BOB_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(BOB) -val BOB_NAME = CordaX500Name(organisation = "Bob Plc", locality = "Rome", country = "IT") -val BOB: Party get() = Party(BOB_NAME, BOB_KEY.public) - -val CHARLIE_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(90)) } -/** Dummy individual identity for tests and simulations */ -val CHARLIE_IDENTITY: PartyAndCertificate get() = getTestPartyAndCertificate(CHARLIE) -val CHARLIE_NAME = CordaX500Name(organisation = "Charlie Ltd", locality = "Athens", country = "GR") -val CHARLIE: Party get() = Party(CHARLIE_NAME, CHARLIE_KEY.public) - -val DUMMY_REGULATOR_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(100)) } -/** Dummy regulator for tests and simulations */ -val DUMMY_REGULATOR: Party get() = Party(CordaX500Name(organisation = "Regulator A", locality = "Paris", country = "FR"), DUMMY_REGULATOR_KEY.public) - +val DUMMY_NOTARY_NAME = CordaX500Name("Notary Service", "Zurich", "CH") +val DUMMY_BANK_A_NAME = CordaX500Name("Bank A", "London", "GB") +val DUMMY_BANK_B_NAME = CordaX500Name("Bank B", "New York", "US") +val DUMMY_BANK_C_NAME = CordaX500Name("Bank C", "Tokyo", "JP") +val BOC_NAME = CordaX500Name("BankOfCorda", "London", "GB") +val ALICE_NAME = CordaX500Name("Alice Corp", "Madrid", "ES") +val BOB_NAME = CordaX500Name("Bob Plc", "Rome", "IT") +val CHARLIE_NAME = CordaX500Name("Charlie Ltd", "Athens", "GR") val DEV_CA: CertificateAndKeyPair by lazy { // TODO: Should be identity scheme val caKeyStore = loadKeyStore(ClassLoader.getSystemResourceAsStream("certificates/cordadevcakeys.jks"), "cordacadevpass") diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/TestDSL.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/TestDSL.kt index cf32668002..1fa551c6a1 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/TestDSL.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/TestDSL.kt @@ -13,10 +13,9 @@ import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.WireTransaction import net.corda.testing.contracts.DummyContract -import net.corda.testing.node.MockAttachmentStorage -import net.corda.testing.node.MockCordappProvider +import net.corda.testing.services.MockAttachmentStorage +import net.corda.testing.services.MockCordappProvider import java.io.InputStream -import java.security.KeyPair import java.security.PublicKey import java.util.* import kotlin.collections.component1 @@ -226,7 +225,7 @@ data class TestLedgerDSLInterpreter private constructor( dsl: TestTransactionDSLInterpreter.() -> R, transactionMap: HashMap = HashMap(), /** If set to true, will add dummy components to [transactionBuilder] to make it valid. */ - fillTransaction: Boolean = false + fillTransaction: Boolean ): WireTransaction { val transactionLocation = getCallerLocation() val transactionInterpreter = interpretTransactionDsl(transactionBuilder, dsl) @@ -255,22 +254,19 @@ data class TestLedgerDSLInterpreter private constructor( */ private fun fillTransaction(transactionBuilder: TransactionBuilder) { if (transactionBuilder.commands().isEmpty()) transactionBuilder.addCommand(dummyCommand()) - if (transactionBuilder.inputStates().isEmpty() && transactionBuilder.outputStates().isEmpty()) { - transactionBuilder.addOutputState(DummyContract.SingleOwnerState(owner = ALICE), DummyContract.PROGRAM_ID) - } } override fun _transaction( transactionLabel: String?, transactionBuilder: TransactionBuilder, dsl: TestTransactionDSLInterpreter.() -> EnforceVerifyOrFail - ) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, transactionWithLocations) + ) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, transactionWithLocations, false) override fun _unverifiedTransaction( transactionLabel: String?, transactionBuilder: TransactionBuilder, dsl: TestTransactionDSLInterpreter.() -> Unit - ) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations, fillTransaction = true) + ) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations, true) override fun _tweak(dsl: LedgerDSLInterpreter.() -> Unit) = copy().dsl() @@ -318,40 +314,3 @@ data class TestLedgerDSLInterpreter private constructor( val transactionsToVerify: List get() = transactionWithLocations.values.map { it.transaction } val transactionsUnverified: List get() = nonVerifiedTransactionWithLocations.values.map { it.transaction } } - -/** - * Expands all [CompositeKey]s present in PublicKey iterable to set of single [PublicKey]s. - * If an element of the set is a single PublicKey it gives just that key, if it is a [CompositeKey] it returns all leaf - * keys for that composite element. - */ -val Iterable.expandedCompositeKeys: Set - get() = flatMap { it.keys }.toSet() - -/** - * Signs all transactions passed in. - * @param transactionsToSign Transactions to be signed. - * @param extraKeys extra keys to sign transactions with. - * @return List of [SignedTransaction]s. - */ -fun signAll(transactionsToSign: List, extraKeys: List) = transactionsToSign.map { wtx -> - check(wtx.requiredSigningKeys.isNotEmpty()) - val signatures = ArrayList() - val keyLookup = HashMap() - - (ALL_TEST_KEYS + extraKeys).forEach { - keyLookup[it.public] = it - } - wtx.requiredSigningKeys.expandedCompositeKeys.forEach { - val key = keyLookup[it] ?: throw IllegalArgumentException("Missing required key for ${it.toStringShort()}") - signatures += key.sign(SignableData(wtx.id, SignatureMetadata(1, Crypto.findSignatureScheme(it).schemeNumberID))) - } - SignedTransaction(wtx, signatures) -} - -/** - * Signs all transactions in the ledger. - * @param extraKeys extra keys to sign transactions with. - * @return List of [SignedTransaction]s. - */ -fun LedgerDSL.signAll( - vararg extraKeys: KeyPair) = signAll(this.interpreter.wireTransactions, extraKeys.toList()) diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt index 8919966f12..0412ddf2f7 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt @@ -101,7 +101,7 @@ class TransactionDSL(interpreter: T, private */ fun input(contractClassName: ContractClassName, state: ContractState) { val transaction = ledgerInterpreter._unverifiedTransaction(null, TransactionBuilder(notary)) { - output(contractClassName, null, DUMMY_NOTARY, null, AlwaysAcceptAttachmentConstraint, state) + output(contractClassName, null, notary, null, AlwaysAcceptAttachmentConstraint, state) } input(transaction.outRef(0).ref) } diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt index b16ca113fb..e303cba51f 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt @@ -18,11 +18,7 @@ import net.corda.finance.contracts.Commodity import net.corda.finance.contracts.DealState import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.CommodityContract -import net.corda.testing.chooseIdentity -import net.corda.testing.chooseIdentityAndCert -import net.corda.testing.dummyCommand -import net.corda.testing.singleIdentity -import java.security.KeyPair +import net.corda.testing.* import java.security.PublicKey import java.time.Duration import java.time.Instant @@ -37,9 +33,8 @@ import java.util.* */ class VaultFiller @JvmOverloads constructor( private val services: ServiceHub, - private val defaultNotary: Party, - private val defaultNotaryKeyPair: KeyPair, - private val altNotary: Party = defaultNotary, + private val defaultNotary: TestIdentity, + private val altNotary: Party = defaultNotary.party, private val rngFactory: () -> Random = { Random(0L) }) { companion object { fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, rng: Random): LongArray { @@ -71,10 +66,6 @@ class VaultFiller @JvmOverloads constructor( } } - init { - require(defaultNotary.owningKey == defaultNotaryKeyPair.public) { "Default notary public keys must match." } - } - @JvmOverloads fun fillWithSomeTestDeals(dealIds: List, issuerServices: ServiceHub = services, @@ -84,12 +75,12 @@ class VaultFiller @JvmOverloads constructor( val transactions: List = dealIds.map { // Issue a deal state - val dummyIssue = TransactionBuilder(notary = defaultNotary).apply { + val dummyIssue = TransactionBuilder(notary = defaultNotary.party).apply { addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)), DUMMY_DEAL_PROGRAM_ID) addCommand(dummyCommand()) } val stx = issuerServices.signInitialTransaction(dummyIssue) - return@map services.addSignature(stx, defaultNotaryKeyPair.public) + return@map services.addSignature(stx, defaultNotary.pubkey) } services.recordTransactions(transactions) // Get all the StateAndRefs of all the generated transactions. @@ -110,11 +101,11 @@ class VaultFiller @JvmOverloads constructor( linearTimestamp: Instant = now()): Vault { val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val me = AnonymousParty(myKey) - val issuerKey = defaultNotaryKeyPair + val issuerKey = defaultNotary.key val signatureMetadata = SignatureMetadata(services.myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID) val transactions: List = (1..numberToCreate).map { // Issue a Linear state - val dummyIssue = TransactionBuilder(notary = defaultNotary).apply { + val dummyIssue = TransactionBuilder(notary = defaultNotary.party).apply { addOutputState(DummyLinearContract.State( linearId = UniqueIdentifier(externalId), participants = participants.plus(me), diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachment.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachment.kt deleted file mode 100644 index ac717da3e0..0000000000 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachment.kt +++ /dev/null @@ -1,9 +0,0 @@ -package net.corda.testing.node - -import net.corda.core.crypto.SecureHash -import net.corda.core.internal.AbstractAttachment - -/** - * An attachment with only an ID and an empty data array - */ -class MockAttachment(override val id: SecureHash = SecureHash.zeroHash) : AbstractAttachment({ ByteArray(0) }) \ No newline at end of file diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachmentStorage.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/services/MockAttachmentStorage.kt similarity index 98% rename from testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachmentStorage.kt rename to testing/test-utils/src/main/kotlin/net/corda/testing/services/MockAttachmentStorage.kt index c12e202b33..8cf1a9ccf2 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockAttachmentStorage.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/services/MockAttachmentStorage.kt @@ -1,4 +1,4 @@ -package net.corda.testing.node +package net.corda.testing.services import net.corda.core.contracts.Attachment import net.corda.core.crypto.SecureHash diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockCordappProvider.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/services/MockCordappProvider.kt similarity index 98% rename from testing/test-utils/src/main/kotlin/net/corda/testing/node/MockCordappProvider.kt rename to testing/test-utils/src/main/kotlin/net/corda/testing/services/MockCordappProvider.kt index e50f4dea84..dba07b73be 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/node/MockCordappProvider.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/services/MockCordappProvider.kt @@ -1,4 +1,4 @@ -package net.corda.testing.node +package net.corda.testing.services import net.corda.core.contracts.ContractClassName import net.corda.core.cordapp.Cordapp diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt index cede37faac..5fb32aa9e6 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt @@ -204,14 +204,15 @@ class NodeTabView : Fragment() { private fun Pane.nodeNameField() = textfield(model.legalName) { minWidth = textWidth - validator { - if (it == null) { + validator { rawName -> + val normalizedName: String? = rawName?.let(LegalNameValidator::normalize) + if (normalizedName == null) { error("Node name is required") - } else if (nodeController.nameExists(LegalNameValidator.normalize(it))) { + } else if (nodeController.nameExists(normalizedName)) { error("Node with this name already exists") } else { try { - LegalNameValidator.validateOrganization(LegalNameValidator.normalize(it)) + LegalNameValidator.validateOrganization(normalizedName, LegalNameValidator.Validation.MINIMAL) null } catch (e: IllegalArgumentException) { error(e.message) diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt index fa9f56f1d1..edc0a0543e 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt @@ -24,8 +24,8 @@ import net.corda.finance.flows.CashExitFlow.ExitRequest import net.corda.finance.flows.CashIssueAndPaymentFlow.IssueAndPaymentRequest import net.corda.node.services.Permissions.Companion.startFlow import net.corda.nodeapi.internal.config.User -import net.corda.testing.ALICE -import net.corda.testing.BOB +import net.corda.testing.ALICE_NAME +import net.corda.testing.BOB_NAME import net.corda.testing.driver.JmxPolicy import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.PortAllocation @@ -68,8 +68,8 @@ class ExplorerSimulation(private val options: OptionSet) { driver(portAllocation = portAllocation, extraCordappPackagesToScan = listOf("net.corda.finance", IOUFlow::class.java.`package`.name), isDebug = true, waitForAllNodesToFinish = true, jmxPolicy = JmxPolicy(true)) { // TODO : Supported flow should be exposed somehow from the node instead of set of ServiceInfo. - val alice = startNode(providedName = ALICE.name, rpcUsers = listOf(user)) - val bob = startNode(providedName = BOB.name, rpcUsers = listOf(user)) + val alice = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)) + val bob = startNode(providedName = BOB_NAME, rpcUsers = listOf(user)) val ukBankName = CordaX500Name(organisation = "UK Bank Plc", locality = "London", country = "GB") val usaBankName = CordaX500Name(organisation = "USA Bank Corp", locality = "New York", country = "US") val issuerGBP = startNode(providedName = ukBankName, rpcUsers = listOf(manager), diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt index 592f0375a4..d1d500b7a2 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt @@ -1,11 +1,9 @@ package net.corda.loadtest.tests import net.corda.client.mock.Generator -import net.corda.core.crypto.entropyToKeyPair import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FlowException import net.corda.core.identity.CordaX500Name -import net.corda.core.identity.Party import net.corda.core.internal.concurrent.thenMatch import net.corda.core.messaging.startFlow import net.corda.core.transactions.SignedTransaction @@ -16,25 +14,26 @@ import net.corda.testing.contracts.DummyContract import net.corda.testing.node.MockServices import net.corda.testing.node.makeTestIdentityService import org.slf4j.LoggerFactory -import java.math.BigInteger private val log = LoggerFactory.getLogger("NotaryTest") -private val DUMMY_CASH_ISSUER_KEY = entropyToKeyPair(BigInteger.valueOf(10)) -private val DUMMY_CASH_ISSUER_IDENTITY = getTestPartyAndCertificate(Party(CordaX500Name("Snake Oil Issuer", "London", "GB"), DUMMY_CASH_ISSUER_KEY.public)) -private val DUMMY_CASH_ISSUER = DUMMY_CASH_ISSUER_IDENTITY.party.ref(1) +private val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10) +private val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1) +private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) +private val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB")) +private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) data class NotariseCommand(val issueTx: SignedTransaction, val moveTx: SignedTransaction, val node: NodeConnection) val dummyNotarisationTest = LoadTest( "Notarising dummy transactions", generate = { _, _ -> - val issuerServices = MockServices(makeTestIdentityService(listOf(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, DUMMY_CASH_ISSUER_IDENTITY, DUMMY_NOTARY_IDENTITY)), MEGA_CORP.name, DUMMY_CASH_ISSUER_KEY) + val issuerServices = MockServices(makeTestIdentityService(listOf(megaCorp.identity, miniCorp.identity, dummyCashIssuer.identity, dummyNotary.identity)), megaCorp.name, dummyCashIssuer.key) val generateTx = Generator.pickOne(simpleNodes).flatMap { node -> Generator.int().map { val issueBuilder = DummyContract.generateInitial(it, notary.info.legalIdentities[0], DUMMY_CASH_ISSUER) // TODO notary choice val issueTx = issuerServices.signInitialTransaction(issueBuilder) val asset = issueTx.tx.outRef(0) - val moveBuilder = DummyContract.move(asset, DUMMY_CASH_ISSUER.party) + val moveBuilder = DummyContract.move(asset, dummyCashIssuer.party) val moveTx = issuerServices.signInitialTransaction(moveBuilder) NotariseCommand(issueTx, moveTx, node) } diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierDriver.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierDriver.kt index 4fa35ff2b9..791df21211 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierDriver.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierDriver.kt @@ -26,8 +26,8 @@ import net.corda.testing.driver.JmxPolicy import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver -import net.corda.testing.internal.* import net.corda.testing.node.NotarySpec +import net.corda.testing.node.internal.* import org.apache.activemq.artemis.api.core.SimpleString import org.apache.activemq.artemis.api.core.client.ActiveMQClient import org.apache.activemq.artemis.api.core.client.ClientProducer diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt index 60ad59b5ea..737d7a1bed 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt @@ -46,7 +46,7 @@ class VerifierTests : IntegrationTest() { @Test fun `single verifier works with requestor`() { verifierDriver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) { - val aliceFuture = startVerificationRequestor(ALICE.name) + val aliceFuture = startVerificationRequestor(ALICE_NAME) val transactions = generateTransactions(100) val alice = aliceFuture.get() startVerifier(alice) @@ -63,7 +63,7 @@ class VerifierTests : IntegrationTest() { @Test fun `single verification fails`() { verifierDriver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) { - val aliceFuture = startVerificationRequestor(ALICE.name) + val aliceFuture = startVerificationRequestor(ALICE_NAME) // Generate transactions as per usual, but then remove attachments making transaction invalid. val transactions = generateTransactions(1).map { it.copy(attachments = emptyList()) } val alice = aliceFuture.get() @@ -78,7 +78,7 @@ class VerifierTests : IntegrationTest() { @Test fun `multiple verifiers work with requestor`() { verifierDriver { - val aliceFuture = startVerificationRequestor(ALICE.name) + val aliceFuture = startVerificationRequestor(ALICE_NAME) val transactions = generateTransactions(100) val alice = aliceFuture.get() val numberOfVerifiers = 4 @@ -98,7 +98,7 @@ class VerifierTests : IntegrationTest() { @Test fun `verification redistributes on verifier death`() { verifierDriver { - val aliceFuture = startVerificationRequestor(ALICE.name) + val aliceFuture = startVerificationRequestor(ALICE_NAME) val numberOfTransactions = 100 val transactions = generateTransactions(numberOfTransactions) val alice = aliceFuture.get() @@ -126,7 +126,7 @@ class VerifierTests : IntegrationTest() { @Test fun `verification request waits until verifier comes online`() { verifierDriver { - val aliceFuture = startVerificationRequestor(ALICE.name) + val aliceFuture = startVerificationRequestor(ALICE_NAME) val transactions = generateTransactions(100) val alice = aliceFuture.get() val futures = transactions.map { alice.verifyTransaction(it) } @@ -139,9 +139,9 @@ class VerifierTests : IntegrationTest() { fun `single verifier works with a node`() { verifierDriver( extraCordappPackagesToScan = listOf("net.corda.finance.contracts"), - notarySpecs = listOf(NotarySpec(DUMMY_NOTARY.name, verifierType = VerifierType.OutOfProcess)) + notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, verifierType = VerifierType.OutOfProcess)) ) { - val aliceNode = startNode(providedName = ALICE.name).getOrThrow() + val aliceNode = startNode(providedName = ALICE_NAME).getOrThrow() val notaryNode = defaultNotaryNode.getOrThrow() val alice = aliceNode.rpc.wellKnownPartyFromX500Name(ALICE_NAME)!! startVerifier(notaryNode) diff --git a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt index 1af27a5759..db797db7df 100644 --- a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt +++ b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt @@ -3,9 +3,10 @@ package net.corda.webserver import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.testing.* +import net.corda.testing.DUMMY_BANK_A_NAME import net.corda.testing.driver.WebserverHandle -import net.corda.testing.internal.addressMustBeBound -import net.corda.testing.internal.addressMustNotBeBound +import net.corda.testing.node.internal.addressMustBeBound +import net.corda.testing.node.internal.addressMustNotBeBound import net.corda.testing.driver.driver import org.junit.ClassRule import org.junit.Test @@ -31,7 +32,7 @@ class WebserverDriverTests : IntegrationTest() { @Test fun `starting a node and independent web server works`() { val addr = driver { - val node = startNode(providedName = DUMMY_BANK_A.name).getOrThrow() + val node = startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow() val webserverHandle = startWebserver(node).getOrThrow() webserverMustBeUp(webserverHandle) webserverHandle.listenAddress