mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Merge remote-tracking branch 'corda/master' into christians_os_merge_20171031
This commit is contained in:
@ -15,4 +15,5 @@ import kotlin.reflect.KClass
|
||||
* @see InitiatingFlow
|
||||
*/
|
||||
@Target(CLASS)
|
||||
@MustBeDocumented
|
||||
annotation class InitiatedBy(val value: KClass<out FlowLogic<*>>)
|
@ -3,6 +3,7 @@ package net.corda.core.flows
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.internal.ResolveTransactionsFlow
|
||||
import net.corda.core.node.StatesToRecord
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.unwrap
|
||||
import java.security.SignatureException
|
||||
@ -14,25 +15,41 @@ import java.security.SignatureException
|
||||
* [SignedTransaction] and perform the resolution back-and-forth required to check the dependencies and download any missing
|
||||
* attachments. The flow will return the [SignedTransaction] after it is resolved and then verified using [SignedTransaction.verify].
|
||||
*
|
||||
* @param otherSideSession session to the other side which is calling [SendTransactionFlow].
|
||||
* @param checkSufficientSignatures if true checks all required signatures are present. See [SignedTransaction.verify].
|
||||
* Please note that it will *not* store the transaction to the vault unless that is explicitly requested.
|
||||
*
|
||||
* @property otherSideSession session to the other side which is calling [SendTransactionFlow].
|
||||
* @property checkSufficientSignatures if true checks all required signatures are present. See [SignedTransaction.verify].
|
||||
* @property statesToRecord which transaction states should be recorded in the vault, if any.
|
||||
*/
|
||||
class ReceiveTransactionFlow(private val otherSideSession: FlowSession,
|
||||
private val checkSufficientSignatures: Boolean) : FlowLogic<SignedTransaction>() {
|
||||
/** Receives a [SignedTransaction] from [otherSideSession], verifies it and then records it in the vault. */
|
||||
constructor(otherSideSession: FlowSession) : this(otherSideSession, true)
|
||||
|
||||
class ReceiveTransactionFlow @JvmOverloads constructor(private val otherSideSession: FlowSession,
|
||||
private val checkSufficientSignatures: Boolean = true,
|
||||
private val statesToRecord: StatesToRecord = StatesToRecord.NONE) : FlowLogic<SignedTransaction>() {
|
||||
@Suppress("KDocMissingDocumentation")
|
||||
@Suspendable
|
||||
@Throws(SignatureException::class,
|
||||
AttachmentResolutionException::class,
|
||||
TransactionResolutionException::class,
|
||||
TransactionVerificationException::class)
|
||||
override fun call(): SignedTransaction {
|
||||
return otherSideSession.receive<SignedTransaction>().unwrap {
|
||||
if (checkSufficientSignatures) {
|
||||
logger.trace("Receiving a transaction from ${otherSideSession.counterparty}")
|
||||
} else {
|
||||
logger.trace("Receiving a transaction (but without checking the signatures) from ${otherSideSession.counterparty}")
|
||||
}
|
||||
|
||||
val stx = otherSideSession.receive<SignedTransaction>().unwrap {
|
||||
subFlow(ResolveTransactionsFlow(it, otherSideSession))
|
||||
it.verify(serviceHub, checkSufficientSignatures)
|
||||
it
|
||||
}
|
||||
|
||||
if (checkSufficientSignatures) {
|
||||
// We should only send a transaction to the vault for processing if we did in fact fully verify it, and
|
||||
// there are no missing signatures. We don't want partly signed stuff in the vault.
|
||||
logger.trace("Successfully received fully signed tx ${stx.id}, sending to the vault for processing")
|
||||
serviceHub.recordTransactions(statesToRecord, setOf(stx))
|
||||
}
|
||||
return stx
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.flows.FlowException
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.FlowSession
|
||||
import net.corda.core.node.StatesToRecord
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.exactAdd
|
||||
@ -94,7 +95,7 @@ class ResolveTransactionsFlow(private val txHashes: Set<SecureHash>,
|
||||
// half way through, it's no big deal, although it might result in us attempting to re-download data
|
||||
// redundantly next time we attempt verification.
|
||||
it.verify(serviceHub)
|
||||
serviceHub.recordTransactions(false, it)
|
||||
serviceHub.recordTransactions(StatesToRecord.NONE, listOf(it))
|
||||
}
|
||||
|
||||
return signedTransaction?.let {
|
||||
|
@ -50,6 +50,26 @@ interface ServicesForResolution : StateLoader {
|
||||
val cordappProvider: CordappProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether the transaction is sent to the vault at all, and if so whether states have to be relevant
|
||||
* or not in order to be recorded. Used in [ServiceHub.recordTransactions]
|
||||
*/
|
||||
enum class StatesToRecord {
|
||||
/** The received transaction is not sent to the vault at all. This is used within transaction resolution. */
|
||||
NONE,
|
||||
/**
|
||||
* All states that can be seen in the transaction will be recorded by the vault, even if none of the identities
|
||||
* on this node are a participant or owner.
|
||||
*/
|
||||
ALL_VISIBLE,
|
||||
/**
|
||||
* Only states that involve one of our public keys will be stored in the vault. This is the default. A public
|
||||
* key is involved (relevant) if it's in the [OwnableState.owner] field, or appears in the [ContractState.participants]
|
||||
* collection. This is usually equivalent to "can I change the contents of this state by signing a transaction".
|
||||
*/
|
||||
ONLY_RELEVANT
|
||||
}
|
||||
|
||||
/**
|
||||
* A service hub is the starting point for most operations you can do inside the node. You are provided with one
|
||||
* when a class annotated with [CordaService] is constructed, and you have access to one inside flows. Most RPCs
|
||||
@ -132,7 +152,9 @@ interface ServiceHub : ServicesForResolution {
|
||||
* @param txs The transactions to record.
|
||||
* @param notifyVault indicate if the vault should be notified for the update.
|
||||
*/
|
||||
fun recordTransactions(notifyVault: Boolean, txs: Iterable<SignedTransaction>)
|
||||
fun recordTransactions(notifyVault: Boolean, txs: Iterable<SignedTransaction>) {
|
||||
recordTransactions(if (notifyVault) StatesToRecord.ONLY_RELEVANT else StatesToRecord.NONE, txs)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the given [SignedTransaction]s in the local transaction storage and then sends them to the vault for
|
||||
@ -142,12 +164,22 @@ interface ServiceHub : ServicesForResolution {
|
||||
recordTransactions(notifyVault, listOf(first, *remaining))
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the given [SignedTransaction]s in the local transaction storage and then sends them to the vault for
|
||||
* further processing if [statesToRecord] is not [StatesToRecord.NONE].
|
||||
* This is expected to be run within a database transaction.
|
||||
*
|
||||
* @param txs The transactions to record.
|
||||
* @param statesToRecord how the vault should treat the output states of the transaction.
|
||||
*/
|
||||
fun recordTransactions(statesToRecord: StatesToRecord, txs: Iterable<SignedTransaction>)
|
||||
|
||||
/**
|
||||
* Stores the given [SignedTransaction]s in the local transaction storage and then sends them to the vault for
|
||||
* further processing. This is expected to be run within a database transaction.
|
||||
*/
|
||||
fun recordTransactions(first: SignedTransaction, vararg remaining: SignedTransaction) {
|
||||
recordTransactions(true, first, *remaining)
|
||||
recordTransactions(listOf(first, *remaining))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +187,7 @@ interface ServiceHub : ServicesForResolution {
|
||||
* further processing. This is expected to be run within a database transaction.
|
||||
*/
|
||||
fun recordTransactions(txs: Iterable<SignedTransaction>) {
|
||||
recordTransactions(true, txs)
|
||||
recordTransactions(StatesToRecord.ONLY_RELEVANT, txs)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ object NodeInfoSchemaV1 : MappedSchema(
|
||||
private val persistentNodeInfos: Set<PersistentNodeInfo> = emptySet()
|
||||
) {
|
||||
constructor(partyAndCert: PartyAndCertificate, isMain: Boolean = false)
|
||||
: this(partyAndCert.party.name.toString(),
|
||||
: this(partyAndCert.name.toString(),
|
||||
partyAndCert.party.owningKey.toStringShort(),
|
||||
partyAndCert.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes, isMain)
|
||||
|
||||
|
@ -0,0 +1,93 @@
|
||||
package net.corda.core.serialization
|
||||
|
||||
/**
|
||||
* This annotation is used to mark an enumerated type as having had multiple members added, It acts
|
||||
* as a container annotation for instances of [CordaSerializationTransformEnumDefault], each of which
|
||||
* details individual additions.
|
||||
*
|
||||
* @property value an array of [CordaSerializationTransformEnumDefault].
|
||||
*
|
||||
* NOTE: Order is important, new values should always be added before any others
|
||||
*
|
||||
* ```
|
||||
* // initial implementation
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C
|
||||
* }
|
||||
*
|
||||
* // First alteration
|
||||
* @CordaSerializationTransformEnumDefaults(
|
||||
* CordaSerializationTransformEnumDefault("D", "C"))
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C, D
|
||||
* }
|
||||
*
|
||||
* // Second alteration, new transform is placed at the head of the list
|
||||
* @CordaSerializationTransformEnumDefaults(
|
||||
* CordaSerializationTransformEnumDefault("E", "C"),
|
||||
* CordaSerializationTransformEnumDefault("D", "C"))
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C, D, E
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* IMPORTANT - Once added (and in production) do NOT remove old annotations. See documentation for
|
||||
* more discussion on this point!.
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class CordaSerializationTransformEnumDefaults(vararg val value: CordaSerializationTransformEnumDefault)
|
||||
|
||||
/**
|
||||
* This annotation is used to mark an enumerated type as having had a new constant appended to it. For
|
||||
* each additional constant added a new annotation should be appended to the class. If more than one
|
||||
* is required the wrapper annotation [CordaSerializationTransformEnumDefaults] should be used to
|
||||
* encapsulate them
|
||||
*
|
||||
* @property new [String] equivalent of the value of the new constant
|
||||
* @property old [String] equivalent of the value of the existing constant that deserialisers should
|
||||
* favour when de-serialising a value they have no corresponding value for
|
||||
*
|
||||
* For Example
|
||||
*
|
||||
* Enum before modification:
|
||||
* ```
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Assuming at some point a new constant is added it is required we have some mechanism by which to tell
|
||||
* nodes with an older version of the class on their Class Path what to do if they attempt to deserialize
|
||||
* an example of the class with that new value
|
||||
*
|
||||
* ```
|
||||
* @CordaSerializationTransformEnumDefault("D", "C")
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C, D
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* So, on deserialisation treat any instance of the enum that is encoded as D as C
|
||||
*
|
||||
* Adding a second new constant requires the wrapper annotation [CordaSerializationTransformEnumDefaults]
|
||||
*
|
||||
* ```
|
||||
* @CordaSerializationTransformEnumDefaults(
|
||||
* CordaSerializationTransformEnumDefault("E", "D"),
|
||||
* CordaSerializationTransformEnumDefault("D", "C"))
|
||||
* enum class ExampleEnum {
|
||||
* A, B, C, D, E
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* It's fine to assign the second new value a default that may not be present in all versions as in this
|
||||
* case it will work down the transform hierarchy until it finds a value it can apply, in this case it would
|
||||
* try E -> D -> C (when E -> D fails)
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
// When Kotlin starts writing 1.8 class files enable this, it removes the need for the wrapping annotation
|
||||
//@Repeatable
|
||||
annotation class CordaSerializationTransformEnumDefault(val new: String, val old: String)
|
||||
|
@ -0,0 +1,35 @@
|
||||
package net.corda.core.serialization
|
||||
|
||||
/**
|
||||
* This annotation is used to mark a class as having had multiple elements renamed as a container annotation for
|
||||
* instances of [CordaSerializationTransformRename], each of which details an individual rename.
|
||||
*
|
||||
* @property value an array of [CordaSerializationTransformRename]
|
||||
*
|
||||
* NOTE: Order is important, new values should always be added before existing
|
||||
*
|
||||
* IMPORTANT - Once added (and in production) do NOT remove old annotations. See documentation for
|
||||
* more discussion on this point!.
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class CordaSerializationTransformRenames(vararg val value: CordaSerializationTransformRename)
|
||||
|
||||
// TODO When we have class renaming update the docs
|
||||
/**
|
||||
* This annotation is used to mark a class has having had a property element. It is used by the
|
||||
* AMQP deserialiser to allow instances with different versions of the class on their Class Path
|
||||
* to successfully deserialize the object
|
||||
*
|
||||
* NOTE: Renaming of the class itself is not be done with this annotation. For class renaming
|
||||
* see ???
|
||||
*
|
||||
* @property to [String] representation of the properties new name
|
||||
* @property from [String] representation of the properties old new
|
||||
*
|
||||
*/
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
// When Kotlin starts writing 1.8 class files enable this, it removes the need for the wrapping annotation
|
||||
//@Repeatable
|
||||
annotation class CordaSerializationTransformRename(val to: String, val from: String)
|
@ -3,6 +3,7 @@ package net.corda.core.serialization
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.internal.WriteOnceProperty
|
||||
import net.corda.core.serialization.internal.SerializationEnvironment
|
||||
import net.corda.core.utilities.ByteSequence
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.sequence
|
||||
@ -172,13 +173,13 @@ interface SerializationContext {
|
||||
/**
|
||||
* Global singletons to be used as defaults that are injected elsewhere (generally, in the node or in RPC client).
|
||||
*/
|
||||
object SerializationDefaults {
|
||||
var SERIALIZATION_FACTORY: SerializationFactory by WriteOnceProperty()
|
||||
var P2P_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
var RPC_SERVER_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
var RPC_CLIENT_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
var STORAGE_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
var CHECKPOINT_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
object SerializationDefaults : SerializationEnvironment {
|
||||
override var SERIALIZATION_FACTORY: SerializationFactory by WriteOnceProperty()
|
||||
override var P2P_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
override var RPC_SERVER_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
override var RPC_CLIENT_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
override var STORAGE_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
override var CHECKPOINT_CONTEXT: SerializationContext by WriteOnceProperty()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,13 @@
|
||||
package net.corda.core.serialization.internal
|
||||
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.SerializationFactory
|
||||
|
||||
interface SerializationEnvironment {
|
||||
val SERIALIZATION_FACTORY: SerializationFactory
|
||||
val P2P_CONTEXT: SerializationContext
|
||||
val RPC_SERVER_CONTEXT: SerializationContext
|
||||
val RPC_CLIENT_CONTEXT: SerializationContext
|
||||
val STORAGE_CONTEXT: SerializationContext
|
||||
val CHECKPOINT_CONTEXT: SerializationContext
|
||||
}
|
@ -8,13 +8,16 @@ import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.contracts.DummyState
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.util.function.Predicate
|
||||
import kotlin.test.*
|
||||
|
||||
class CompatibleTransactionTests : TestDependencyInjectionBase() {
|
||||
|
||||
class CompatibleTransactionTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
private val dummyOutState = TransactionState(DummyState(0), DummyContract.PROGRAM_ID, DUMMY_NOTARY)
|
||||
private val stateRef1 = StateRef(SecureHash.randomSHA256(), 0)
|
||||
private val stateRef2 = StateRef(SecureHash.randomSHA256(), 1)
|
||||
|
@ -4,10 +4,11 @@ import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.internal.UpgradeCommand
|
||||
import net.corda.testing.ALICE
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.contracts.DummyContractV2
|
||||
import net.corda.testing.node.MockServices
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
@ -15,7 +16,11 @@ import kotlin.test.assertTrue
|
||||
/**
|
||||
* Tests for the version 2 dummy contract, to cover ensuring upgrade transactions are built correctly.
|
||||
*/
|
||||
class DummyContractV2Tests : TestDependencyInjectionBase() {
|
||||
class DummyContractV2Tests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
@Test
|
||||
fun `upgrade from v1`() {
|
||||
val services = MockServices()
|
||||
|
@ -3,21 +3,21 @@ package net.corda.core.contracts
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.transactions.LedgerTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.chooseIdentity
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.MockServices
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.util.function.Predicate
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class LedgerTransactionQueryTests : TestDependencyInjectionBase() {
|
||||
|
||||
class LedgerTransactionQueryTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
private val services: MockServices = MockServices()
|
||||
|
||||
@Before
|
||||
|
@ -10,14 +10,18 @@ import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER_KEY
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.node.MockAttachment
|
||||
import net.corda.testing.node.MockAttachmentStorage
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.security.KeyPair
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class TransactionTests : TestDependencyInjectionBase() {
|
||||
class TransactionTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
private fun makeSigned(wtx: WireTransaction, vararg keys: KeyPair, notarySig: Boolean = true): SignedTransaction {
|
||||
val keySigs = keys.map { it.sign(SignableData(wtx.id, SignatureMetadata(1, Crypto.findSignatureScheme(it.public).schemeNumberID))) }
|
||||
val sigs = if (notarySig) {
|
||||
|
@ -9,8 +9,8 @@ import net.corda.core.serialization.serialize
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.toBase58String
|
||||
import net.corda.node.utilities.*
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.kryoSpecific
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
@ -20,7 +20,10 @@ import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class CompositeKeyTests : TestDependencyInjectionBase() {
|
||||
class CompositeKeyTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
@Rule
|
||||
@JvmField
|
||||
val tempFolder: TemporaryFolder = TemporaryFolder()
|
||||
|
@ -10,6 +10,7 @@ import net.corda.finance.DOLLARS
|
||||
import net.corda.finance.`issued by`
|
||||
import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.testing.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.security.PublicKey
|
||||
import java.util.function.Predicate
|
||||
@ -17,14 +18,14 @@ import java.util.stream.IntStream
|
||||
import kotlin.streams.toList
|
||||
import kotlin.test.*
|
||||
|
||||
class PartialMerkleTreeTest : TestDependencyInjectionBase() {
|
||||
class PartialMerkleTreeTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
private val testSerialization = SerializationEnvironmentRule()
|
||||
private val nodes = "abcdef"
|
||||
private val hashed = nodes.map {
|
||||
initialiseTestSerialization()
|
||||
try {
|
||||
it.serialize().sha256()
|
||||
} finally {
|
||||
resetTestSerialization()
|
||||
private val hashed = nodes.map { node ->
|
||||
withTestSerialization {
|
||||
node.serialize().sha256()
|
||||
}
|
||||
}
|
||||
private val expectedRoot = MerkleTree.getMerkleTree(hashed.toMutableList() + listOf(zeroHash, zeroHash)).hash
|
||||
|
@ -2,13 +2,18 @@ package net.corda.core.crypto
|
||||
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.security.SignatureException
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SignedDataTest : TestDependencyInjectionBase() {
|
||||
class SignedDataTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
@Before
|
||||
fun initialise() {
|
||||
serialized = data.serialize()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.core.crypto
|
||||
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.security.SignatureException
|
||||
import kotlin.test.assertTrue
|
||||
@ -8,8 +9,10 @@ import kotlin.test.assertTrue
|
||||
/**
|
||||
* Digital signature MetaData tests.
|
||||
*/
|
||||
class TransactionSignatureTest : TestDependencyInjectionBase() {
|
||||
|
||||
class TransactionSignatureTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
val testBytes = "12345678901234567890123456789012".toByteArray()
|
||||
|
||||
/** Valid sign and verify. */
|
||||
|
@ -6,47 +6,48 @@ import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.node.utilities.KEYSTORE_TYPE
|
||||
import net.corda.node.utilities.save
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import net.corda.testing.getTestPartyAndCertificate
|
||||
import net.corda.testing.withTestSerialization
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.math.BigInteger
|
||||
import java.security.KeyStore
|
||||
|
||||
class PartyAndCertificateTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
@Test
|
||||
fun `kryo serialisation`() {
|
||||
withTestSerialization {
|
||||
val original = getTestPartyAndCertificate(Party(
|
||||
CordaX500Name(organisation = "Test Corp", locality = "Madrid", country = "ES"),
|
||||
entropyToKeyPair(BigInteger.valueOf(83)).public))
|
||||
val copy = original.serialize().deserialize()
|
||||
assertThat(copy).isEqualTo(original).isNotSameAs(original)
|
||||
assertThat(copy.certPath).isEqualTo(original.certPath)
|
||||
assertThat(copy.certificate).isEqualTo(original.certificate)
|
||||
}
|
||||
val original = getTestPartyAndCertificate(Party(
|
||||
CordaX500Name(organisation = "Test Corp", locality = "Madrid", country = "ES"),
|
||||
entropyToKeyPair(BigInteger.valueOf(83)).public))
|
||||
val copy = original.serialize().deserialize()
|
||||
assertThat(copy).isEqualTo(original).isNotSameAs(original)
|
||||
assertThat(copy.certPath).isEqualTo(original.certPath)
|
||||
assertThat(copy.certificate).isEqualTo(original.certificate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `jdk serialization`() {
|
||||
withTestSerialization {
|
||||
val identity = getTestPartyAndCertificate(Party(
|
||||
CordaX500Name(organisation = "Test Corp", locality = "Madrid", country = "ES"),
|
||||
entropyToKeyPair(BigInteger.valueOf(83)).public))
|
||||
val original = identity.certificate
|
||||
val storePassword = "test"
|
||||
val keyStoreFilePath = File.createTempFile("serialization_test", "jks").toPath()
|
||||
var keyStore = KeyStore.getInstance(KEYSTORE_TYPE)
|
||||
keyStore.load(null, storePassword.toCharArray())
|
||||
keyStore.setCertificateEntry(identity.name.toString(), original)
|
||||
keyStore.save(keyStoreFilePath, storePassword)
|
||||
val identity = getTestPartyAndCertificate(Party(
|
||||
CordaX500Name(organisation = "Test Corp", locality = "Madrid", country = "ES"),
|
||||
entropyToKeyPair(BigInteger.valueOf(83)).public))
|
||||
val original = identity.certificate
|
||||
val storePassword = "test"
|
||||
val keyStoreFilePath = File.createTempFile("serialization_test", "jks").toPath()
|
||||
var keyStore = KeyStore.getInstance(KEYSTORE_TYPE)
|
||||
keyStore.load(null, storePassword.toCharArray())
|
||||
keyStore.setCertificateEntry(identity.name.toString(), original)
|
||||
keyStore.save(keyStoreFilePath, storePassword)
|
||||
|
||||
// Load the key store back in again
|
||||
keyStore = KeyStore.getInstance(KEYSTORE_TYPE)
|
||||
keyStoreFilePath.read { keyStore.load(it, storePassword.toCharArray()) }
|
||||
val copy = keyStore.getCertificate(identity.name.toString())
|
||||
assertThat(copy).isEqualTo(original) // .isNotSameAs(original)
|
||||
}
|
||||
// Load the key store back in again
|
||||
keyStore = KeyStore.getInstance(KEYSTORE_TYPE)
|
||||
keyStoreFilePath.read { keyStore.load(it, storePassword.toCharArray()) }
|
||||
val copy = keyStore.getCertificate(identity.name.toString())
|
||||
assertThat(copy).isEqualTo(original) // .isNotSameAs(original)
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,15 @@ package net.corda.core.serialization
|
||||
|
||||
import net.corda.finance.contracts.CommercialPaper
|
||||
import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class CommandsSerializationTests : TestDependencyInjectionBase() {
|
||||
class CommandsSerializationTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
@Test
|
||||
fun `test cash move serialization`() {
|
||||
|
@ -9,6 +9,7 @@ import net.corda.finance.POUNDS
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.node.MockServices
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.security.SignatureException
|
||||
import java.util.*
|
||||
@ -16,7 +17,10 @@ import kotlin.reflect.jvm.javaField
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class TransactionSerializationTests : TestDependencyInjectionBase() {
|
||||
class TransactionSerializationTests {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
private val TEST_CASH_PROGRAM_ID = "net.corda.core.serialization.TransactionSerializationTests\$TestCash"
|
||||
|
||||
class TestCash : Contract {
|
||||
|
@ -5,11 +5,15 @@ import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.node.services.UniquenessException
|
||||
import net.corda.core.node.services.UniquenessProvider
|
||||
import net.corda.testing.DUMMY_PARTY
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class UniquenessExceptionSerializationTest : TestDependencyInjectionBase() {
|
||||
class UniquenessExceptionSerializationTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
|
||||
@Test
|
||||
fun testSerializationRoundTrip() {
|
||||
|
@ -7,13 +7,16 @@ import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.nodeapi.internal.serialization.KRYO_CHECKPOINT_CONTEXT
|
||||
import net.corda.nodeapi.internal.serialization.KRYO_P2P_CONTEXT
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
class KotlinUtilsTest : TestDependencyInjectionBase() {
|
||||
class KotlinUtilsTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
@JvmField
|
||||
@Rule
|
||||
val expectedEx: ExpectedException = ExpectedException.none()
|
||||
|
@ -7,8 +7,7 @@ import com.google.common.collect.testing.features.CollectionSize
|
||||
import junit.framework.TestSuite
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.testing.initialiseTestSerialization
|
||||
import net.corda.testing.resetTestSerialization
|
||||
import net.corda.testing.withTestSerialization
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
@ -49,14 +48,10 @@ class NonEmptySetTest {
|
||||
|
||||
@Test
|
||||
fun `serialize deserialize`() {
|
||||
initialiseTestSerialization()
|
||||
try {
|
||||
withTestSerialization {
|
||||
val original = NonEmptySet.of(-17, 22, 17)
|
||||
val copy = original.serialize().deserialize()
|
||||
|
||||
assertThat(copy).isEqualTo(original).isNotSameAs(original)
|
||||
} finally {
|
||||
resetTestSerialization()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user