diff --git a/experimental/src/main/kotlin/net/corda/contracts/universal/Perceivable.kt b/experimental/src/main/kotlin/net/corda/contracts/universal/Perceivable.kt index 1a67f87c08..0e428f4ec8 100644 --- a/experimental/src/main/kotlin/net/corda/contracts/universal/Perceivable.kt +++ b/experimental/src/main/kotlin/net/corda/contracts/universal/Perceivable.kt @@ -151,9 +151,6 @@ class DummyPerceivable : Perceivable data class Interest(val amount: Perceivable, val dayCountConvention: String, val interest: Perceivable, val start: Perceivable, val end: Perceivable) : Perceivable -fun libor(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") start: String, @Suppress("UNUSED_PARAMETER") end: String): Perceivable = DummyPerceivable() -fun libor(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") start: Perceivable, @Suppress("UNUSED_PARAMETER") end: Perceivable): Perceivable = DummyPerceivable() - fun interest(@Suppress("UNUSED_PARAMETER") amount: BigDecimal, @Suppress("UNUSED_PARAMETER") dayCountConvention: String, @Suppress("UNUSED_PARAMETER") interest: BigDecimal /* todo - appropriate type */, @Suppress("UNUSED_PARAMETER") start: String, @Suppress("UNUSED_PARAMETER") end: String): Perceivable = Interest(Const(amount), dayCountConvention, Const(interest), const(parseDate(start).toInstant()), const(parseDate(end).toInstant())) diff --git a/experimental/src/main/kotlin/net/corda/contracts/universal/PrettyPrint.kt b/experimental/src/main/kotlin/net/corda/contracts/universal/PrettyPrint.kt index cec8a1cfa4..613c4b2a48 100644 --- a/experimental/src/main/kotlin/net/corda/contracts/universal/PrettyPrint.kt +++ b/experimental/src/main/kotlin/net/corda/contracts/universal/PrettyPrint.kt @@ -158,7 +158,7 @@ private class PrettyPrint(arr : Arrangement) { fun prettyPrint(arr: Arrangement) { when (arr) { - is Zero -> print("zero") + is Zero -> println("zero") is RollOut -> { println("rollOut(\"${arr.startDate}\".ld, \"${arr.endDate}\".ld, Frequency.${arr.frequency}) { ") indent { diff --git a/experimental/src/test/kotlin/net/corda/contracts/universal/Swaption.kt b/experimental/src/test/kotlin/net/corda/contracts/universal/Swaption.kt index f354f3dcac..e1f04921a4 100644 --- a/experimental/src/test/kotlin/net/corda/contracts/universal/Swaption.kt +++ b/experimental/src/test/kotlin/net/corda/contracts/universal/Swaption.kt @@ -1,125 +1,84 @@ package net.corda.contracts.universal import net.corda.core.contracts.Frequency +import net.corda.core.contracts.Tenor +import net.corda.core.utilities.DUMMY_NOTARY +import net.corda.testing.transaction +import org.junit.Ignore +import org.junit.Test +import java.time.Instant +import java.time.LocalDate class Swaption { - val notional = 10.M - val currency = USD - val coupon = 1.5.bd - val dreary_contract = arrange { + val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z") + + val notional = 50.M + val currency = EUR + + val tradeDate: LocalDate = LocalDate.of(2016, 9, 1) + + val contractInitial = arrange { + actions { - (highStreetBank or acmeCorp) may { - "proceed".givenThat(after("01/07/2015")) { - highStreetBank.owes(acmeCorp, libor(notional, "01/04/2015", "01/07/2015"), currency) - acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, "01/04/2015", "01/07/2015"), currency) - actions { - (highStreetBank or acmeCorp) may { - "proceed".givenThat(after("01/10/2015")) { - highStreetBank.owes(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency) - acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency) - actions { - (highStreetBank or acmeCorp) may { - "dummy" anytime { zero } - // etc ... - } - } - } - } - } - actions { - acmeCorp may { - "cancel" anytime { - acmeCorp.owes(highStreetBank, 10.K, USD) - } - } - } - } - } acmeCorp may { - "cancel" anytime { - acmeCorp.owes(highStreetBank, 10.K, USD) - } - } - } - } - - - val elegant_contract = arrange { - rollOut("01/04/2015".ld, "01/04/2025".ld, Frequency.Quarterly) { - actions { - (highStreetBank or acmeCorp) may { - "proceed".givenThat(after(start)) { - highStreetBank.owes(acmeCorp, libor(notional, start, end), currency) - acmeCorp.owes(highStreetBank, interest(notional, "act/365", coupon, start, end), currency) - next() - } - } - acmeCorp may { - "cancel" anytime { - acmeCorp.owes(highStreetBank, 10.K, currency) - } - } - } - } - } - - val strike = 1.2 - - val tarf = arrange { - rollOut("01/04/2015".ld, "01/04/2016".ld, Frequency.Quarterly, object { - val cap = variable(150.K) - }) { - actions { - acmeCorp may { - "exercise".givenThat(before(end)) { - val payout = (EUR / USD - strike).plus() * notional - + "exercise" anytime { + rollOut("2016-09-01".ld, "2018-09-01".ld, Frequency.Quarterly) { actions { (acmeCorp or highStreetBank) may { - "proceed".givenThat(after(end)) { - highStreetBank.owes(acmeCorp, payout, USD) - next(vars.cap to vars.cap - payout) + val floating = interest(notional, "act/365", fix("LIBOR", start, Tenor("3M")), start, end) + val fixed = interest(notional, "act/365", 0.5.bd, start, end) + + "pay floating" anytime { + highStreetBank.owes(acmeCorp, floating - fixed, currency) + next() + } + "pay fixed" anytime { + highStreetBank.owes(acmeCorp, fixed - floating, currency) + next() } } } } } - (acmeCorp or highStreetBank) may { - "proceedWithoutExercise".givenThat(after(end)) { - next() - } + } + + highStreetBank may { + "expire".givenThat(after("2016-09-01")) + { + zero } } } + } - val tarf2 = arrange { - rollOut("01/04/2015".ld, "01/04/2016".ld, Frequency.Quarterly, object { - val uses = variable(4) - }) { - actions { - acmeCorp may { - "exercise".givenThat(before(end)) { - val payout = (EUR / USD - strike).plus() * notional + val stateInitial = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), contractInitial) - actions { - (acmeCorp or highStreetBank) may { - "proceed".givenThat(after(end)) { - highStreetBank.owes(acmeCorp, payout, currency) - next(vars.uses to vars.uses - 1) - } - } - } - } - } - (acmeCorp or highStreetBank) may { - "proceedWithoutExercise".givenThat(after(end)) { - next() - } - } + @Test + fun issue() { + transaction { + output { stateInitial } + timestamp(TEST_TX_TIME_1) + + this `fails with` "transaction has a single command" + + tweak { + command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() } + this `fails with` "the transaction is signed by all liable parties" } + + command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() } + + this.verifies() } } + + @Test @Ignore + fun `pretty print`() { + println ( prettyPrint(contractInitial) ) + } + + }