mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-3206: Move serialization tests into separate module to break de… (#5452)
* CORDA-3206: Move serialization tests into separate module to break dependency on `node-driver` (and associated transitive dependencies). Required to complete CORDA-2050: Upgrade Corda to Java 11 (compatibility mode) * Keep all serialization tests in same module UNLESS they require access to `node-driver` (and transitive dependencies of). * Move helper object to internal package. * Gradle build file clean-up and additional README. * Addressing CS PR review comments.
This commit is contained in:
parent
dea00fd107
commit
c096dcab3b
24
serialization-tests/build.gradle
Normal file
24
serialization-tests/build.gradle
Normal file
@ -0,0 +1,24 @@
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
// Any serialization tests that require further Corda dependencies (other than `core`) should be added to this module.
|
||||
description 'Corda serialization tests'
|
||||
|
||||
dependencies {
|
||||
testCompile project(":serialization")
|
||||
testCompile project(path: ':serialization', configuration: 'testArtifacts')
|
||||
testCompile project(':node-driver')
|
||||
|
||||
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}"
|
||||
|
||||
testCompile "org.assertj:assertj-core:$assertj_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
}
|
||||
|
||||
configurations {
|
||||
testArtifacts.extendsFrom testRuntimeClasspath
|
||||
}
|
3
serialization-tests/src/test/README.md
Normal file
3
serialization-tests/src/test/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Adding tests to the Serialization module
|
||||
|
||||
Any serialization tests that require further Corda dependencies (other than `core`) should be added to this module.
|
@ -5,8 +5,10 @@ import net.corda.core.serialization.SerializationContext;
|
||||
import net.corda.core.serialization.SerializationFactory;
|
||||
import net.corda.core.serialization.SerializedBytes;
|
||||
import net.corda.serialization.internal.AllWhitelist;
|
||||
import net.corda.serialization.internal.amqp.*;
|
||||
import net.corda.serialization.internal.amqp.Schema;
|
||||
import net.corda.serialization.internal.amqp.DeserializationInput;
|
||||
import net.corda.serialization.internal.amqp.Envelope;
|
||||
import net.corda.serialization.internal.amqp.ObjectAndEnvelope;
|
||||
import net.corda.serialization.internal.amqp.SerializerFactory;
|
||||
import net.corda.serialization.internal.amqp.testutils.TestSerializationContext;
|
||||
import net.corda.serialization.internal.model.RemoteTypeInformation;
|
||||
import net.corda.serialization.internal.model.TypeIdentifier;
|
||||
@ -15,10 +17,8 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactoryNoEvolution;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JavaCalculatedValuesToClassCarpenterTest extends AmqpCarpenterBase {
|
||||
public JavaCalculatedValuesToClassCarpenterTest() {
|
@ -13,7 +13,6 @@ import net.corda.core.contracts.TransactionVerificationException
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.internal.DEPLOYED_CORDAPP_UPLOADER
|
||||
import net.corda.core.node.services.AttachmentStorage
|
||||
import net.corda.core.serialization.ClassWhitelist
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.internal.AttachmentsClassLoader
|
||||
import net.corda.core.serialization.internal.CheckpointSerializationContext
|
||||
@ -110,10 +109,6 @@ class DefaultSerializableSerializer : Serializer<DefaultSerializable>() {
|
||||
}
|
||||
}
|
||||
|
||||
object EmptyWhitelist : ClassWhitelist {
|
||||
override fun hasListed(type: Class<*>): Boolean = false
|
||||
}
|
||||
|
||||
class CordaClassResolverTests {
|
||||
private companion object {
|
||||
val emptyListClass = listOf<Any>().javaClass
|
@ -6,15 +6,15 @@ import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.node.serialization.kryo.kryoMagic
|
||||
import net.corda.node.services.statemachine.DataSessionMessage
|
||||
import net.corda.serialization.internal.amqp.propertyDescriptors
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
import net.corda.testing.internal.kryoSpecific
|
||||
import org.junit.Assert.*
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.*
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
|
||||
class SetsSerializationTest {
|
||||
private companion object {
|
||||
@ -85,7 +85,8 @@ class SetsSerializationTest {
|
||||
*/
|
||||
@Test
|
||||
fun `type variance on setter getter pair does not fail validation`() {
|
||||
assertThat(VarOfP::class.java.propertyDescriptors()).containsKey("p")
|
||||
assertThat(VarOfP::class.java.accessPropertyDescriptors()).containsKey("p")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.core.flows.FlowException
|
||||
import net.corda.serialization.internal.amqp.custom.ThrowableSerializer
|
||||
import net.corda.serialization.internal.amqp.testutils.serializeAndReturnSchema
|
||||
import net.corda.serialization.internal.amqp.testutils.testDefaultFactory
|
||||
import net.corda.serialization.internal.model.*
|
||||
import net.corda.serialization.internal.accessAsClass
|
||||
import net.corda.serialization.internal.model.RemoteTypeInformation
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.util.*
|
||||
|
||||
class AMQPRemoteTypeModelTests {
|
||||
@ -76,7 +74,7 @@ class AMQPRemoteTypeModelTests {
|
||||
val schema = output.serializeAndReturnSchema(obj)
|
||||
schema.schema.types.forEach { println(it) }
|
||||
val values = typeModel.interpret(SerializationSchemas(schema.schema, schema.transformsSchema)).values
|
||||
return values.find { it.typeIdentifier.getLocalType().asClass().isAssignableFrom(obj::class.java) } ?:
|
||||
return values.find { it.typeIdentifier.getLocalType().accessAsClass().isAssignableFrom(obj::class.java) } ?:
|
||||
throw IllegalArgumentException(
|
||||
"Can't find ${obj::class.java.name} in ${values.map { it.typeIdentifier.name}}")
|
||||
}
|
@ -222,16 +222,16 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
val bytes = ser.serialize(obj, compression)
|
||||
|
||||
val decoder = DecoderImpl().apply {
|
||||
this.register(Envelope.DESCRIPTOR, Envelope.Companion)
|
||||
this.register(Schema.DESCRIPTOR, Schema.Companion)
|
||||
this.register(Descriptor.DESCRIPTOR, Descriptor.Companion)
|
||||
this.register(Field.DESCRIPTOR, Field.Companion)
|
||||
this.register(CompositeType.DESCRIPTOR, CompositeType.Companion)
|
||||
this.register(Choice.DESCRIPTOR, Choice.Companion)
|
||||
this.register(RestrictedType.DESCRIPTOR, RestrictedType.Companion)
|
||||
this.register(ReferencedObject.DESCRIPTOR, ReferencedObject.Companion)
|
||||
this.register(TransformsSchema.DESCRIPTOR, TransformsSchema.Companion)
|
||||
this.register(TransformTypes.DESCRIPTOR, TransformTypes.Companion)
|
||||
this.register(Envelope.DESCRIPTOR, Envelope)
|
||||
this.register(Schema.DESCRIPTOR, Schema)
|
||||
this.register(Descriptor.DESCRIPTOR, Descriptor)
|
||||
this.register(Field.DESCRIPTOR, Field)
|
||||
this.register(CompositeType.DESCRIPTOR, CompositeType)
|
||||
this.register(Choice.DESCRIPTOR, Choice)
|
||||
this.register(RestrictedType.DESCRIPTOR, RestrictedType)
|
||||
this.register(ReferencedObject.DESCRIPTOR, ReferencedObject)
|
||||
this.register(TransformsSchema.DESCRIPTOR, TransformsSchema)
|
||||
this.register(TransformTypes.DESCRIPTOR, TransformTypes)
|
||||
}
|
||||
EncoderImpl(decoder)
|
||||
DeserializationInput.withDataBytes(bytes, encodingWhitelist) {
|
||||
@ -424,7 +424,6 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
serdes(obj)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `test inherits generic captured`() {
|
||||
val obj = CapturesGenericX(InheritGenericX(1.0, "Ginger"))
|
||||
@ -664,7 +663,6 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
|
||||
object FooContract : Contract {
|
||||
override fun verify(tx: LedgerTransaction) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,9 @@ dependencies {
|
||||
|
||||
testCompile "org.assertj:assertj-core:$assertj_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
testCompile project(':node-driver')
|
||||
testCompile "org.mockito:mockito-core:$mockito_version"
|
||||
testCompile 'org.hamcrest:hamcrest-library:2.1'
|
||||
testCompile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
@ -118,7 +118,7 @@ internal fun suitableForObjectReference(type: Type): Boolean {
|
||||
/**
|
||||
* Common properties that are to be used in the [SerializationContext.properties] to alter serialization behavior/content
|
||||
*/
|
||||
internal enum class CommonPropertyNames {
|
||||
enum class CommonPropertyNames {
|
||||
IncludeInternalInfo,
|
||||
}
|
||||
|
||||
|
11
serialization/src/test/README.md
Normal file
11
serialization/src/test/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Adding tests to the Serialization module
|
||||
|
||||
Any tests that do not require further Corda dependencies (other than `core`) should be added to this module, anything that requires additional
|
||||
Corda dependencies needs to go into `serialization-tests`.
|
||||
|
||||
The Corda Serialization module should be self-contained and compilable to Java 8 (for the DJVM) bytecode when using a Java 11 compiler.
|
||||
Prior to this change, it was impossible to use a Java 11 compiler to compile this module to Java 8 bytecode due to its dependencies on other
|
||||
modules compiled to Java 11 (`node-driver` and transitive dependencies including: `test-utils`, `node`, `test-common`, `common-logging`, `node-api`,
|
||||
`client-mock`. `tools-cliutils`).
|
||||
Therefore, any tests that require further Corda dependencies need to be defined in the module `serialization-tests`, which has the full set
|
||||
of dependencies including `node-driver`.
|
@ -1,15 +1,13 @@
|
||||
package net.corda.serialization.internal.amqp;
|
||||
|
||||
import net.corda.serialization.internal.AllWhitelist;
|
||||
import net.corda.serialization.internal.amqp.testutils.TestSerializationContext;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@Ignore("Current behaviour allows for the serialization of objects with private members, this will be disallowed at some point in the future")
|
||||
public class ErrorMessageTests {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.corda.serialization.internal.amqp;
|
||||
|
||||
import kotlin.Suppress;
|
||||
import net.corda.core.serialization.SerializedBytes;
|
||||
import net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt;
|
||||
import net.corda.serialization.internal.amqp.testutils.TestSerializationContext;
|
||||
@ -8,7 +7,9 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
@ -14,7 +14,7 @@ import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory;
|
||||
import static org.jgroups.util.Util.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JavaGenericsTest {
|
||||
|
@ -5,12 +5,10 @@ import net.corda.serialization.internal.amqp.testutils.TestSerializationContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.corda.core.internal.InternalUtils.uncheckedCast;
|
||||
import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class JavaPrivatePropertyTests {
|
||||
static class C {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.corda.serialization.internal.amqp;
|
||||
|
||||
import net.corda.core.serialization.SerializedBytes;
|
||||
import net.corda.serialization.internal.amqp.testutils.TestSerializationContext;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.corda.serialization.internal
|
||||
|
||||
import net.corda.core.serialization.ClassWhitelist
|
||||
import net.corda.serialization.internal.amqp.*
|
||||
import java.lang.reflect.Type
|
||||
|
||||
/**
|
||||
* A set of functions in serialization:test that allows testing of serialization internal classes in the serialization-tests project.
|
||||
*/
|
||||
|
||||
const val MAX_TYPE_PARAM_DEPTH = AMQPTypeIdentifierParser.MAX_TYPE_PARAM_DEPTH
|
||||
|
||||
fun Class<out Any?>.accessPropertyDescriptors(validateProperties: Boolean = true): Map<String, PropertyDescriptor> = propertyDescriptors(validateProperties)
|
||||
fun Type.accessAsClass(): Class<*> = asClass()
|
||||
fun <T> ifThrowsAppend(strToAppendFn: () -> String, block: () -> T): T = net.corda.serialization.internal.amqp.ifThrowsAppend(strToAppendFn, block)
|
||||
|
||||
object EmptyWhitelist : ClassWhitelist {
|
||||
override fun hasListed(type: Class<*>): Boolean = false
|
||||
}
|
@ -4,6 +4,7 @@ import org.assertj.core.api.Assertions
|
||||
import org.junit.Test
|
||||
import java.io.NotSerializableException
|
||||
import kotlin.test.assertEquals
|
||||
import net.corda.serialization.internal.ifThrowsAppend
|
||||
|
||||
class AMQPExceptionsTests {
|
||||
|
||||
|
@ -10,6 +10,7 @@ import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import net.corda.serialization.internal.MAX_TYPE_PARAM_DEPTH
|
||||
|
||||
class AMQPTypeIdentifierParserTests {
|
||||
|
||||
@ -157,7 +158,7 @@ class AMQPTypeIdentifierParserTests {
|
||||
@Test(expected = NotSerializableException::class)
|
||||
fun `test excessive nesting`() {
|
||||
var nested = "java.lang.Integer"
|
||||
for (i in 1..AMQPTypeIdentifierParser.MAX_TYPE_PARAM_DEPTH) {
|
||||
for (i in 1..MAX_TYPE_PARAM_DEPTH) {
|
||||
nested = "java.util.List<$nested>"
|
||||
}
|
||||
verify(nested)
|
||||
|
@ -3,21 +3,19 @@ package net.corda.serialization.internal.amqp
|
||||
import net.corda.core.serialization.*
|
||||
import net.corda.serialization.internal.NotSerializableDetailedException
|
||||
import net.corda.serialization.internal.amqp.testutils.*
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.io.NotSerializableException
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class EnumEvolvabilityTests {
|
||||
@Suppress("UNUSED")
|
||||
val localPath: URI = projectRootDir.toUri().resolve(
|
||||
"serialization/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
"serialization-tests/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
|
||||
companion object {
|
||||
const val VERBOSE = false
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.core.internal.toPath
|
||||
import net.corda.core.serialization.*
|
||||
import net.corda.core.serialization.CordaSerializationTransformEnumDefault
|
||||
import net.corda.core.serialization.CordaSerializationTransformEnumDefaults
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir
|
||||
import net.corda.serialization.internal.amqp.testutils.deserialize
|
||||
import net.corda.serialization.internal.amqp.testutils.serialize
|
||||
import net.corda.serialization.internal.amqp.testutils.testDefaultFactory
|
||||
import net.corda.serialization.internal.amqp.testutils.testName
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.io.NotSerializableException
|
||||
@ -23,7 +24,7 @@ import kotlin.test.assertNotNull
|
||||
class EnumEvolveTests {
|
||||
@Suppress("UNUSED")
|
||||
var localPath: URI = projectRootDir.toUri().resolve(
|
||||
"serialization/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
"serialization-tests/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
|
||||
// Version of the class as it was serialised
|
||||
//
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.core.crypto.Crypto
|
||||
import net.corda.core.crypto.Crypto.generateKeyPair
|
||||
import net.corda.core.crypto.SignedData
|
||||
import net.corda.core.crypto.sign
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.node.NetworkParameters
|
||||
import net.corda.core.node.NotaryInfo
|
||||
import net.corda.core.serialization.ConstructorForDeserialization
|
||||
@ -10,9 +13,6 @@ import net.corda.core.serialization.DeprecatedConstructorForDeserialization
|
||||
import net.corda.core.serialization.SerializableCalculatedProperty
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.serialization.internal.amqp.testutils.*
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||
import net.corda.testing.core.TestIdentity
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
@ -21,6 +21,8 @@ import java.net.URI
|
||||
import java.time.Instant
|
||||
import kotlin.test.assertEquals
|
||||
import net.corda.serialization.internal.amqp.custom.InstantSerializer
|
||||
import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir
|
||||
import java.math.BigInteger
|
||||
|
||||
// To regenerate any of the binary test files do the following
|
||||
//
|
||||
@ -34,7 +36,12 @@ class EvolvabilityTests {
|
||||
// When regenerating the test files this needs to be set to the file system location of the resource files
|
||||
@Suppress("UNUSED")
|
||||
var localPath: URI = projectRootDir.toUri().resolve(
|
||||
"serialization/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
"serialization-test/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
|
||||
companion object {
|
||||
private val DUMMY_NOTARY_NAME = CordaX500Name("Notary Service", "Zurich", "CH")
|
||||
private val DUMMY_NOTARY_PARTY = Party(DUMMY_NOTARY_NAME, Crypto.deriveKeyPairFromEntropy(Crypto.DEFAULT_SIGNATURE_SCHEME, BigInteger.valueOf(20)).public)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun simpleOrderSwapSameType() {
|
||||
@ -619,7 +626,7 @@ class EvolvabilityTests {
|
||||
assertEquals(1000, networkParams.maxTransactionSize)
|
||||
assertEquals(3, networkParams.minimumPlatformVersion)
|
||||
assertEquals(1, networkParams.notaries.size)
|
||||
assertEquals(TestIdentity(DUMMY_NOTARY_NAME, 20).party, networkParams.notaries.firstOrNull()?.identity)
|
||||
assertEquals(DUMMY_NOTARY_PARTY, networkParams.notaries.firstOrNull()?.identity)
|
||||
}
|
||||
|
||||
//
|
||||
@ -631,9 +638,8 @@ class EvolvabilityTests {
|
||||
fun `regenerate broken network parameters`() {
|
||||
// note: 6a6b6f256 is the sha that generates the file
|
||||
val resource = "networkParams.<corda version>.<commit sha>"
|
||||
val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party
|
||||
val networkParameters = NetworkParameters(
|
||||
3, listOf(NotaryInfo(DUMMY_NOTARY, false)), 1000, 1000, Instant.EPOCH, 1, emptyMap())
|
||||
3, listOf(NotaryInfo(DUMMY_NOTARY_PARTY, false)), 1000, 1000, Instant.EPOCH, 1, emptyMap())
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
sf.register(net.corda.serialization.internal.amqp.custom.InstantSerializer(sf))
|
||||
|
@ -4,15 +4,17 @@ import net.corda.core.contracts.Attachment
|
||||
import net.corda.core.contracts.AttachmentConstraint
|
||||
import net.corda.core.contracts.ContractState
|
||||
import net.corda.core.contracts.TransactionState
|
||||
import net.corda.core.crypto.Crypto
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.serialization.internal.amqp.testutils.*
|
||||
import net.corda.serialization.internal.AllWhitelist
|
||||
import net.corda.serialization.internal.amqp.testutils.ProjectStructure.projectRootDir
|
||||
import net.corda.serialization.internal.carpenter.ClassCarpenterImpl
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import net.corda.testing.core.TestIdentity
|
||||
import org.junit.Test
|
||||
import java.math.BigInteger
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
@ -31,9 +33,10 @@ class GenericsTests {
|
||||
|
||||
@Suppress("UNUSED")
|
||||
var localPath: URI = projectRootDir.toUri().resolve(
|
||||
"serialization/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
"serialization-tests/src/test/resources/net/corda/serialization/internal/amqp")
|
||||
|
||||
val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
|
||||
private val MINI_CORP_NAME = CordaX500Name("Notary Service", "Zurich", "CH")
|
||||
private val MINI_CORP_PARTY = Party(MINI_CORP_NAME, Crypto.deriveKeyPairFromEntropy(Crypto.DEFAULT_SIGNATURE_SCHEME, BigInteger.valueOf(20)).public)
|
||||
}
|
||||
|
||||
private fun printSeparator() = if (VERBOSE) println("\n\n-------------------------------------------\n\n") else Unit
|
||||
@ -313,8 +316,8 @@ class GenericsTests {
|
||||
@Test
|
||||
fun fingerprintingDiffers() {
|
||||
val state = TransactionState(
|
||||
TestContractState(listOf(miniCorp.party)),
|
||||
"wibble", miniCorp.party,
|
||||
TestContractState(listOf(MINI_CORP_PARTY)),
|
||||
"wibble",MINI_CORP_PARTY,
|
||||
encumbrance = null,
|
||||
constraint = TestAttachmentConstraint())
|
||||
|
||||
@ -326,8 +329,8 @@ class GenericsTests {
|
||||
@Test
|
||||
fun fingerprintingDiffersList() {
|
||||
val state = TransactionState(
|
||||
TestContractState(listOf(miniCorp.party)),
|
||||
"wibble", miniCorp.party,
|
||||
TestContractState(listOf(MINI_CORP_PARTY)),
|
||||
"wibble", MINI_CORP_PARTY,
|
||||
encumbrance = null,
|
||||
constraint = TestAttachmentConstraint())
|
||||
|
||||
@ -349,8 +352,8 @@ class GenericsTests {
|
||||
data class TransactionStateWrapper<out T : ContractState> (val o: List<GenericStateAndString<T>>)
|
||||
|
||||
val state = TransactionState<TestContractState> (
|
||||
TestContractState(listOf(miniCorp.party)),
|
||||
"wibble", miniCorp.party,
|
||||
TestContractState(listOf(MINI_CORP_PARTY)),
|
||||
"wibble", MINI_CORP_PARTY,
|
||||
encumbrance = null,
|
||||
constraint = TestAttachmentConstraint())
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package net.corda.serialization.internal.amqp.testutils
|
||||
|
||||
import net.corda.core.internal.copyTo
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.packageName
|
||||
import net.corda.core.internal.*
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.SerializationEncoding
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
@ -11,11 +9,11 @@ import net.corda.serialization.internal.AllWhitelist
|
||||
import net.corda.serialization.internal.EmptyWhitelist
|
||||
import net.corda.serialization.internal.amqp.*
|
||||
import net.corda.serialization.internal.carpenter.ClassCarpenterImpl
|
||||
import net.corda.testing.common.internal.ProjectStructure
|
||||
import org.apache.qpid.proton.codec.Data
|
||||
import org.junit.Test
|
||||
import java.io.File.separatorChar
|
||||
import java.io.NotSerializableException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
|
||||
|
||||
/**
|
||||
@ -99,6 +97,16 @@ fun testName(): String {
|
||||
|
||||
fun Any.testResourceName(): String = "${javaClass.simpleName}.${testName()}"
|
||||
|
||||
internal object ProjectStructure {
|
||||
val projectRootDir: Path = run {
|
||||
var dir = javaClass.getResource("/").toPath()
|
||||
while (!(dir / ".git").isDirectory()) {
|
||||
dir = dir.parent
|
||||
}
|
||||
dir
|
||||
}
|
||||
}
|
||||
|
||||
fun Any.writeTestResource(bytes: OpaqueBytes) {
|
||||
val dir = ProjectStructure.projectRootDir / "serialization" / "src" / "test" / "resources" / javaClass.packageName.replace('.', separatorChar)
|
||||
bytes.open().copyTo(dir / testResourceName(), REPLACE_EXISTING)
|
||||
|
@ -4,10 +4,10 @@ import com.google.common.reflect.TypeToken
|
||||
import net.corda.core.serialization.ClassWhitelist
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.serialization.internal.accessAsClass
|
||||
import net.corda.serialization.internal.amqp.*
|
||||
import net.corda.serialization.internal.amqp.testutils.deserializeAndReturnEnvelope
|
||||
import net.corda.serialization.internal.amqp.testutils.serialize
|
||||
import net.corda.serialization.internal.amqp.testutils.testName
|
||||
import net.corda.serialization.internal.model.*
|
||||
import org.junit.Assert.assertTrue
|
||||
|
||||
@ -85,7 +85,7 @@ open class AmqpCarpenterBase(whitelist: ClassWhitelist) {
|
||||
}
|
||||
|
||||
protected fun RemoteTypeInformation.load(context : SerializationContext): Class<*> =
|
||||
typeLoader.load(listOf(this), context)[typeIdentifier]!!.asClass()
|
||||
typeLoader.load(listOf(this), context)[typeIdentifier]!!.accessAsClass()
|
||||
|
||||
protected fun assertCanLoadAll(context: SerializationContext, vararg types: RemoteTypeInformation) {
|
||||
assertTrue(typeLoader.load(types.asList(), context).keys.containsAll(types.map { it.typeIdentifier }))
|
||||
|
@ -3,7 +3,7 @@ package net.corda.serialization.internal.model
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.google.common.reflect.TypeToken
|
||||
import net.corda.serialization.internal.AllWhitelist
|
||||
import net.corda.serialization.internal.amqp.asClass
|
||||
import net.corda.serialization.internal.accessAsClass
|
||||
import net.corda.serialization.internal.amqp.testutils.testSerializationContext
|
||||
import net.corda.serialization.internal.carpenter.ClassCarpenterImpl
|
||||
import org.junit.Test
|
||||
@ -75,7 +75,7 @@ class ClassCarpentingTypeLoaderTests {
|
||||
}
|
||||
|
||||
private fun Type.make(vararg params: Any): Any {
|
||||
val cls = this.asClass()
|
||||
val cls = this.accessAsClass()
|
||||
val paramTypes = params.map { it::class.javaPrimitiveType ?: it::class.javaObjectType }.toTypedArray()
|
||||
val constructor = cls.constructors.find { it.parameterTypes.zip(paramTypes).all {
|
||||
(expected, actual) -> expected.isAssignableFrom(actual)
|
||||
|
@ -77,6 +77,7 @@ include 'samples:cordapp-configuration:workflows'
|
||||
include 'samples:network-verifier:contracts'
|
||||
include 'samples:network-verifier:workflows'
|
||||
include 'serialization'
|
||||
include 'serialization-tests'
|
||||
|
||||
// Common libraries - start
|
||||
include 'common-validation'
|
||||
|
Loading…
Reference in New Issue
Block a user