diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt b/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt index f0f0ef36f0..f3bc5eab21 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt @@ -5,11 +5,12 @@ import com.r3corda.contracts.cash.CASH_PROGRAM_ID import com.r3corda.contracts.cash.Cash import com.r3corda.core.contracts.Amount import com.r3corda.core.contracts.Contract +import com.r3corda.core.contracts.ContractState import com.r3corda.core.contracts.DUMMY_PROGRAM_ID import com.r3corda.core.contracts.DummyContract +import com.r3corda.core.contracts.DummyState import com.r3corda.core.contracts.PartyAndReference import com.r3corda.core.contracts.Issued -import com.r3corda.core.contracts.ContractState import com.r3corda.core.contracts.TransactionState import com.r3corda.core.crypto.NullPublicKey import com.r3corda.core.crypto.Party @@ -31,7 +32,7 @@ val TEST_PROGRAM_MAP: Map> = mapOf( IRS_PROGRAM_ID to InterestRateSwap::class.java ) -fun generateState() = DummyContract.State(Random().nextInt()) +fun generateState() = DummyState(Random().nextInt()) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt index 3a9f9e1fdd..c9ba546142 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt @@ -80,7 +80,7 @@ class ObligationTests { fun `issue debt`() { // Check we can't "move" debt into existence. transaction { - input { DummyContract.State() } + input { DummyState() } output { outState } arg(MINI_CORP_PUBKEY) { Obligation.Commands.Move(outState.issuanceDef) } diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/cash/CashTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/cash/CashTests.kt index 0b0e355720..000a7bb959 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/cash/CashTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/cash/CashTests.kt @@ -66,7 +66,7 @@ class CashTests { fun issueMoney() { // Check we can't "move" money into existence. transaction { - input { DummyContract.State() } + input { DummyState() } output { outState } arg(MINI_CORP_PUBKEY) { Cash.Commands.Move() } diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/DummyContract.kt b/core/src/main/kotlin/com/r3corda/core/contracts/DummyContract.kt index 41038e128b..66358cebd5 100644 --- a/core/src/main/kotlin/com/r3corda/core/contracts/DummyContract.kt +++ b/core/src/main/kotlin/com/r3corda/core/contracts/DummyContract.kt @@ -9,13 +9,12 @@ import java.security.PublicKey val DUMMY_PROGRAM_ID = DummyContract() class DummyContract : Contract { - data class State(val magicNumber: Int = 0) : ContractState { - override val contract = DUMMY_PROGRAM_ID - override val participants: List - get() = emptyList() + + interface State : ContractState { + val magicNumber: Int } - data class SingleOwnerState(val magicNumber: Int = 0, override val owner: PublicKey) : OwnableState { + data class SingleOwnerState(override val magicNumber: Int = 0, override val owner: PublicKey) : OwnableState, State { override val contract = DUMMY_PROGRAM_ID override val participants: List get() = listOf(owner) @@ -23,8 +22,13 @@ class DummyContract : Contract { override fun withNewOwner(newOwner: PublicKey) = Pair(Commands.Move(), copy(owner = newOwner)) } - data class MultiOwnerState(val magicNumber: Int = 0, - val owners: List) : ContractState { + /** + * Alternative state with multiple owners. This exists primarily to provide a dummy state with multiple + * participants, and could in theory be merged with [SingleOwnerState] by putting the additional participants + * in a different field, however this is a good example of a contract with multiple states. + */ + data class MultiOwnerState(override val magicNumber: Int = 0, + val owners: List) : ContractState, State { override val contract = DUMMY_PROGRAM_ID override val participants: List get() = owners diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/DummyState.kt b/core/src/main/kotlin/com/r3corda/core/contracts/DummyState.kt new file mode 100644 index 0000000000..1f6fb6df2c --- /dev/null +++ b/core/src/main/kotlin/com/r3corda/core/contracts/DummyState.kt @@ -0,0 +1,12 @@ +package com.r3corda.core.contracts + +import java.security.PublicKey + +/** + * Dummy state for use in testing. Not part of any real contract. + */ +data class DummyState(val magicNumber: Int = 0) : ContractState { + override val contract = DUMMY_PROGRAM_ID + override val participants: List + get() = emptyList() +} \ No newline at end of file diff --git a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt index 195fde036f..a6630302f3 100644 --- a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt +++ b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt @@ -28,12 +28,12 @@ class TransactionGraphSearchTests { */ fun buildTransactions(command: CommandData, signer: KeyPair): GraphTransactionStorage { val originTx = TransactionType.General.Builder().apply { - addOutputState(DummyContract.State(random31BitValue()), DUMMY_NOTARY) + addOutputState(DummyState(random31BitValue()), DUMMY_NOTARY) addCommand(command, signer.public) signWith(signer) }.toSignedTransaction(false) val inputTx = TransactionType.General.Builder().apply { - addInputState(originTx.tx.outRef(0)) + addInputState(originTx.tx.outRef(0)) signWith(signer) }.toSignedTransaction(false) return GraphTransactionStorage(originTx, inputTx)