mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
ENT-4494 split nodeapi tests (#6024)
* Split out node-api tests that require test-utils/node-driver * Add node-api test artefacts to publication list. * Make test-common a transient dependency - downstream tests assume that it's available. * Switch dependencies to java-library * Fix magic package name for cordapp scanning in test
This commit is contained in:
parent
e639091626
commit
9a406839fa
19
node-api-tests/build.gradle
Normal file
19
node-api-tests/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
description 'NodeAPI tests that require node etc'
|
||||
|
||||
dependencies {
|
||||
testCompile project(":node-api")
|
||||
testCompile project(path: ':node-api', configuration:'testArtifacts')
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
|
||||
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
|
||||
testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
|
||||
// Unit testing helpers.
|
||||
testCompile "org.assertj:assertj-core:$assertj_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
testCompile project(':node-driver')
|
||||
testCompile project(':test-utils')
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.corda.nodeapi.internal
|
||||
package net.corda.nodeapitests.internal
|
||||
|
||||
import com.nhaarman.mockito_kotlin.any
|
||||
import com.nhaarman.mockito_kotlin.doReturn
|
||||
@ -19,7 +19,7 @@ import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.nodeapi.internal.cordapp.CordappLoader
|
||||
import net.corda.node.internal.cordapp.CordappProviderImpl
|
||||
import net.corda.node.internal.cordapp.JarScanningCordappLoader
|
||||
import net.corda.nodeapi.internal.AttachmentsClassLoaderStaticContractTests.AttachmentDummyContract.Companion.ATTACHMENT_PROGRAM_ID
|
||||
import net.corda.nodeapitests.internal.AttachmentsClassLoaderStaticContractTests.AttachmentDummyContract.Companion.ATTACHMENT_PROGRAM_ID
|
||||
import net.corda.testing.common.internal.testNetworkParameters
|
||||
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
@ -45,7 +45,7 @@ class AttachmentsClassLoaderStaticContractTests {
|
||||
|
||||
class AttachmentDummyContract : Contract {
|
||||
companion object {
|
||||
const val ATTACHMENT_PROGRAM_ID = "net.corda.nodeapi.internal.AttachmentsClassLoaderStaticContractTests\$AttachmentDummyContract"
|
||||
const val ATTACHMENT_PROGRAM_ID = "net.corda.nodeapitests.internal.AttachmentsClassLoaderStaticContractTests\$AttachmentDummyContract"
|
||||
}
|
||||
|
||||
data class State(val magicNumber: Int = 0) : ContractState {
|
||||
@ -75,7 +75,7 @@ class AttachmentsClassLoaderStaticContractTests {
|
||||
}
|
||||
|
||||
private val serviceHub get() = rigorousMock<ServicesForResolution>().also {
|
||||
val cordappProviderImpl = CordappProviderImpl(cordappLoaderForPackages(listOf("net.corda.nodeapi.internal")), MockCordappConfigProvider(), MockAttachmentStorage())
|
||||
val cordappProviderImpl = CordappProviderImpl(cordappLoaderForPackages(listOf("net.corda.nodeapitests.internal")), MockCordappConfigProvider(), MockAttachmentStorage())
|
||||
cordappProviderImpl.start()
|
||||
doReturn(cordappProviderImpl).whenever(it).cordappProvider
|
||||
doReturn(networkParametersService).whenever(it).networkParametersService
|
||||
@ -95,7 +95,8 @@ class AttachmentsClassLoaderStaticContractTests {
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `test serialization of WireTransaction with statically loaded contract`() {
|
||||
val tx = AttachmentDummyContract().generateInitial(MEGA_CORP.ref(0), 42, DUMMY_NOTARY)
|
||||
val tx = AttachmentDummyContract()
|
||||
.generateInitial(MEGA_CORP.ref(0), 42, DUMMY_NOTARY)
|
||||
val wireTransaction = tx.toWireTransaction(serviceHub)
|
||||
val bytes = wireTransaction.serialize()
|
||||
val copiedWireTransaction = bytes.deserialize()
|
@ -1,4 +1,4 @@
|
||||
package net.corda.nodeapi.internal
|
||||
package net.corda.nodeapitests.internal
|
||||
|
||||
import net.corda.node.services.schema.NodeSchemaService
|
||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
@ -1,4 +1,4 @@
|
||||
package net.corda.nodeapi.internal.crypto
|
||||
package net.corda.nodeapitests.internal.crypto
|
||||
|
||||
|
||||
import io.netty.handler.ssl.ClientAuth
|
||||
@ -42,6 +42,14 @@ import net.corda.coretesting.internal.NettyTestHandler
|
||||
import net.corda.coretesting.internal.NettyTestServer
|
||||
import net.corda.testing.internal.createDevIntermediateCaCertPath
|
||||
import net.corda.coretesting.internal.stubs.CertificateStoreStubs
|
||||
import net.corda.nodeapi.internal.crypto.CertificateType
|
||||
import net.corda.nodeapi.internal.crypto.X509Utilities
|
||||
import net.corda.nodeapi.internal.crypto.checkValidity
|
||||
import net.corda.nodeapi.internal.crypto.getSupportedKey
|
||||
import net.corda.nodeapi.internal.crypto.loadOrCreateKeyStore
|
||||
import net.corda.nodeapi.internal.crypto.save
|
||||
import net.corda.nodeapi.internal.crypto.toBc
|
||||
import net.corda.nodeapi.internal.crypto.x509
|
||||
import net.i2p.crypto.eddsa.EdDSAPrivateKey
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.bouncycastle.asn1.x509.*
|
@ -1,4 +1,4 @@
|
||||
package net.corda.nodeapi.internal.network
|
||||
package net.corda.nodeapitests.internal.network
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.corda.core.crypto.secureRandomBytes
|
||||
@ -24,6 +24,14 @@ import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
import net.corda.testing.core.TestIdentity
|
||||
import net.corda.coretesting.internal.createNodeInfoAndSigned
|
||||
import net.corda.nodeapi.internal.network.CopyCordapps
|
||||
import net.corda.nodeapi.internal.network.NETWORK_PARAMS_FILE_NAME
|
||||
import net.corda.nodeapi.internal.network.NetworkBootstrapper
|
||||
import net.corda.nodeapi.internal.network.NetworkParametersOverrides
|
||||
import net.corda.nodeapi.internal.network.PackageOwner
|
||||
import net.corda.nodeapi.internal.network.SignedNetworkParameters
|
||||
import net.corda.nodeapi.internal.network.TestContractsJar
|
||||
import net.corda.nodeapi.internal.network.verifiedNetworkParametersCert
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.After
|
||||
@ -72,7 +80,9 @@ class NetworkBootstrapperTest {
|
||||
|
||||
private val bootstrapper = NetworkBootstrapper(
|
||||
initSerEnv = false,
|
||||
embeddedCordaJar = { fakeEmbeddedCordaJar.toUri().toURL() },
|
||||
embeddedCordaJar = {
|
||||
fakeEmbeddedCordaJar.toUri().toURL()
|
||||
},
|
||||
nodeInfosGenerator = { nodeDirs ->
|
||||
nodeDirs.map { nodeDir ->
|
||||
val name = nodeDir.fakeNodeConfig.myLegalName
|
@ -1,7 +1,10 @@
|
||||
package net.corda.nodeapi.internal.persistence
|
||||
package net.corda.nodeapitests.internal.persistence
|
||||
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
import net.corda.core.schemas.PersistentState
|
||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
||||
import net.corda.nodeapi.internal.persistence.MissingMigrationException
|
||||
import net.corda.nodeapi.internal.persistence.SchemaMigration
|
||||
import net.corda.node.internal.DataSourceFactory
|
||||
import net.corda.node.services.persistence.DBCheckpointStorage
|
||||
import net.corda.node.services.schema.NodeSchemaService
|
@ -0,0 +1,65 @@
|
||||
package net.corda.nodeapitests.internal.serialization.kryo
|
||||
|
||||
import com.nhaarman.mockito_kotlin.doReturn
|
||||
import com.nhaarman.mockito_kotlin.whenever
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.serialization.EncodingWhitelist
|
||||
import net.corda.core.serialization.internal.CheckpointSerializationContext
|
||||
import net.corda.core.serialization.internal.checkpointDeserialize
|
||||
import net.corda.core.serialization.internal.checkpointSerialize
|
||||
import net.corda.coretesting.internal.rigorousMock
|
||||
import net.corda.node.services.persistence.NodeAttachmentService
|
||||
import net.corda.serialization.internal.AllWhitelist
|
||||
import net.corda.serialization.internal.CheckpointSerializationContextImpl
|
||||
import net.corda.serialization.internal.CordaSerializationEncoding
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import net.corda.testing.core.TestIdentity
|
||||
import net.corda.testing.core.internal.CheckpointSerializationEnvironmentRule
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
import java.io.InputStream
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class KryoAttachmentTest(private val compression: CordaSerializationEncoding?) {
|
||||
companion object {
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
@JvmStatic
|
||||
fun compression() = arrayOf<CordaSerializationEncoding?>(null) + CordaSerializationEncoding.values()
|
||||
}
|
||||
|
||||
|
||||
@get:Rule
|
||||
val serializationRule = CheckpointSerializationEnvironmentRule()
|
||||
private lateinit var context: CheckpointSerializationContext
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
context = CheckpointSerializationContextImpl(
|
||||
javaClass.classLoader,
|
||||
AllWhitelist,
|
||||
emptyMap(),
|
||||
true,
|
||||
compression,
|
||||
rigorousMock<EncodingWhitelist>().also {
|
||||
if (compression != null) doReturn(true).whenever(it).acceptEncoding(compression)
|
||||
})
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `HashCheckingStream (de)serialize`() {
|
||||
val rubbish = ByteArray(12345) { (it * it * 0.12345).toByte() }
|
||||
val readRubbishStream: InputStream = NodeAttachmentService.HashCheckingStream(
|
||||
SecureHash.sha256(rubbish),
|
||||
rubbish.size,
|
||||
rubbish.inputStream()
|
||||
).checkpointSerialize(context).checkpointDeserialize(context)
|
||||
for (i in 0..12344) {
|
||||
Assert.assertEquals(rubbish[i], readRubbishStream.read().toByte())
|
||||
}
|
||||
Assert.assertEquals(-1, readRubbishStream.read())
|
||||
}
|
||||
}
|
@ -54,8 +54,7 @@ dependencies {
|
||||
// Unit testing helpers.
|
||||
testCompile "org.assertj:assertj-core:$assertj_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
testCompile project(':node-driver')
|
||||
testCompile project(':test-utils')
|
||||
testCompile project(':core-test-utils')
|
||||
|
||||
compile ("org.apache.activemq:artemis-amqp-protocol:${artemis_version}") {
|
||||
// Gains our proton-j version from core module.
|
||||
@ -74,6 +73,7 @@ task testJar(type: Jar) {
|
||||
|
||||
artifacts {
|
||||
testArtifacts testJar
|
||||
publish testJar
|
||||
}
|
||||
|
||||
jar {
|
||||
|
@ -54,7 +54,7 @@ import kotlin.streams.toList
|
||||
// TODO Move this to tools:bootstrapper
|
||||
class NetworkBootstrapper
|
||||
@VisibleForTesting
|
||||
internal constructor(private val initSerEnv: Boolean,
|
||||
constructor(private val initSerEnv: Boolean,
|
||||
private val embeddedCordaJar: () -> URL,
|
||||
private val nodeInfosGenerator: (List<Path>) -> List<Path>,
|
||||
private val contractsJarConverter: (Path) -> ContractsJar) : NetworkBootstrapperWithOverridableParameters {
|
||||
|
@ -3,8 +3,8 @@ package net.corda.nodeapi.internal.protonwrapper.netty
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.coretesting.internal.configureTestSSL
|
||||
import net.corda.nodeapi.internal.config.CertificateStore
|
||||
import net.corda.testing.internal.configureTestSSL
|
||||
import org.junit.Test
|
||||
import javax.net.ssl.KeyManagerFactory
|
||||
import javax.net.ssl.SNIHostName
|
||||
|
@ -18,7 +18,6 @@ import net.corda.core.serialization.internal.checkpointSerialize
|
||||
import net.corda.core.utilities.ByteSequence
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
import net.corda.core.utilities.sequence
|
||||
import net.corda.node.services.persistence.NodeAttachmentService
|
||||
import net.corda.serialization.internal.*
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import net.corda.testing.core.TestIdentity
|
||||
@ -198,20 +197,6 @@ class KryoTests(private val compression: CordaSerializationEncoding?) {
|
||||
assertTrue(logger === logger2)
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `HashCheckingStream (de)serialize`() {
|
||||
val rubbish = ByteArray(12345) { (it * it * 0.12345).toByte() }
|
||||
val readRubbishStream: InputStream = NodeAttachmentService.HashCheckingStream(
|
||||
SecureHash.sha256(rubbish),
|
||||
rubbish.size,
|
||||
rubbish.inputStream()
|
||||
).checkpointSerialize(context).checkpointDeserialize(context)
|
||||
for (i in 0..12344) {
|
||||
assertEquals(rubbish[i], readRubbishStream.read().toByte())
|
||||
}
|
||||
assertEquals(-1, readRubbishStream.read())
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
private data class Person(val name: String, val birthday: Instant?)
|
||||
|
||||
|
@ -14,6 +14,7 @@ import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.unwrap
|
||||
import net.corda.coretesting.internal.configureTestSSL
|
||||
import net.corda.node.internal.NodeWithInfo
|
||||
import net.corda.nodeapi.RPCApi
|
||||
import net.corda.nodeapi.internal.ArtemisMessagingComponent.Companion.INTERNAL_PREFIX
|
||||
@ -22,7 +23,6 @@ import net.corda.nodeapi.internal.config.MutualSslConfiguration
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import net.corda.testing.core.BOB_NAME
|
||||
import net.corda.testing.core.singleIdentity
|
||||
import net.corda.testing.internal.configureTestSSL
|
||||
import net.corda.testing.node.User
|
||||
import net.corda.testing.node.internal.NodeBasedTest
|
||||
import net.corda.testing.node.internal.startFlow
|
||||
|
@ -3,9 +3,9 @@ package net.corda.services.messaging
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.serialization.internal.nodeSerializationEnv
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.coretesting.internal.configureTestSSL
|
||||
import net.corda.nodeapi.internal.ArtemisTcpTransport.Companion.p2pConnectorTcpTransport
|
||||
import net.corda.nodeapi.internal.config.MutualSslConfiguration
|
||||
import net.corda.testing.internal.configureTestSSL
|
||||
import org.apache.activemq.artemis.api.core.client.*
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.internal.notary.UniquenessProvider
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.minutes
|
||||
import net.corda.coretesting.internal.configureTestSSL
|
||||
import net.corda.node.services.schema.NodeSchemaService
|
||||
import net.corda.nodeapi.internal.crypto.X509Utilities
|
||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||
@ -29,7 +30,6 @@ import net.corda.testing.core.generateStateRef
|
||||
import net.corda.testing.internal.LogHelper
|
||||
import net.corda.testing.internal.TestingNamedCacheFactory
|
||||
import net.corda.testing.internal.configureDatabase
|
||||
import net.corda.testing.internal.configureTestSSL
|
||||
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
|
||||
import net.corda.testing.node.TestClock
|
||||
import net.corda.testing.node.internal.MockKeyManagementService
|
||||
|
@ -18,6 +18,7 @@ include 'core'
|
||||
include 'core-tests'
|
||||
include 'docs'
|
||||
include 'node-api'
|
||||
include 'node-api-tests'
|
||||
include 'node'
|
||||
include 'node:capsule'
|
||||
include 'node:djvm'
|
||||
|
@ -3,14 +3,15 @@ plugins {
|
||||
id 'net.corda.plugins.publish-utils'
|
||||
id 'net.corda.plugins.api-scanner'
|
||||
id 'com.jfrog.artifactory'
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
description 'Core test types and helpers for testing Corda'
|
||||
|
||||
dependencies {
|
||||
implementation project(':core')
|
||||
implementation project(':test-common')
|
||||
compile "org.jetbrains.kotlin:kotlin-test"
|
||||
api project(':test-common')
|
||||
api "org.jetbrains.kotlin:kotlin-test"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
@ -0,0 +1,21 @@
|
||||
package net.corda.coretesting.internal
|
||||
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.coretesting.internal.stubs.CertificateStoreStubs
|
||||
import net.corda.nodeapi.internal.config.MutualSslConfiguration
|
||||
import net.corda.nodeapi.internal.loadDevCaTrustStore
|
||||
import net.corda.nodeapi.internal.registerDevP2pCertificates
|
||||
import java.nio.file.Files
|
||||
|
||||
fun configureTestSSL(legalName: CordaX500Name): MutualSslConfiguration {
|
||||
|
||||
val certificatesDirectory = Files.createTempDirectory("certs")
|
||||
val config = CertificateStoreStubs.P2P.withCertificatesDirectory(certificatesDirectory)
|
||||
if (config.trustStore.getOptional() == null) {
|
||||
loadDevCaTrustStore().copyTo(config.trustStore.get(true))
|
||||
}
|
||||
if (config.keyStore.getOptional() == null) {
|
||||
config.keyStore.get(true).registerDevP2pCertificates(legalName)
|
||||
}
|
||||
return config
|
||||
}
|
@ -67,19 +67,6 @@ inline fun <reified T : Any> T.amqpSpecific(reason: String, function: () -> Unit
|
||||
loggerFor<T>().info("Ignoring AMQP specific test, reason: $reason")
|
||||
}
|
||||
|
||||
fun configureTestSSL(legalName: CordaX500Name): MutualSslConfiguration {
|
||||
|
||||
val certificatesDirectory = Files.createTempDirectory("certs")
|
||||
val config = CertificateStoreStubs.P2P.withCertificatesDirectory(certificatesDirectory)
|
||||
if (config.trustStore.getOptional() == null) {
|
||||
loadDevCaTrustStore().copyTo(config.trustStore.get(true))
|
||||
}
|
||||
if (config.keyStore.getOptional() == null) {
|
||||
config.keyStore.get(true).registerDevP2pCertificates(legalName)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
private val defaultRootCaName = X500Principal("CN=Corda Root CA,O=R3 Ltd,L=London,C=GB")
|
||||
private val defaultIntermediateCaName = X500Principal("CN=Corda Intermediate CA,O=R3 Ltd,L=London,C=GB")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user