Moved dummy contracts to test-utils

This commit is contained in:
Shams Asari 2017-07-06 10:24:42 +01:00
parent cefa14507a
commit fb0a043485
36 changed files with 145 additions and 126 deletions

View File

@ -1,55 +0,0 @@
package net.corda.core.contracts.testing
// The dummy contract doesn't do anything useful. It exists for testing purposes.
val DUMMY_V2_PROGRAM_ID = net.corda.core.contracts.testing.DummyContractV2()
/**
* Dummy contract state for testing of the upgrade process.
*/
// DOCSTART 1
class DummyContractV2 : net.corda.core.contracts.UpgradedContract<DummyContract.State, DummyContractV2.State> {
override val legacyContract = DummyContract::class.java
data class State(val magicNumber: Int = 0, val owners: List<net.corda.core.identity.AbstractParty>) : net.corda.core.contracts.ContractState {
override val contract = net.corda.core.contracts.testing.DUMMY_V2_PROGRAM_ID
override val participants: List<net.corda.core.identity.AbstractParty> = owners
}
interface Commands : net.corda.core.contracts.CommandData {
class Create : net.corda.core.contracts.TypeOnlyCommandData(), net.corda.core.contracts.testing.DummyContractV2.Commands
class Move : net.corda.core.contracts.TypeOnlyCommandData(), net.corda.core.contracts.testing.DummyContractV2.Commands
}
override fun upgrade(state: DummyContract.State): net.corda.core.contracts.testing.DummyContractV2.State {
return net.corda.core.contracts.testing.DummyContractV2.State(state.magicNumber, state.participants)
}
override fun verify(tx: net.corda.core.contracts.TransactionForContract) {
if (tx.commands.any { it.value is net.corda.core.contracts.UpgradeCommand }) net.corda.flows.ContractUpgradeFlow.Companion.verify(tx)
// Other verifications.
}
// The "empty contract"
override val legalContractReference: net.corda.core.crypto.SecureHash = net.corda.core.crypto.SecureHash.Companion.sha256("")
// DOCEND 1
/**
* Generate an upgrade transaction from [DummyContract].
*
* Note: This is a convenience helper method used for testing only.
*
* @return a pair of wire transaction, and a set of those who should sign the transaction for it to be valid.
*/
fun generateUpgradeFromV1(vararg states: net.corda.core.contracts.StateAndRef<DummyContract.State>): Pair<net.corda.core.transactions.WireTransaction, Set<net.corda.core.identity.AbstractParty>> {
val notary = states.map { it.state.notary }.single()
require(states.isNotEmpty())
val signees: Set<net.corda.core.identity.AbstractParty> = states.flatMap { it.state.data.participants }.distinct().toSet()
return Pair(net.corda.core.contracts.TransactionType.General.Builder(notary).apply {
states.forEach {
addInputState(it)
addOutputState(upgrade(it.state.data))
addCommand(net.corda.core.contracts.UpgradeCommand(DUMMY_V2_PROGRAM_ID.javaClass), signees.map { it.owningKey }.toList())
}
}.toWireTransaction(), signees)
}
}

View File

@ -1,10 +0,0 @@
package net.corda.core.contracts.testing
/**
* Dummy state for use in testing. Not part of any contract, not even the [DummyContract].
*/
data class DummyState(val magicNumber: Int = 0) : net.corda.core.contracts.ContractState {
override val contract = DUMMY_PROGRAM_ID
override val participants: List<net.corda.core.identity.AbstractParty>
get() = emptyList()
}

View File

@ -1,7 +1,7 @@
package net.corda.core.contracts package net.corda.core.contracts
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.contracts.testing.DummyContractV2 import net.corda.testing.contracts.DummyContractV2
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.testing.ALICE import net.corda.testing.ALICE
import net.corda.testing.DUMMY_NOTARY import net.corda.testing.DUMMY_NOTARY

View File

@ -1,7 +1,7 @@
package net.corda.core.contracts package net.corda.core.contracts
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.contracts.testing.DummyState import net.corda.testing.contracts.DummyState
import net.corda.core.crypto.newSecureRandom import net.corda.core.crypto.newSecureRandom
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction

View File

