diff --git a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyContractV2.kt b/core/src/main/kotlin/net/corda/core/contracts/testing/DummyContractV2.kt deleted file mode 100644 index 5e6be3631e..0000000000 --- a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyContractV2.kt +++ /dev/null @@ -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 { - override val legacyContract = DummyContract::class.java - - data class State(val magicNumber: Int = 0, val owners: List) : net.corda.core.contracts.ContractState { - override val contract = net.corda.core.contracts.testing.DUMMY_V2_PROGRAM_ID - override val participants: List = 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): Pair> { - val notary = states.map { it.state.notary }.single() - require(states.isNotEmpty()) - - val signees: Set = 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) - } -} diff --git a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyState.kt b/core/src/main/kotlin/net/corda/core/contracts/testing/DummyState.kt deleted file mode 100644 index 6c852bb33d..0000000000 --- a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyState.kt +++ /dev/null @@ -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 - get() = emptyList() -} diff --git a/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt b/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt index 81274dfa52..e059dd2e1e 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/DummyContractV2Tests.kt @@ -1,7 +1,7 @@ package net.corda.core.contracts -import net.corda.core.contracts.testing.DummyContract -import net.corda.core.contracts.testing.DummyContractV2 +import net.corda.testing.contracts.DummyContract +import net.corda.testing.contracts.DummyContractV2 import net.corda.core.crypto.SecureHash import net.corda.testing.ALICE import net.corda.testing.DUMMY_NOTARY diff --git a/core/src/test/kotlin/net/corda/core/contracts/TransactionGraphSearchTests.kt b/core/src/test/kotlin/net/corda/core/contracts/TransactionGraphSearchTests.kt index f48e5b920b..8f55aa7317 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/TransactionGraphSearchTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/TransactionGraphSearchTests.kt @@ -1,7 +1,7 @@ package net.corda.core.contracts -import net.corda.core.contracts.testing.DummyContract -import net.corda.core.contracts.testing.DummyState +import net.corda.testing.contracts.DummyContract +import net.corda.testing.contracts.DummyState import net.corda.core.crypto.newSecureRandom import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.WireTransaction diff --git a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt index f4bbe7f3f4..ffb3faeb4c 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/TransactionTests.kt @@ -1,7 +1,7 @@ package net.corda.core.contracts 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.SecureHash import net.corda.core.crypto.generateKeyPair diff --git a/core/src/test/kotlin/net/corda/core/contracts/clauses/VerifyClausesTests.kt b/core/src/test/kotlin/net/corda/core/contracts/clauses/VerifyClausesTests.kt index 076d7e2854..4627f1baa2 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/clauses/VerifyClausesTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/clauses/VerifyClausesTests.kt @@ -4,7 +4,7 @@ import net.corda.core.contracts.AuthenticatedObject import net.corda.core.contracts.CommandData import net.corda.core.contracts.ContractState 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 org.junit.Test import kotlin.test.assertFailsWith diff --git a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt index fdc472ab1e..8bccd7666c 100644 --- a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt @@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.Command import net.corda.core.contracts.TransactionType 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.identity.Party import net.corda.core.transactions.SignedTransaction diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt index 3f8cfae6ae..1ee8601e34 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt @@ -3,8 +3,8 @@ package net.corda.core.flows import co.paralleluniverse.fibers.Suspendable import net.corda.contracts.asset.Cash import net.corda.core.contracts.* -import net.corda.core.contracts.testing.DummyContract -import net.corda.core.contracts.testing.DummyContractV2 +import net.corda.testing.contracts.DummyContract +import net.corda.testing.contracts.DummyContractV2 import net.corda.core.crypto.SecureHash import net.corda.core.getOrThrow import net.corda.core.identity.AbstractParty diff --git a/core/src/test/kotlin/net/corda/core/flows/ResolveTransactionsFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ResolveTransactionsFlowTest.kt index 2336298996..341f9b0d5d 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ResolveTransactionsFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ResolveTransactionsFlowTest.kt @@ -1,6 +1,6 @@ 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.getOrThrow import net.corda.core.identity.Party diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index c2ab1cfba8..fa674479d4 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -20,6 +20,9 @@ UNRELEASED * Mock identity constants used in tests, such as ``ALICE``, ``BOB``, ``DUMMY_NOTARY``, have moved to ``net.corda.testing`` 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 of ``QueryCrtieria``. diff --git a/docs/source/contract-upgrade.rst b/docs/source/contract-upgrade.rst index e448ade570..5d7298b36b 100644 --- a/docs/source/contract-upgrade.rst +++ b/docs/source/contract-upgrade.rst @@ -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. -.. 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 :start-after: DOCSTART 1 :end-before: DOCEND 1 diff --git a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java index 8d5d16364d..cf188f4e2c 100644 --- a/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java +++ b/docs/source/example-code/src/main/java/net/corda/docs/FlowCookbookJava.java @@ -7,8 +7,8 @@ import net.corda.contracts.asset.Cash; import net.corda.core.contracts.*; import net.corda.core.contracts.TransactionType.General; import net.corda.core.contracts.TransactionType.NotaryChange; -import net.corda.core.contracts.testing.DummyContract; -import net.corda.core.contracts.testing.DummyState; +import net.corda.testing.contracts.DummyContract; +import net.corda.testing.contracts.DummyState; import net.corda.core.crypto.DigitalSignature; import net.corda.core.crypto.SecureHash; import net.corda.core.flows.*; @@ -239,8 +239,8 @@ public class FlowCookbookJava { // When building a transaction, input states are passed in as // ``StateRef`` instances, which pair the hash of the transaction // that generated the state with the state's index in the outputs - // of that transaction. In practice, we'd pass the transaction hash - // or the ``StateRef`` as a parameter to the flow, or extract the + // of that transaction. In practice, we'd pass the transaction hash + // or the ``StateRef`` as a parameter to the flow, or extract the // ``StateRef`` from our vault. // DOCSTART 20 StateRef ourStateRef = new StateRef(SecureHash.sha256("DummyTransactionHash"), 0); @@ -381,10 +381,10 @@ public class FlowCookbookJava { // DOCEND 39 // We can also generate a signature over the transaction without - // adding it to the transaction itself. We may do this when - // sending just the signature in a flow instead of returning the - // entire transaction with our signature. This way, the receiving - // node does not need to check we haven't changed anything in the + // adding it to the transaction itself. We may do this when + // sending just the signature in a flow instead of returning the + // entire transaction with our signature. This way, the receiving + // node does not need to check we haven't changed anything in the // transaction. // DOCSTART 40 DigitalSignature.WithKey sig = getServiceHub().createSignature(onceSignedTx); diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt index 14053980cc..6414d50f9b 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/FlowCookbook.kt @@ -5,8 +5,8 @@ import net.corda.contracts.asset.Cash import net.corda.core.contracts.* import net.corda.core.contracts.TransactionType.General import net.corda.core.contracts.TransactionType.NotaryChange -import net.corda.core.contracts.testing.DummyContract -import net.corda.core.contracts.testing.DummyState +import net.corda.testing.contracts.DummyContract +import net.corda.testing.contracts.DummyState import net.corda.core.crypto.DigitalSignature import net.corda.core.crypto.SecureHash import net.corda.core.flows.* @@ -222,8 +222,8 @@ object FlowCookbook { // When building a transaction, input states are passed in as // ``StateRef`` instances, which pair the hash of the transaction // that generated the state with the state's index in the outputs - // of that transaction. In practice, we'd pass the transaction hash - // or the ``StateRef`` as a parameter to the flow, or extract the + // of that transaction. In practice, we'd pass the transaction hash + // or the ``StateRef`` as a parameter to the flow, or extract the // ``StateRef`` from our vault. // DOCSTART 20 val ourStateRef: StateRef = StateRef(SecureHash.sha256("DummyTransactionHash"), 0) @@ -362,10 +362,10 @@ object FlowCookbook { // DOCEND 39 // We can also generate a signature over the transaction without - // adding it to the transaction itself. We may do this when - // sending just the signature in a flow instead of returning the - // entire transaction with our signature. This way, the receiving - // node does not need to check we haven't changed anything in the + // adding it to the transaction itself. We may do this when + // sending just the signature in a flow instead of returning the + // entire transaction with our signature. This way, the receiving + // node does not need to check we haven't changed anything in the // transaction. // DOCSTART 40 val sig: DigitalSignature.WithKey = serviceHub.createSignature(onceSignedTx) diff --git a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt index d08d9e36c4..5a0771ed3d 100644 --- a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt @@ -2,7 +2,7 @@ package net.corda.contracts.asset import net.corda.testing.contracts.fillWithSomeTestCash 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.generateKeyPair import net.corda.core.identity.AbstractParty diff --git a/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt b/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt index 78f2a65759..5d393f71db 100644 --- a/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/asset/ObligationTests.kt @@ -4,7 +4,7 @@ import net.corda.contracts.Commodity import net.corda.contracts.NetType import net.corda.contracts.asset.Obligation.Lifecycle 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.hours import net.corda.core.crypto.testing.NULL_PARTY diff --git a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt index b597a8188d..879f7dd5f0 100644 --- a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt +++ b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt @@ -8,7 +8,7 @@ import io.requery.rx.KotlinRxEntityStore import io.requery.sql.* import io.requery.sql.platform.Generic 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.SecureHash import net.corda.core.crypto.generateKeyPair diff --git a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt index e996f9d43b..0f8a0c40e4 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/BFTNotaryServiceTests.kt @@ -5,7 +5,7 @@ import net.corda.core.ErrorOr import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateRef 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.SecureHash import net.corda.core.div diff --git a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt index 1075e83ad2..566c4674e1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt @@ -4,7 +4,7 @@ import com.google.common.util.concurrent.Futures import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef 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.identity.Party import net.corda.core.map diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index e2ffa4359d..d88d023b5c 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -5,7 +5,7 @@ import kotlin.Pair; import net.corda.contracts.DealState; import net.corda.contracts.asset.Cash; 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.identity.AbstractParty; import net.corda.core.messaging.DataFeed; diff --git a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt index b47ee4d0a0..8aef7f445e 100644 --- a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt @@ -1,7 +1,7 @@ package net.corda.node.services 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.getOrThrow import net.corda.core.identity.Party diff --git a/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt index b0f5f06787..ec8f6a57d2 100644 --- a/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/database/RequeryConfigurationTest.kt @@ -5,7 +5,7 @@ import io.requery.kotlin.eq import io.requery.sql.KotlinEntityDataStore import net.corda.core.contracts.StateRef 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.SecureHash import net.corda.core.crypto.testing.NullPublicKey diff --git a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt index 37b26f174f..6fec905bae 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt @@ -2,7 +2,7 @@ package net.corda.node.services.events import co.paralleluniverse.fibers.Suspendable 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.flows.FlowInitiator import net.corda.core.flows.FlowLogic diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index 26ea5b06f3..f83de31b69 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -8,7 +8,7 @@ import net.corda.core.* import net.corda.core.contracts.ContractState import net.corda.core.contracts.DOLLARS 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.generateKeyPair import net.corda.core.crypto.random63BitValue diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt index a553fb8b26..c0da57821c 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt @@ -4,7 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef 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.getOrThrow import net.corda.core.node.services.ServiceInfo diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt index 05bfb68c69..3072677dfd 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt @@ -5,7 +5,7 @@ import net.corda.core.contracts.Command import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef 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.getOrThrow import net.corda.core.node.services.ServiceInfo diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 1d2fbd7cbf..0ff47da943 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -6,7 +6,7 @@ import net.corda.contracts.DealState import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER 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.toBase58String import net.corda.core.days @@ -841,7 +841,7 @@ class VaultQueryTests { } 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.last().contractStateClassName).isEqualTo("net.corda.contracts.DummyDealContract\$State") assertThat(metadata.last().status).isEqualTo(Vault.StateStatus.CONSUMED) // 1 = CONSUMED diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 50314208d4..02686c72b7 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -7,7 +7,7 @@ import net.corda.testing.contracts.fillWithSomeTestCash import net.corda.testing.contracts.fillWithSomeTestDeals import net.corda.testing.contracts.fillWithSomeTestLinearStates 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.node.services.VaultService import net.corda.core.node.services.consumedStates diff --git a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt index bfd75f00d5..50f51bc9e1 100644 --- a/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt +++ b/samples/notary-demo/src/main/kotlin/net/corda/notarydemo/flows/DummyIssueAndMove.kt @@ -1,7 +1,7 @@ package net.corda.notarydemo.flows 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.StartableByRPC import net.corda.core.identity.Party diff --git a/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt b/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt index bb660ac058..cb973e022f 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/TransactionDSLInterpreter.kt @@ -1,7 +1,7 @@ package net.corda.testing 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.identity.Party import net.corda.core.seconds diff --git a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyContract.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContract.kt similarity index 98% rename from core/src/main/kotlin/net/corda/core/contracts/testing/DummyContract.kt rename to test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContract.kt index 5edc0d4f19..e7a96d9a0b 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyContract.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContract.kt @@ -1,4 +1,4 @@ -package net.corda.core.contracts.testing +package net.corda.testing.contracts import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContractV2.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContractV2.kt new file mode 100644 index 0000000000..b14b55937f --- /dev/null +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyContractV2.kt @@ -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 { + override val legacyContract = DummyContract::class.java + + data class State(val magicNumber: Int = 0, val owners: List) : ContractState { + override val contract = DUMMY_V2_PROGRAM_ID + override val participants: List = 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): Pair> { + val notary = states.map { it.state.notary }.single() + require(states.isNotEmpty()) + + val signees: Set = 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) + } +} diff --git a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyLinearContract.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt similarity index 52% rename from core/src/main/kotlin/net/corda/core/contracts/testing/DummyLinearContract.kt rename to test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt index 2723de3a61..46519730cf 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/testing/DummyLinearContract.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyLinearContract.kt @@ -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.verifyClause +import net.corda.core.crypto.SecureHash 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.DummyLinearStateSchemaV2 +import java.time.LocalDateTime +import java.time.ZoneOffset.UTC -class DummyLinearContract : net.corda.core.contracts.Contract { - override val legalContractReference: net.corda.core.crypto.SecureHash = net.corda.core.crypto.SecureHash.Companion.sha256("Test") +class DummyLinearContract : Contract { + override val legalContractReference: SecureHash = SecureHash.sha256("Test") - val clause: net.corda.core.contracts.clauses.Clause = net.corda.core.contracts.LinearState.ClauseVerifier() - override fun verify(tx: net.corda.core.contracts.TransactionForContract) = net.corda.core.contracts.clauses.verifyClause(tx, + val clause: Clause = LinearState.ClauseVerifier() + override fun verify(tx: TransactionForContract) = verifyClause(tx, FilterOn(clause, { states -> states.filterIsInstance() }), emptyList()) data class State( - override val linearId: net.corda.core.contracts.UniqueIdentifier = net.corda.core.contracts.UniqueIdentifier(), - override val contract: net.corda.core.contracts.Contract = net.corda.core.contracts.testing.DummyLinearContract(), - override val participants: List = listOf(), + override val linearId: UniqueIdentifier = UniqueIdentifier(), + override val contract: Contract = DummyLinearContract(), + override val participants: List = listOf(), val linearString: String = "ABC", 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 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): Boolean { return participants.any { it.owningKey.containsAny(ourKeys) } } - override fun supportedSchemas(): Iterable = listOf(DummyLinearStateSchemaV1, DummyLinearStateSchemaV2) + override fun supportedSchemas(): Iterable = 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) { is DummyLinearStateSchemaV1 -> DummyLinearStateSchemaV1.PersistentDummyLinearState( externalId = linearId.externalId, diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyState.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyState.kt new file mode 100644 index 0000000000..c2e0696889 --- /dev/null +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyState.kt @@ -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 get() = emptyList() +} diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt index 9ee4f513c2..0c39d2746e 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt @@ -7,7 +7,6 @@ import net.corda.contracts.DealState import net.corda.contracts.DummyDealContract import net.corda.contracts.asset.* import net.corda.core.contracts.* -import net.corda.core.contracts.testing.DummyLinearContract import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt index 5638dc8e1b..9c3486538d 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/tests/NotaryTest.kt @@ -6,7 +6,7 @@ import net.corda.client.mock.pickOne import net.corda.client.mock.replicate import net.corda.contracts.asset.DUMMY_CASH_ISSUER 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.messaging.startFlow import net.corda.core.success diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt index 8962c5d230..fafc621c2e 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/GeneratedLedger.kt @@ -2,7 +2,7 @@ package net.corda.verifier import net.corda.client.mock.* 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.X509Utilities import net.corda.core.crypto.entropyToKeyPair