universal: new example/unit test FX Fwd with Time Option

syntax enhancement with re-use of contracts.
This commit is contained in:
sofusmortensen 2016-12-05 10:06:43 +00:00 committed by Sofus Mortensen
parent e589031d4b
commit edc30717bb
5 changed files with 67 additions and 6 deletions

View File

@ -46,6 +46,11 @@ class ActionsBuilder {
open class ContractBuilder {
private val contracts = mutableListOf<Arrangement>()
operator fun Arrangement.unaryPlus() : Arrangement {
contracts.add(this)
return this
}
fun actions(init: ActionsBuilder.() -> Action): Arrangement {
val b = ActionsBuilder()
b.init()

View File

@ -81,6 +81,8 @@ fun before(expiry: Perceivable<Instant>) = TimePerceivable(Comparison.LTE, expir
fun after(expiry: Perceivable<Instant>) = TimePerceivable(Comparison.GTE, expiry)
fun before(expiry: Instant) = TimePerceivable(Comparison.LTE, const(expiry))
fun after(expiry: Instant) = TimePerceivable(Comparison.GTE, const(expiry))
fun before(expiry: LocalDate) = TimePerceivable(Comparison.LTE, const(expiry.toInstant()))
fun after(expiry: LocalDate) = TimePerceivable(Comparison.GTE, const(expiry.toInstant()))
fun before(expiry: String) = TimePerceivable(Comparison.LTE, const(parseDate(expiry).toInstant()))
fun after(expiry: String) = TimePerceivable(Comparison.GTE, const(parseDate(expiry).toInstant()))

View File

@ -0,0 +1,59 @@
package net.corda.contracts.universal
import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction
import org.junit.Test
import java.time.Instant
class FXFwdTimeOption
{
// An FX Fwd with Time Option is an early exercise call option that must be exercised no later than maturity
val initialContract = arrange {
val swap = arrange {
highStreetBank.owes(acmeCorp, 1200.K, EUR)
acmeCorp.owes(highStreetBank, 1.M, USD)
}
val maturity = "2018-06-01".ld
actions {
acmeCorp may {
"exercise".givenThat(before(maturity)) {
+swap // problem, swap (wo unary plus) also compiles, but with no effect.
// hopefully this can be solved using @DslMarker in Kotlin 1.1
}
}
highStreetBank may {
"expire".givenThat(after(maturity)) {
+swap
}
}
}
}
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val inState = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), initialContract)
@Test
fun `issue - signature`() {
transaction {
output { inState }
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"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey, acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
this.verifies()
}
}
}

View File

@ -12,7 +12,7 @@ class FXSwap {
val contract = arrange {
actions {
(acmeCorp or highStreetBank).may {
(acmeCorp or highStreetBank) may {
"execute".givenThat(after("2017-09-01")) {
highStreetBank.owes(acmeCorp, 1200.K, USD)
acmeCorp.owes(highStreetBank, 1.M, EUR)

View File

@ -129,11 +129,6 @@ class IRS {
val statePaymentFirst = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), paymentFirst)
@Test
fun ser1() {
}
@Test
fun issue() {
transaction {