mirror of
https://github.com/corda/corda.git
synced 2024-12-20 21:43:14 +00:00
universal: new example/unit test FX Fwd with Time Option
syntax enhancement with re-use of contracts.
This commit is contained in:
parent
e589031d4b
commit
edc30717bb
@ -46,6 +46,11 @@ class ActionsBuilder {
|
|||||||
open class ContractBuilder {
|
open class ContractBuilder {
|
||||||
private val contracts = mutableListOf<Arrangement>()
|
private val contracts = mutableListOf<Arrangement>()
|
||||||
|
|
||||||
|
operator fun Arrangement.unaryPlus() : Arrangement {
|
||||||
|
contracts.add(this)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
fun actions(init: ActionsBuilder.() -> Action): Arrangement {
|
fun actions(init: ActionsBuilder.() -> Action): Arrangement {
|
||||||
val b = ActionsBuilder()
|
val b = ActionsBuilder()
|
||||||
b.init()
|
b.init()
|
||||||
|
@ -81,6 +81,8 @@ fun before(expiry: Perceivable<Instant>) = TimePerceivable(Comparison.LTE, expir
|
|||||||
fun after(expiry: Perceivable<Instant>) = TimePerceivable(Comparison.GTE, expiry)
|
fun after(expiry: Perceivable<Instant>) = TimePerceivable(Comparison.GTE, expiry)
|
||||||
fun before(expiry: Instant) = TimePerceivable(Comparison.LTE, const(expiry))
|
fun before(expiry: Instant) = TimePerceivable(Comparison.LTE, const(expiry))
|
||||||
fun after(expiry: Instant) = TimePerceivable(Comparison.GTE, 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 before(expiry: String) = TimePerceivable(Comparison.LTE, const(parseDate(expiry).toInstant()))
|
||||||
fun after(expiry: String) = TimePerceivable(Comparison.GTE, const(parseDate(expiry).toInstant()))
|
fun after(expiry: String) = TimePerceivable(Comparison.GTE, const(parseDate(expiry).toInstant()))
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ class FXSwap {
|
|||||||
|
|
||||||
val contract = arrange {
|
val contract = arrange {
|
||||||
actions {
|
actions {
|
||||||
(acmeCorp or highStreetBank).may {
|
(acmeCorp or highStreetBank) may {
|
||||||
"execute".givenThat(after("2017-09-01")) {
|
"execute".givenThat(after("2017-09-01")) {
|
||||||
highStreetBank.owes(acmeCorp, 1200.K, USD)
|
highStreetBank.owes(acmeCorp, 1200.K, USD)
|
||||||
acmeCorp.owes(highStreetBank, 1.M, EUR)
|
acmeCorp.owes(highStreetBank, 1.M, EUR)
|
||||||
|
@ -129,11 +129,6 @@ class IRS {
|
|||||||
val statePaymentFirst = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), paymentFirst)
|
val statePaymentFirst = UniversalContract.State(listOf(DUMMY_NOTARY.owningKey), paymentFirst)
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun ser1() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun issue() {
|
fun issue() {
|
||||||
transaction {
|
transaction {
|
||||||
|
Loading…
Reference in New Issue
Block a user