@ -1,7 +1,7 @@
package net.corda.core.contracts package net.corda.core.contracts
import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.CompositeKey
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair

View File

@ -4,7 +4,7 @@ import net.corda.core.contracts.AuthenticatedObject
import net.corda.core.contracts.CommandData import net.corda.core.contracts.CommandData
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.TransactionForContract import net.corda.core.contracts.TransactionForContract
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import org.junit.Test import org.junit.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith

View File

@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.Command import net.corda.core.contracts.Command
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.requireThat import net.corda.core.contracts.requireThat
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction

View File

@ -3,8 +3,8 @@ package net.corda.core.flows
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.contracts.asset.Cash import net.corda.contracts.asset.Cash
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.contracts.testing.DummyContractV2 import net.corda.testing.contracts.DummyContractV2
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty

View File

@ -1,6 +1,6 @@
package net.corda.core.flows package net.corda.core.flows
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.Party import net.corda.core.identity.Party

View File

@ -20,6 +20,9 @@ UNRELEASED
* Mock identity constants used in tests, such as ``ALICE``, ``BOB``, ``DUMMY_NOTARY``, have moved to ``net.corda.testing`` * Mock identity constants used in tests, such as ``ALICE``, ``BOB``, ``DUMMY_NOTARY``, have moved to ``net.corda.testing``
in the ``test-utils`` module. in the ``test-utils`` module.
* ``DummyContract``, ``DummyContractV2``, ``DummyLinearContract`` and ``DummyState`` have moved to ``net.corda.testing.contracts``
in the ``test-utils`` modules.
* In Java, ``QueryCriteriaUtilsKt`` has moved to ``QueryCriteriaUtils``. Also ``and`` and ``or`` are now instance methods * In Java, ``QueryCriteriaUtilsKt`` has moved to ``QueryCriteriaUtils``. Also ``and`` and ``or`` are now instance methods
of ``QueryCrtieria``. of ``QueryCrtieria``.

View File

@ -86,7 +86,7 @@ Bank A and Bank B decided to upgrade the contract to ``DummyContractV2``
1. Developer will create a new contract extending the ``UpgradedContract`` class, and a new state object ``DummyContractV2.State`` referencing the new contract. 1. Developer will create a new contract extending the ``UpgradedContract`` class, and a new state object ``DummyContractV2.State`` referencing the new contract.
.. literalinclude:: /../../core/src/main/kotlin/net/corda/core/contracts/DummyContractV2.kt .. literalinclude:: /../../test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContractV2.kt
:language: kotlin :language: kotlin
:start-after: DOCSTART 1 :start-after: DOCSTART 1
:end-before: DOCEND 1 :end-before: DOCEND 1

View File

