mirror of
https://github.com/corda/corda.git
synced 2025-06-19 15:43:52 +00:00
Move DummyContract.State into its own file
DummyContract.State isn't actually used by the DummyContract any more, so shouldn't be part of that contract class.
This commit is contained in:
@ -5,11 +5,12 @@ import com.r3corda.contracts.cash.CASH_PROGRAM_ID
|
|||||||
import com.r3corda.contracts.cash.Cash
|
import com.r3corda.contracts.cash.Cash
|
||||||
import com.r3corda.core.contracts.Amount
|
import com.r3corda.core.contracts.Amount
|
||||||
import com.r3corda.core.contracts.Contract
|
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.DUMMY_PROGRAM_ID
|
||||||
import com.r3corda.core.contracts.DummyContract
|
import com.r3corda.core.contracts.DummyContract
|
||||||
|
import com.r3corda.core.contracts.DummyState
|
||||||
import com.r3corda.core.contracts.PartyAndReference
|
import com.r3corda.core.contracts.PartyAndReference
|
||||||
import com.r3corda.core.contracts.Issued
|
import com.r3corda.core.contracts.Issued
|
||||||
import com.r3corda.core.contracts.ContractState
|
|
||||||
import com.r3corda.core.contracts.TransactionState
|
import com.r3corda.core.contracts.TransactionState
|
||||||
import com.r3corda.core.crypto.NullPublicKey
|
import com.r3corda.core.crypto.NullPublicKey
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
@ -31,7 +32,7 @@ val TEST_PROGRAM_MAP: Map<Contract, Class<out Contract>> = mapOf(
|
|||||||
IRS_PROGRAM_ID to InterestRateSwap::class.java
|
IRS_PROGRAM_ID to InterestRateSwap::class.java
|
||||||
)
|
)
|
||||||
|
|
||||||
fun generateState() = DummyContract.State(Random().nextInt())
|
fun generateState() = DummyState(Random().nextInt())
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -80,7 +80,7 @@ class ObligationTests {
|
|||||||
fun `issue debt`() {
|
fun `issue debt`() {
|
||||||
// Check we can't "move" debt into existence.
|
// Check we can't "move" debt into existence.
|
||||||
transaction {
|
transaction {
|
||||||
input { DummyContract.State() }
|
input { DummyState() }
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(MINI_CORP_PUBKEY) { Obligation.Commands.Move(outState.issuanceDef) }
|
arg(MINI_CORP_PUBKEY) { Obligation.Commands.Move(outState.issuanceDef) }
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class CashTests {
|
|||||||
fun issueMoney() {
|
fun issueMoney() {
|
||||||
// Check we can't "move" money into existence.
|
// Check we can't "move" money into existence.
|
||||||
transaction {
|
transaction {
|
||||||
input { DummyContract.State() }
|
input { DummyState() }
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
|
arg(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
|
||||||
|
|
||||||
|
@ -9,13 +9,12 @@ import java.security.PublicKey
|
|||||||
val DUMMY_PROGRAM_ID = DummyContract()
|
val DUMMY_PROGRAM_ID = DummyContract()
|
||||||
|
|
||||||
class DummyContract : Contract {
|
class DummyContract : Contract {
|
||||||
data class State(val magicNumber: Int = 0) : ContractState {
|
|
||||||
override val contract = DUMMY_PROGRAM_ID
|
interface State : ContractState {
|
||||||
override val participants: List<PublicKey>
|
val magicNumber: Int
|
||||||
get() = emptyList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 contract = DUMMY_PROGRAM_ID
|
||||||
override val participants: List<PublicKey>
|
override val participants: List<PublicKey>
|
||||||
get() = listOf(owner)
|
get() = listOf(owner)
|
||||||
@ -23,8 +22,13 @@ class DummyContract : Contract {
|
|||||||
override fun withNewOwner(newOwner: PublicKey) = Pair(Commands.Move(), copy(owner = newOwner))
|
override fun withNewOwner(newOwner: PublicKey) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||||
}
|
}
|
||||||
|
|
||||||
data class MultiOwnerState(val magicNumber: Int = 0,
|
/**
|
||||||
val owners: List<PublicKey>) : 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<PublicKey>) : ContractState, State {
|
||||||
override val contract = DUMMY_PROGRAM_ID
|
override val contract = DUMMY_PROGRAM_ID
|
||||||
override val participants: List<PublicKey>
|
override val participants: List<PublicKey>
|
||||||
get() = owners
|
get() = owners
|
||||||
|
@ -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<PublicKey>
|
||||||
|
get() = emptyList()
|
||||||
|
}
|
@ -28,12 +28,12 @@ class TransactionGraphSearchTests {
|
|||||||
*/
|
*/
|
||||||
fun buildTransactions(command: CommandData, signer: KeyPair): GraphTransactionStorage {
|
fun buildTransactions(command: CommandData, signer: KeyPair): GraphTransactionStorage {
|
||||||
val originTx = TransactionType.General.Builder().apply {
|
val originTx = TransactionType.General.Builder().apply {
|
||||||
addOutputState(DummyContract.State(random31BitValue()), DUMMY_NOTARY)
|
addOutputState(DummyState(random31BitValue()), DUMMY_NOTARY)
|
||||||
addCommand(command, signer.public)
|
addCommand(command, signer.public)
|
||||||
signWith(signer)
|
signWith(signer)
|
||||||
}.toSignedTransaction(false)
|
}.toSignedTransaction(false)
|
||||||
val inputTx = TransactionType.General.Builder().apply {
|
val inputTx = TransactionType.General.Builder().apply {
|
||||||
addInputState(originTx.tx.outRef<DummyContract.State>(0))
|
addInputState(originTx.tx.outRef<DummyState>(0))
|
||||||
signWith(signer)
|
signWith(signer)
|
||||||
}.toSignedTransaction(false)
|
}.toSignedTransaction(false)
|
||||||
return GraphTransactionStorage(originTx, inputTx)
|
return GraphTransactionStorage(originTx, inputTx)
|
||||||
|
Reference in New Issue
Block a user