diff --git a/experimental/src/main/kotlin/com/r3corda/contracts/Obligation.kt b/contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt similarity index 100% rename from experimental/src/main/kotlin/com/r3corda/contracts/Obligation.kt rename to contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt 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 d7f3dfc526..f0f0ef36f0 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/testing/TestUtils.kt @@ -14,7 +14,11 @@ import com.r3corda.core.contracts.TransactionState import com.r3corda.core.crypto.NullPublicKey import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.generateKeyPair +import com.r3corda.core.testing.MINI_CORP +import com.r3corda.core.testing.TEST_TX_TIME +import com.r3corda.core.utilities.nonEmptySetOf import java.security.PublicKey +import java.time.Instant import java.util.* // In a real system this would be a persistent map of hash to bytecode and we'd instantiate the object as needed inside @@ -56,6 +60,12 @@ object JavaTestHelpers { @JvmStatic fun withNotary(state: Cash.State, notary: Party) = TransactionState(state, notary) @JvmStatic fun withDeposit(state: Cash.State, deposit: PartyAndReference) = state.copy(amount = state.amount.copy(token = state.amount.token.copy(issuer = deposit))) + @JvmStatic fun at(state: Obligation.State, dueBefore: Instant) = state.copy(template = state.template.copy(dueBefore = dueBefore)) + @JvmStatic fun at(issuanceDef: Obligation.IssuanceDefinition, dueBefore: Instant) = issuanceDef.copy(template = issuanceDef.template.copy(dueBefore = dueBefore)) + @JvmStatic fun between(state: Obligation.State, parties: Pair) = state.copy(obligor = parties.first, beneficiary = parties.second) + @JvmStatic fun ownedBy(state: Obligation.State, owner: PublicKey) = state.copy(beneficiary = owner) + @JvmStatic fun issuedBy(state: Obligation.State, party: Party) = state.copy(obligor = party) + @JvmStatic fun ownedBy(state: CommercialPaper.State, owner: PublicKey) = state.copy(owner = owner) @JvmStatic fun withNotary(state: CommercialPaper.State, notary: Party) = TransactionState(state, notary) @JvmStatic fun ownedBy(state: ICommercialPaperState, new_owner: PublicKey) = state.withOwner(new_owner) @@ -66,6 +76,12 @@ object JavaTestHelpers { Amount>(amount.quantity, Issued(DUMMY_CASH_ISSUER, amount.token)), NullPublicKey) @JvmStatic fun STATE(amount: Amount>) = Cash.State(amount, NullPublicKey) + + // Allows you to write 100.DOLLARS.OBLIGATION + @JvmStatic fun OBLIGATION_DEF(issued: Issued) + = Obligation.StateTemplate(nonEmptySetOf(Cash().legalContractReference), nonEmptySetOf(issued), TEST_TX_TIME) + @JvmStatic fun OBLIGATION(amount: Amount>) = Obligation.State(Obligation.Lifecycle.NORMAL, MINI_CORP, + OBLIGATION_DEF(amount.token), amount.quantity, NullPublicKey) } @@ -75,6 +91,12 @@ infix fun Cash.State.`issued by`(deposit: PartyAndReference) = JavaTestHelpers.i infix fun Cash.State.`with notary`(notary: Party) = JavaTestHelpers.withNotary(this, notary) infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = JavaTestHelpers.withDeposit(this, deposit) +infix fun Obligation.State.`at`(dueBefore: Instant) = JavaTestHelpers.at(this, dueBefore) +infix fun Obligation.IssuanceDefinition.`at`(dueBefore: Instant) = JavaTestHelpers.at(this, dueBefore) +infix fun Obligation.State.`between`(parties: Pair) = JavaTestHelpers.between(this, parties) +infix fun Obligation.State.`owned by`(owner: PublicKey) = JavaTestHelpers.ownedBy(this, owner) +infix fun Obligation.State.`issued by`(party: Party) = JavaTestHelpers.issuedBy(this, party) + infix fun CommercialPaper.State.`owned by`(owner: PublicKey) = JavaTestHelpers.ownedBy(this, owner) infix fun CommercialPaper.State.`with notary`(notary: Party) = JavaTestHelpers.withNotary(this, notary) infix fun ICommercialPaperState.`owned by`(new_owner: PublicKey) = JavaTestHelpers.ownedBy(this, new_owner) @@ -87,3 +109,6 @@ val DUMMY_CASH_ISSUER = Party("Snake Oil Issuer", DUMMY_CASH_ISSUER_KEY.public). val Amount.CASH: Cash.State get() = JavaTestHelpers.CASH(this) val Amount>.STATE: Cash.State get() = JavaTestHelpers.STATE(this) +/** Allows you to write 100.DOLLARS.CASH */ +val Issued.OBLIGATION_DEF: Obligation.StateTemplate get() = JavaTestHelpers.OBLIGATION_DEF(this) +val Amount>.OBLIGATION: Obligation.State get() = JavaTestHelpers.OBLIGATION(this) diff --git a/experimental/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt similarity index 100% rename from experimental/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt rename to contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt diff --git a/experimental/src/main/kotlin/com/r3corda/contracts/testing/ExperimentalTestUtils.kt b/experimental/src/main/kotlin/com/r3corda/contracts/testing/ExperimentalTestUtils.kt deleted file mode 100644 index 112e5f03d6..0000000000 --- a/experimental/src/main/kotlin/com/r3corda/contracts/testing/ExperimentalTestUtils.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.r3corda.contracts.testing - -import com.r3corda.contracts.Obligation -import com.r3corda.contracts.cash.Cash -import com.r3corda.core.contracts.Amount -import com.r3corda.core.contracts.Issued -import com.r3corda.core.crypto.NullPublicKey -import com.r3corda.core.crypto.Party -import com.r3corda.core.testing.MINI_CORP -import com.r3corda.core.testing.TEST_TX_TIME -import com.r3corda.core.utilities.nonEmptySetOf -import java.security.PublicKey -import java.time.Instant -import java.util.* - -object JavaExperimental { - @JvmStatic fun at(state: Obligation.State, dueBefore: Instant) = state.copy(template = state.template.copy(dueBefore = dueBefore)) - @JvmStatic fun at(issuanceDef: Obligation.IssuanceDefinition, dueBefore: Instant) = issuanceDef.copy(template = issuanceDef.template.copy(dueBefore = dueBefore)) - @JvmStatic fun between(state: Obligation.State, parties: Pair) = state.copy(obligor = parties.first, beneficiary = parties.second) - @JvmStatic fun ownedBy(state: Obligation.State, owner: PublicKey) = state.copy(beneficiary = owner) - @JvmStatic fun issuedBy(state: Obligation.State, party: Party) = state.copy(obligor = party) - - // Allows you to write 100.DOLLARS.OBLIGATION - @JvmStatic fun OBLIGATION_DEF(issued: Issued) - = Obligation.StateTemplate(nonEmptySetOf(Cash().legalContractReference), nonEmptySetOf(issued), TEST_TX_TIME) - @JvmStatic fun OBLIGATION(amount: Amount>) = Obligation.State(Obligation.Lifecycle.NORMAL, MINI_CORP, - OBLIGATION_DEF(amount.token), amount.quantity, NullPublicKey) -} -infix fun Obligation.State.`at`(dueBefore: Instant) = JavaExperimental.at(this, dueBefore) -infix fun Obligation.IssuanceDefinition.`at`(dueBefore: Instant) = JavaExperimental.at(this, dueBefore) -infix fun Obligation.State.`between`(parties: Pair) = JavaExperimental.between(this, parties) -infix fun Obligation.State.`owned by`(owner: PublicKey) = JavaExperimental.ownedBy(this, owner) -infix fun Obligation.State.`issued by`(party: Party) = JavaExperimental.issuedBy(this, party) - -/** Allows you to write 100.DOLLARS.CASH */ -val Issued.OBLIGATION_DEF: Obligation.StateTemplate get() = JavaExperimental.OBLIGATION_DEF(this) -val Amount>.OBLIGATION: Obligation.State get() = JavaExperimental.OBLIGATION(this)