@ -7,8 +7,8 @@ import net.corda.contracts.asset.Cash;
import net.corda.core.contracts.*; import net.corda.core.contracts.*;
import net.corda.core.contracts.TransactionType.General; import net.corda.core.contracts.TransactionType.General;
import net.corda.core.contracts.TransactionType.NotaryChange; import net.corda.core.contracts.TransactionType.NotaryChange;
import net.corda.core.contracts.testing.DummyContract; import net.corda.testing.contracts.DummyContract;
import net.corda.core.contracts.testing.DummyState; import net.corda.testing.contracts.DummyState;
import net.corda.core.crypto.DigitalSignature; import net.corda.core.crypto.DigitalSignature;
import net.corda.core.crypto.SecureHash; import net.corda.core.crypto.SecureHash;
import net.corda.core.flows.*; import net.corda.core.flows.*;
@ -239,8 +239,8 @@ public class FlowCookbookJava {
// When building a transaction, input states are passed in as // When building a transaction, input states are passed in as
// ``StateRef`` instances, which pair the hash of the transaction // ``StateRef`` instances, which pair the hash of the transaction
// that generated the state with the state's index in the outputs // that generated the state with the state's index in the outputs
// of that transaction. In practice, we'd pass the transaction hash // of that transaction. In practice, we'd pass the transaction hash
// or the ``StateRef`` as a parameter to the flow, or extract the // or the ``StateRef`` as a parameter to the flow, or extract the
// ``StateRef`` from our vault. // ``StateRef`` from our vault.
// DOCSTART 20 // DOCSTART 20
StateRef ourStateRef = new StateRef(SecureHash.sha256("DummyTransactionHash"), 0); StateRef ourStateRef = new StateRef(SecureHash.sha256("DummyTransactionHash"), 0);
@ -381,10 +381,10 @@ public class FlowCookbookJava {
// DOCEND 39 // DOCEND 39
// We can also generate a signature over the transaction without // We can also generate a signature over the transaction without
// adding it to the transaction itself. We may do this when // adding it to the transaction itself. We may do this when
// sending just the signature in a flow instead of returning the // sending just the signature in a flow instead of returning the
// entire transaction with our signature. This way, the receiving // entire transaction with our signature. This way, the receiving
// node does not need to check we haven't changed anything in the // node does not need to check we haven't changed anything in the
// transaction. // transaction.
// DOCSTART 40 // DOCSTART 40
DigitalSignature.WithKey sig = getServiceHub().createSignature(onceSignedTx); DigitalSignature.WithKey sig = getServiceHub().createSignature(onceSignedTx);

View File

@ -5,8 +5,8 @@ import net.corda.contracts.asset.Cash
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.TransactionType.General import net.corda.core.contracts.TransactionType.General
import net.corda.core.contracts.TransactionType.NotaryChange import net.corda.core.contracts.TransactionType.NotaryChange
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.contracts.testing.DummyState import net.corda.testing.contracts.DummyState
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.flows.* import net.corda.core.flows.*
@ -222,8 +222,8 @@ object FlowCookbook {
// When building a transaction, input states are passed in as // When building a transaction, input states are passed in as
// ``StateRef`` instances, which pair the hash of the transaction // ``StateRef`` instances, which pair the hash of the transaction
// that generated the state with the state's index in the outputs // that generated the state with the state's index in the outputs
// of that transaction. In practice, we'd pass the transaction hash // of that transaction. In practice, we'd pass the transaction hash
// or the ``StateRef`` as a parameter to the flow, or extract the // or the ``StateRef`` as a parameter to the flow, or extract the
// ``StateRef`` from our vault. // ``StateRef`` from our vault.
// DOCSTART 20 // DOCSTART 20
val ourStateRef: StateRef = StateRef(SecureHash.sha256("DummyTransactionHash"), 0) val ourStateRef: StateRef = StateRef(SecureHash.sha256("DummyTransactionHash"), 0)
@ -362,10 +362,10 @@ object FlowCookbook {
// DOCEND 39 // DOCEND 39
// We can also generate a signature over the transaction without // We can also generate a signature over the transaction without
// adding it to the transaction itself. We may do this when // adding it to the transaction itself. We may do this when
// sending just the signature in a flow instead of returning the // sending just the signature in a flow instead of returning the
// entire transaction with our signature. This way, the receiving // entire transaction with our signature. This way, the receiving
// node does not need to check we haven't changed anything in the // node does not need to check we haven't changed anything in the
// transaction. // transaction.
// DOCSTART 40 // DOCSTART 40
val sig: DigitalSignature.WithKey = serviceHub.createSignature(onceSignedTx) val sig: DigitalSignature.WithKey = serviceHub.createSignature(onceSignedTx)

View File

@ -2,7 +2,7 @@ package net.corda.contracts.asset
import net.corda.testing.contracts.fillWithSomeTestCash import net.corda.testing.contracts.fillWithSomeTestCash
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyState import net.corda.testing.contracts.DummyState
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty

View File

@ -4,7 +4,7 @@ import net.corda.contracts.Commodity
import net.corda.contracts.NetType import net.corda.contracts.NetType
import net.corda.contracts.asset.Obligation.Lifecycle import net.corda.contracts.asset.Obligation.Lifecycle
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyState import net.corda.testing.contracts.DummyState
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.hours import net.corda.core.hours
import net.corda.core.crypto.testing.NULL_PARTY import net.corda.core.crypto.testing.NULL_PARTY

View File

@ -8,7 +8,7 @@ import io.requery.rx.KotlinRxEntityStore
import io.requery.sql.* import io.requery.sql.*
import io.requery.sql.platform.Generic import io.requery.sql.platform.Generic
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.CompositeKey
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair

View File

@ -5,7 +5,7 @@ import net.corda.core.ErrorOr
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.CompositeKey
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.div import net.corda.core.div

View File

@ -4,7 +4,7 @@ import com.google.common.util.concurrent.Futures
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.map import net.corda.core.map

View File

@ -5,7 +5,7 @@ import kotlin.Pair;
import net.corda.contracts.DealState; import net.corda.contracts.DealState;
import net.corda.contracts.asset.Cash; import net.corda.contracts.asset.Cash;
import net.corda.core.contracts.*; import net.corda.core.contracts.*;
import net.corda.core.contracts.testing.DummyLinearContract; import net.corda.testing.contracts.DummyLinearContract;
import net.corda.core.crypto.*; import net.corda.core.crypto.*;
import net.corda.core.identity.AbstractParty; import net.corda.core.identity.AbstractParty;
import net.corda.core.messaging.DataFeed; import net.corda.core.messaging.DataFeed;

View File

@ -1,7 +1,7 @@
package net.corda.node.services package net.corda.node.services
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.identity.Party import net.corda.core.identity.Party

View File

@ -5,7 +5,7 @@ import io.requery.kotlin.eq
import io.requery.sql.KotlinEntityDataStore import io.requery.sql.KotlinEntityDataStore
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.testing.NullPublicKey import net.corda.core.crypto.testing.NullPublicKey

View File

@ -2,7 +2,7 @@ package net.corda.node.services.events
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.containsAny import net.corda.core.crypto.containsAny
import net.corda.core.flows.FlowInitiator import net.corda.core.flows.FlowInitiator
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic

View File

@ -8,7 +8,7 @@ import net.corda.core.*
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.DOLLARS import net.corda.core.contracts.DOLLARS
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.testing.DummyState import net.corda.testing.contracts.DummyState
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.generateKeyPair import net.corda.core.crypto.generateKeyPair
import net.corda.core.crypto.random63BitValue import net.corda.core.crypto.random63BitValue

View File

@ -4,7 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo

View File

@ -5,7 +5,7 @@ import net.corda.core.contracts.Command
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.DigitalSignature
import net.corda.core.getOrThrow import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo import net.corda.core.node.services.ServiceInfo

View File

@ -6,7 +6,7 @@ import net.corda.contracts.DealState
import net.corda.contracts.asset.Cash import net.corda.contracts.asset.Cash
import net.corda.contracts.asset.DUMMY_CASH_ISSUER import net.corda.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyLinearContract import net.corda.testing.contracts.DummyLinearContract
import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.crypto.toBase58String import net.corda.core.crypto.toBase58String
import net.corda.core.days import net.corda.core.days
@ -841,7 +841,7 @@ class VaultQueryTests {
} }
assertThat(states).hasSize(20) assertThat(states).hasSize(20)
assertThat(metadata.first().contractStateClassName).isEqualTo("net.corda.core.contracts.testing.DummyLinearContract\$State") assertThat(metadata.first().contractStateClassName).isEqualTo("net.corda.testing.contracts.DummyLinearContract\$State")
assertThat(metadata.first().status).isEqualTo(Vault.StateStatus.UNCONSUMED) // 0 = UNCONSUMED assertThat(metadata.first().status).isEqualTo(Vault.StateStatus.UNCONSUMED) // 0 = UNCONSUMED
assertThat(metadata.last().contractStateClassName).isEqualTo("net.corda.contracts.DummyDealContract\$State") assertThat(metadata.last().contractStateClassName).isEqualTo("net.corda.contracts.DummyDealContract\$State")
assertThat(metadata.last().status).isEqualTo(Vault.StateStatus.CONSUMED) // 1 = CONSUMED assertThat(metadata.last().status).isEqualTo(Vault.StateStatus.CONSUMED) // 1 = CONSUMED

View File

@ -7,7 +7,7 @@ import net.corda.testing.contracts.fillWithSomeTestCash
import net.corda.testing.contracts.fillWithSomeTestDeals import net.corda.testing.contracts.fillWithSomeTestDeals
import net.corda.testing.contracts.fillWithSomeTestLinearStates import net.corda.testing.contracts.fillWithSomeTestLinearStates
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyLinearContract import net.corda.testing.contracts.DummyLinearContract
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.node.services.VaultService import net.corda.core.node.services.VaultService
import net.corda.core.node.services.consumedStates import net.corda.core.node.services.consumedStates

View File

@ -1,7 +1,7 @@
package net.corda.notarydemo.flows package net.corda.notarydemo.flows
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.Party import net.corda.core.identity.Party

View File

@ -1,7 +1,7 @@
package net.corda.testing package net.corda.testing
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.seconds import net.corda.core.seconds

View File

@ -1,4 +1,4 @@
package net.corda.core.contracts.testing package net.corda.testing.contracts
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash

View File

@ -0,0 +1,61 @@
package net.corda.testing.contracts
import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash
import net.corda.core.identity.AbstractParty
import net.corda.core.transactions.WireTransaction
import net.corda.flows.ContractUpgradeFlow
// The dummy contract doesn't do anything useful. It exists for testing purposes.
val DUMMY_V2_PROGRAM_ID = DummyContractV2()
/**
* Dummy contract state for testing of the upgrade process.
*/
// DOCSTART 1
class DummyContractV2 : UpgradedContract<DummyContract.State, DummyContractV2.State> {
override val legacyContract = DummyContract::class.java
data class State(val magicNumber: Int = 0, val owners: List<AbstractParty>) : ContractState {
override val contract = DUMMY_V2_PROGRAM_ID
override val participants: List<AbstractParty> = owners
}
interface Commands : CommandData {
class Create : TypeOnlyCommandData(), Commands
class Move : TypeOnlyCommandData(), Commands
}
override fun upgrade(state: DummyContract.State): State {
return State(state.magicNumber, state.participants)
}
override fun verify(tx: TransactionForContract) {
if (tx.commands.any { it.value is UpgradeCommand }) ContractUpgradeFlow.verify(tx)
// Other verifications.
}
// The "empty contract"
override val legalContractReference: SecureHash = SecureHash.sha256("")
// DOCEND 1
/**
* Generate an upgrade transaction from [DummyContract].
*
* Note: This is a convenience helper method used for testing only.
*
* @return a pair of wire transaction, and a set of those who should sign the transaction for it to be valid.
*/
fun generateUpgradeFromV1(vararg states: StateAndRef<DummyContract.State>): Pair<WireTransaction, Set<AbstractParty>> {
val notary = states.map { it.state.notary }.single()
require(states.isNotEmpty())
val signees: Set<AbstractParty> = states.flatMap { it.state.data.participants }.distinct().toSet()
return Pair(TransactionType.General.Builder(notary).apply {
states.forEach {
addInputState(it)
addOutputState(upgrade(it.state.data))
addCommand(UpgradeCommand(DUMMY_V2_PROGRAM_ID.javaClass), signees.map { it.owningKey }.toList())
}
}.toWireTransaction(), signees)
}
}

View File

@ -1,36 +1,45 @@
package net.corda.core.contracts.testing package net.corda.testing.contracts
import net.corda.core.contracts.CommandData import net.corda.core.contracts.*
import net.corda.core.contracts.clauses.Clause
import net.corda.core.contracts.clauses.FilterOn import net.corda.core.contracts.clauses.FilterOn
import net.corda.core.contracts.clauses.verifyClause
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.containsAny import net.corda.core.crypto.containsAny
import net.corda.core.identity.AbstractParty
import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import net.corda.core.schemas.QueryableState
import net.corda.core.schemas.testing.DummyLinearStateSchemaV1 import net.corda.core.schemas.testing.DummyLinearStateSchemaV1
import net.corda.core.schemas.testing.DummyLinearStateSchemaV2 import net.corda.core.schemas.testing.DummyLinearStateSchemaV2
import java.time.LocalDateTime
import java.time.ZoneOffset.UTC
class DummyLinearContract : net.corda.core.contracts.Contract { class DummyLinearContract : Contract {
override val legalContractReference: net.corda.core.crypto.SecureHash = net.corda.core.crypto.SecureHash.Companion.sha256("Test") override val legalContractReference: SecureHash = SecureHash.sha256("Test")
val clause: net.corda.core.contracts.clauses.Clause<State, CommandData, Unit> = net.corda.core.contracts.LinearState.ClauseVerifier() val clause: Clause<State, CommandData, Unit> = LinearState.ClauseVerifier()
override fun verify(tx: net.corda.core.contracts.TransactionForContract) = net.corda.core.contracts.clauses.verifyClause(tx, override fun verify(tx: TransactionForContract) = verifyClause(tx,
FilterOn(clause, { states -> states.filterIsInstance<State>() }), FilterOn(clause, { states -> states.filterIsInstance<State>() }),
emptyList()) emptyList())
data class State( data class State(
override val linearId: net.corda.core.contracts.UniqueIdentifier = net.corda.core.contracts.UniqueIdentifier(), override val linearId: UniqueIdentifier = UniqueIdentifier(),
override val contract: net.corda.core.contracts.Contract = net.corda.core.contracts.testing.DummyLinearContract(), override val contract: Contract = DummyLinearContract(),
override val participants: List<net.corda.core.identity.AbstractParty> = listOf(), override val participants: List<AbstractParty> = listOf(),
val linearString: String = "ABC", val linearString: String = "ABC",
val linearNumber: Long = 123L, val linearNumber: Long = 123L,
val linearTimestamp: java.time.Instant = java.time.LocalDateTime.now().toInstant(java.time.ZoneOffset.UTC), val linearTimestamp: java.time.Instant = LocalDateTime.now().toInstant(UTC),
val linearBoolean: Boolean = true, val linearBoolean: Boolean = true,
val nonce: net.corda.core.crypto.SecureHash = net.corda.core.crypto.SecureHash.Companion.randomSHA256()) : net.corda.core.contracts.LinearState, net.corda.core.schemas.QueryableState { val nonce: SecureHash = SecureHash.randomSHA256()) : LinearState, QueryableState {
override fun isRelevant(ourKeys: Set<java.security.PublicKey>): Boolean { override fun isRelevant(ourKeys: Set<java.security.PublicKey>): Boolean {
return participants.any { it.owningKey.containsAny(ourKeys) } return participants.any { it.owningKey.containsAny(ourKeys) }
} }
override fun supportedSchemas(): Iterable<net.corda.core.schemas.MappedSchema> = listOf(DummyLinearStateSchemaV1, DummyLinearStateSchemaV2) override fun supportedSchemas(): Iterable<MappedSchema> = listOf(DummyLinearStateSchemaV1, DummyLinearStateSchemaV2)
override fun generateMappedObject(schema: net.corda.core.schemas.MappedSchema): net.corda.core.schemas.PersistentState { override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) { return when (schema) {
is DummyLinearStateSchemaV1 -> DummyLinearStateSchemaV1.PersistentDummyLinearState( is DummyLinearStateSchemaV1 -> DummyLinearStateSchemaV1.PersistentDummyLinearState(
externalId = linearId.externalId, externalId = linearId.externalId,

View File

@ -0,0 +1,12 @@
package net.corda.testing.contracts
import net.corda.core.contracts.ContractState
import net.corda.core.identity.AbstractParty
/**
* Dummy state for use in testing. Not part of any contract, not even the [DummyContract].
*/
data class DummyState(val magicNumber: Int = 0) : ContractState {
override val contract = DUMMY_PROGRAM_ID
override val participants: List<AbstractParty> get() = emptyList()
}

View File

@ -7,7 +7,6 @@ import net.corda.contracts.DealState
import net.corda.contracts.DummyDealContract import net.corda.contracts.DummyDealContract
import net.corda.contracts.asset.* import net.corda.contracts.asset.*
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyLinearContract
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party

View File

@ -6,7 +6,7 @@ import net.corda.client.mock.pickOne
import net.corda.client.mock.replicate import net.corda.client.mock.replicate
import net.corda.contracts.asset.DUMMY_CASH_ISSUER import net.corda.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.flows.FlowException import net.corda.core.flows.FlowException
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.success import net.corda.core.success

View File

@ -2,7 +2,7 @@ package net.corda.verifier
import net.corda.client.mock.* import net.corda.client.mock.*
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.contracts.testing.DummyContract import net.corda.testing.contracts.DummyContract
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.X509Utilities import net.corda.core.crypto.X509Utilities
import net.corda.core.crypto.entropyToKeyPair import net.corda.core.crypto.entropyToKeyPair