Retire some initialiseSerialization booleans. (#2019)

This commit is contained in:
Andrzej Cichocki 2017-11-10 10:15:55 +00:00 committed by GitHub
parent 8738391b8c
commit 6b71c6cf75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 159 additions and 116 deletions

View File

@ -10,6 +10,7 @@ import net.corda.finance.DOLLARS
import net.corda.finance.`issued by`
import net.corda.finance.contracts.asset.Cash
import net.corda.testing.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.security.PublicKey
@ -23,44 +24,46 @@ class PartialMerkleTreeTest {
@JvmField
val testSerialization = SerializationEnvironmentRule()
private val nodes = "abcdef"
private val hashed = nodes.map { node ->
withTestSerialization {
node.serialize().sha256()
}
}
private val expectedRoot = MerkleTree.getMerkleTree(hashed.toMutableList() + listOf(zeroHash, zeroHash)).hash
private val merkleTree = MerkleTree.getMerkleTree(hashed)
private val testLedger = ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP
)
private lateinit var hashed: List<SecureHash.SHA256>
private lateinit var expectedRoot: SecureHash
private lateinit var merkleTree: MerkleTree
private lateinit var testLedger: LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter>
private lateinit var txs: List<WireTransaction>
private lateinit var testTx: WireTransaction
@Before
fun init() {
hashed = nodes.map { it.serialize().sha256() }
expectedRoot = MerkleTree.getMerkleTree(hashed.toMutableList() + listOf(zeroHash, zeroHash)).hash
merkleTree = MerkleTree.getMerkleTree(hashed)
testLedger = ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP
)
}
output(Cash.PROGRAM_ID, "dummy cash 1") {
Cash.State(
amount = 900.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MINI_CORP
)
}
}
output(Cash.PROGRAM_ID, "dummy cash 1") {
Cash.State(
amount = 900.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MINI_CORP
)
transaction {
attachments(Cash.PROGRAM_ID)
input("MEGA_CORP cash")
output(Cash.PROGRAM_ID, "MEGA_CORP cash".output<Cash.State>().copy(owner = MINI_CORP))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
timeWindow(TEST_TX_TIME)
this.verifies()
}
}
transaction {
attachments(Cash.PROGRAM_ID)
input("MEGA_CORP cash")
output(Cash.PROGRAM_ID, "MEGA_CORP cash".output<Cash.State>().copy(owner = MINI_CORP))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
timeWindow(TEST_TX_TIME)
this.verifies()
}
txs = testLedger.interpreter.transactionsToVerify
testTx = txs[0]
}
private val txs = testLedger.interpreter.transactionsToVerify
private val testTx = txs[0]
// Building full Merkle Tree tests.
@Test
fun `building Merkle tree with 6 nodes - no rightmost nodes`() {

View File

@ -9,7 +9,9 @@ import net.corda.finance.`issued by`
import net.corda.finance.contracts.asset.Cash
import net.corda.testing.MEGA_CORP
import net.corda.testing.MINI_CORP
import net.corda.testing.SerializationEnvironmentRule
import net.corda.testing.ledger
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.temporal.ChronoUnit
@ -17,6 +19,9 @@ import java.time.temporal.ChronoUnit
val TEST_TIMELOCK_ID = "net.corda.core.transactions.TransactionEncumbranceTests\$DummyTimeLock"
class TransactionEncumbranceTests {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val defaultIssuer = MEGA_CORP.ref(1)
val state = Cash.State(

View File

@ -6,6 +6,8 @@ import net.corda.core.utilities.OpaqueBytes;
import net.corda.finance.contracts.ICommercialPaperState;
import net.corda.finance.contracts.JavaCommercialPaper;
import net.corda.finance.contracts.asset.Cash;
import net.corda.testing.SerializationEnvironmentRule;
import org.junit.Rule;
import org.junit.Test;
import java.time.temporal.ChronoUnit;
@ -19,6 +21,8 @@ import static net.corda.testing.NodeTestUtils.transaction;
import static net.corda.testing.TestConstants.*;
public class CommercialPaperTest {
@Rule
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
private final OpaqueBytes defaultRef = new OpaqueBytes(new byte[]{123});
// DOCSTART 1

View File

@ -8,11 +8,15 @@ import net.corda.finance.contracts.CommercialPaper
import net.corda.finance.contracts.ICommercialPaperState
import net.corda.finance.contracts.asset.CASH
import net.corda.finance.contracts.asset.Cash
import net.corda.finance.contracts.asset.ownedBy
import net.corda.testing.*
import org.junit.Rule
import org.junit.Test
class CommercialPaperTest {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
// DOCSTART 1
fun getPaper(): ICommercialPaperState = CommercialPaper.State(
issuance = MEGA_CORP.ref(123),

View File

@ -4,11 +4,9 @@ import net.corda.finance.contracts.BusinessCalendar
import net.corda.finance.contracts.FixOf
import net.corda.finance.contracts.Frequency
import net.corda.finance.contracts.Tenor
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.EnforceVerifyOrFail
import net.corda.testing.TransactionDSL
import net.corda.testing.TransactionDSLInterpreter
import net.corda.testing.*
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.LocalDate
@ -18,7 +16,9 @@ fun transaction(script: TransactionDSL<TransactionDSLInterpreter>.() -> EnforceV
}
class Cap {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val notional = 50.M

View File

@ -3,13 +3,17 @@ package net.corda.finance.contracts.universal
import net.corda.finance.contracts.FixOf
import net.corda.finance.contracts.Tenor
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.LocalDate
class Caplet {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val tradeDate: LocalDate = LocalDate.of(2016, 9, 1)

View File

@ -1,12 +1,16 @@
package net.corda.finance.contracts.universal
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
class FXFwdTimeOption
{
class FXFwdTimeOption {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
// An FX Fwd with Time Option is an early exercise call option that must be exercised no later than maturity
val initialContract = arrange {

View File

@ -1,12 +1,16 @@
package net.corda.finance.contracts.universal
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
class FXSwap {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val TEST_TX_TIME_TOO_EARLY: Instant get() = Instant.parse("2017-08-31T12:00:00.00Z")

View File

@ -4,13 +4,17 @@ import net.corda.finance.contracts.FixOf
import net.corda.finance.contracts.Frequency
import net.corda.finance.contracts.Tenor
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.LocalDate
class IRS {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val notional = 50.M

View File

@ -2,11 +2,16 @@ package net.corda.finance.contracts.universal
import net.corda.finance.contracts.Frequency
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import kotlin.test.assertEquals
class RollOutTests {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val contract = arrange {

View File

@ -3,13 +3,17 @@ package net.corda.finance.contracts.universal
import net.corda.finance.contracts.Frequency
import net.corda.finance.contracts.Tenor
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.LocalDate
class Swaption {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z")
val notional = 50.M

View File

@ -1,12 +1,16 @@
package net.corda.finance.contracts.universal
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.SerializationEnvironmentRule
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import kotlin.test.assertEquals
class ZeroCouponBond {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val contract = arrange {
actions {
(acmeCorp or highStreetBank) may {

View File

@ -4,6 +4,8 @@ import net.corda.core.contracts.PartyAndReference;
import net.corda.core.identity.AnonymousParty;
import net.corda.core.utilities.OpaqueBytes;
import net.corda.testing.DummyCommandData;
import net.corda.testing.SerializationEnvironmentRule;
import org.junit.Rule;
import org.junit.Test;
import static net.corda.finance.Currencies.DOLLARS;
@ -19,6 +21,8 @@ public class CashTestsJava {
private final PartyAndReference defaultIssuer = getMEGA_CORP().ref(defaultRef);
private final Cash.State inState = new Cash.State(issuedBy(DOLLARS(1000), defaultIssuer), new AnonymousParty(getMEGA_CORP_PUBKEY()));
private final Cash.State outState = new Cash.State(inState.getAmount(), new AnonymousParty(getMINI_CORP_PUBKEY()));
@Rule
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
@Test
public void trivial() {

View File

@ -17,6 +17,7 @@ import net.corda.testing.contracts.fillWithSomeTestCash
import net.corda.testing.node.MockServices
import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@ -87,7 +88,9 @@ class CommercialPaperTestsGeneric {
@Parameterized.Parameter
lateinit var thisTest: ICommercialPaperTestTemplate
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
val issuer = MEGA_CORP.ref(123)
@Test

View File

@ -24,12 +24,16 @@ import net.corda.testing.node.MockServices
import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.security.KeyPair
import java.util.*
import kotlin.test.*
class CashTests {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
private val defaultRef = OpaqueBytes(ByteArray(1, { 1 }))
private val defaultIssuer = MEGA_CORP.ref(defaultRef)
private val inState = Cash.State(
@ -51,7 +55,7 @@ class CashTests {
private lateinit var vaultStatesUnconsumed: List<StateAndRef<Cash.State>>
@Before
fun setUp() = withTestSerialization {
fun setUp() {
LogHelper.setLevel(NodeVaultService::class)
megaCorpServices = MockServices(listOf("net.corda.finance.contracts.asset"), MEGA_CORP_KEY)
val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = listOf("net.corda.finance.contracts.asset"), keys = listOf(MINI_CORP_KEY, MEGA_CORP_KEY, OUR_KEY))
@ -153,7 +157,7 @@ class CashTests {
}
@Test
fun generateIssueRaw() = withTestSerialization {
fun generateIssueRaw() {
// Test generation works.
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
Cash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
@ -168,7 +172,7 @@ class CashTests {
}
@Test
fun generateIssueFromAmount() = withTestSerialization {
fun generateIssueFromAmount() {
// Test issuance from an issued amount
val amount = 100.DOLLARS `issued by` MINI_CORP.ref(12, 34)
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
@ -236,7 +240,7 @@ class CashTests {
* cash inputs.
*/
@Test(expected = IllegalStateException::class)
fun `reject issuance with inputs`() = withTestSerialization {
fun `reject issuance with inputs`() {
// Issue some cash
var ptx = TransactionBuilder(DUMMY_NOTARY)
@ -247,7 +251,6 @@ class CashTests {
ptx = TransactionBuilder(DUMMY_NOTARY)
ptx.addInputState(tx.tx.outRef<Cash.State>(0))
Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY)
Unit
}
@Test
@ -512,7 +515,7 @@ class CashTests {
* Try exiting an amount which matches a single state.
*/
@Test
fun generateSimpleExit() = withTestSerialization {
fun generateSimpleExit() {
val wtx = makeExit(miniCorpServices, 100.DOLLARS, MEGA_CORP, 1)
assertEquals(WALLET[0].ref, wtx.inputs[0])
assertEquals(0, wtx.outputs.size)
@ -527,7 +530,7 @@ class CashTests {
* Try exiting an amount smaller than the smallest available input state, and confirm change is generated correctly.
*/
@Test
fun generatePartialExit() = withTestSerialization {
fun generatePartialExit() {
val wtx = makeExit(miniCorpServices, 50.DOLLARS, MEGA_CORP, 1)
val actualInput = wtx.inputs.single()
// Filter the available inputs and confirm exactly one has been used
@ -544,52 +547,47 @@ class CashTests {
* Try exiting a currency we don't have.
*/
@Test
fun generateAbsentExit() = withTestSerialization {
fun generateAbsentExit() {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, MEGA_CORP, 1) }
Unit
}
/**
* Try exiting with a reference mis-match.
*/
@Test
fun generateInvalidReferenceExit() = withTestSerialization {
fun generateInvalidReferenceExit() {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, MEGA_CORP, 2) }
Unit
}
/**
* Try exiting an amount greater than the maximum available.
*/
@Test
fun generateInsufficientExit() = withTestSerialization {
fun generateInsufficientExit() {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 1000.DOLLARS, MEGA_CORP, 1) }
Unit
}
/**
* Try exiting for an owner with no states
*/
@Test
fun generateOwnerWithNoStatesExit() = withTestSerialization {
fun generateOwnerWithNoStatesExit() {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, CHARLIE, 1) }
Unit
}
/**
* Try exiting when vault is empty
*/
@Test
fun generateExitWithEmptyVault() = withTestSerialization {
fun generateExitWithEmptyVault() {
assertFailsWith<IllegalArgumentException> {
val tx = TransactionBuilder(DUMMY_NOTARY)
Cash().generateExit(tx, Amount(100, Issued(CHARLIE.ref(1), GBP)), emptyList(), OUR_IDENTITY_1)
}
Unit
}
@Test
fun generateSimpleDirectSpend() = withTestSerialization {
fun generateSimpleDirectSpend() {
val wtx =
database.transaction {
makeSpend(100.DOLLARS, THEIR_IDENTITY_1)
@ -603,7 +601,7 @@ class CashTests {
}
@Test
fun generateSimpleSpendWithParties() = withTestSerialization {
fun generateSimpleSpendWithParties() {
database.transaction {
val tx = TransactionBuilder(DUMMY_NOTARY)
@ -614,7 +612,7 @@ class CashTests {
}
@Test
fun generateSimpleSpendWithChange() = withTestSerialization {
fun generateSimpleSpendWithChange() {
val wtx =
database.transaction {
makeSpend(10.DOLLARS, THEIR_IDENTITY_1)
@ -639,7 +637,7 @@ class CashTests {
}
@Test
fun generateSpendWithTwoInputs() = withTestSerialization {
fun generateSpendWithTwoInputs() {
val wtx =
database.transaction {
makeSpend(500.DOLLARS, THEIR_IDENTITY_1)
@ -655,7 +653,7 @@ class CashTests {
}
@Test
fun generateSpendMixedDeposits() = withTestSerialization {
fun generateSpendMixedDeposits() {
val wtx =
database.transaction {
val wtx = makeSpend(580.DOLLARS, THEIR_IDENTITY_1)
@ -676,7 +674,7 @@ class CashTests {
}
@Test
fun generateSpendInsufficientBalance() = withTestSerialization {
fun generateSpendInsufficientBalance() {
database.transaction {
val e: InsufficientBalanceException = assertFailsWith("balance") {
@ -688,7 +686,6 @@ class CashTests {
makeSpend(81.SWISS_FRANCS, THEIR_IDENTITY_1)
}
}
Unit
}
/**
@ -815,7 +812,7 @@ class CashTests {
}
@Test
fun multiSpend() = withTestSerialization {
fun multiSpend() {
val tx = TransactionBuilder(DUMMY_NOTARY)
database.transaction {
val payments = listOf(

View File

@ -19,6 +19,7 @@ import net.corda.testing.*
import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState
import net.corda.testing.node.MockServices
import org.junit.Rule
import org.junit.Test
import java.time.Instant
import java.time.temporal.ChronoUnit
@ -29,6 +30,9 @@ import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
class ObligationTests {
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
private val defaultRef = OpaqueBytes.of(1)
private val defaultIssuer = MEGA_CORP.ref(defaultRef)
private val oneMillionDollars = 1000000.DOLLARS `issued by` defaultIssuer
@ -133,7 +137,7 @@ class ObligationTests {
command(MINI_CORP_PUBKEY) { Obligation.Commands.Issue() }
this.verifies()
}
withTestSerialization {
run {
// Test generation works.
val tx = TransactionBuilder(notary = null).apply {
Obligation<Currency>().generateIssue(this, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity,
@ -206,7 +210,7 @@ class ObligationTests {
* cash inputs.
*/
@Test(expected = IllegalStateException::class)
fun `reject issuance with inputs`() = withTestSerialization {
fun `reject issuance with inputs`() {
// Issue some obligation
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
Obligation<Currency>().generateIssue(this, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity,
@ -219,12 +223,11 @@ class ObligationTests {
ptx.addInputState(tx.outRef<Obligation.State<Currency>>(0))
Obligation<Currency>().generateIssue(ptx, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity,
beneficiary = MINI_CORP, notary = DUMMY_NOTARY)
Unit
}
/** Test generating a transaction to net two obligations of the same size, and therefore there are no outputs. */
@Test
fun `generate close-out net transaction`() = withTestSerialization {
fun `generate close-out net transaction`() {
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB), Obligation.PROGRAM_ID)
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE), Obligation.PROGRAM_ID)
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
@ -235,7 +238,7 @@ class ObligationTests {
/** Test generating a transaction to net two obligations of the different sizes, and confirm the balance is correct. */
@Test
fun `generate close-out net transaction with remainder`() = withTestSerialization {
fun `generate close-out net transaction with remainder`() {
val obligationAliceToBob = getStateAndRef((2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(ALICE, BOB), Obligation.PROGRAM_ID)
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE), Obligation.PROGRAM_ID)
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
@ -249,7 +252,7 @@ class ObligationTests {
/** Test generating a transaction to net two obligations of the same size, and therefore there are no outputs. */
@Test
fun `generate payment net transaction`() = withTestSerialization {
fun `generate payment net transaction`() {
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB), Obligation.PROGRAM_ID)
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE), Obligation.PROGRAM_ID)
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
@ -260,7 +263,7 @@ class ObligationTests {
/** Test generating a transaction to two obligations, where one is bigger than the other and therefore there is a remainder. */
@Test
fun `generate payment net transaction with remainder`() = withTestSerialization {
fun `generate payment net transaction with remainder`() {
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB), Obligation.PROGRAM_ID)
val obligationAliceToBobState = obligationAliceToBob.state.data
val obligationBobToAlice = getStateAndRef((2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(BOB, ALICE), Obligation.PROGRAM_ID)
@ -282,7 +285,7 @@ class ObligationTests {
/** Test generating a transaction to mark outputs as having defaulted. */
@Test
fun `generate set lifecycle`() = withTestSerialization {
fun `generate set lifecycle`() {
// We don't actually verify the states, this is just here to make things look sensible
val dueBefore = TEST_TX_TIME - 7.days
@ -320,7 +323,7 @@ class ObligationTests {
/** Test generating a transaction to settle an obligation. */
@Test
fun `generate settlement transaction`() = withTestSerialization {
fun `generate settlement transaction`() {
val cashTx = TransactionBuilder(null).apply {
Cash().generateIssue(this, 100.DOLLARS `issued by` defaultIssuer, MINI_CORP, DUMMY_NOTARY)
}.toWireTransaction(miniCorpServices)
@ -912,7 +915,7 @@ class ObligationTests {
}
@Test
fun `summing balances due between parties`() = withTestSerialization {
fun `summing balances due between parties`() {
val simple: Map<Pair<AbstractParty, AbstractParty>, Amount<Currency>> = mapOf(Pair(Pair(ALICE, BOB), Amount(100000000, GBP)))
val expected: Map<AbstractParty, Long> = mapOf(Pair(ALICE, -100000000L), Pair(BOB, 100000000L))
val actual = sumAmountsDue(simple)

View File

@ -90,7 +90,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
// we run in the unit test thread exclusively to speed things up, ensure deterministic results and
// allow interruption half way through.
mockNet = MockNetwork(threadPerNode = true, cordappPackages = cordappPackages)
ledger(MockServices(cordappPackages), initialiseSerialization = false) {
ledger(MockServices(cordappPackages)) {
val notaryNode = mockNet.defaultNotaryNode
val aliceNode = mockNet.createPartyNode(ALICE_NAME)
val bobNode = mockNet.createPartyNode(BOB_NAME)
@ -140,7 +140,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test(expected = InsufficientBalanceException::class)
fun `trade cash for commercial paper fails using soft locking`() {
mockNet = MockNetwork(threadPerNode = true, cordappPackages = cordappPackages)
ledger(MockServices(cordappPackages), initialiseSerialization = false) {
ledger(MockServices(cordappPackages)) {
val notaryNode = mockNet.defaultNotaryNode
val aliceNode = mockNet.createPartyNode(ALICE_NAME)
val bobNode = mockNet.createPartyNode(BOB_NAME)
@ -196,7 +196,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
fun `shutdown and restore`() {
mockNet = MockNetwork(cordappPackages = cordappPackages)
ledger(MockServices(cordappPackages), initialiseSerialization = false) {
ledger(MockServices(cordappPackages)) {
val notaryNode = mockNet.defaultNotaryNode
val aliceNode = mockNet.createPartyNode(ALICE_NAME)
var bobNode = mockNet.createPartyNode(BOB_NAME)
@ -317,7 +317,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
val bank = bankNode.info.singleIdentity()
val issuer = bank.ref(1, 2, 3)
ledger(aliceNode.services, initialiseSerialization = false) {
ledger(aliceNode.services) {
// Insert a prospectus type attachment into the commercial paper transaction.
val stream = ByteArrayOutputStream()
@ -422,7 +422,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
val bank: Party = bankNode.info.singleIdentity()
val issuer = bank.ref(1, 2, 3)
ledger(aliceNode.services, initialiseSerialization = false) {
ledger(aliceNode.services) {
// Insert a prospectus type attachment into the commercial paper transaction.
val stream = ByteArrayOutputStream()
JarOutputStream(stream).use {
@ -490,7 +490,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
fun `dependency with error on buyer side`() {
mockNet = MockNetwork(cordappPackages = cordappPackages)
ledger(MockServices(cordappPackages), initialiseSerialization = false) {
ledger(MockServices(cordappPackages)) {
runWithError(true, false, "at least one cash input")
}
}
@ -498,7 +498,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
@Test
fun `dependency with error on seller side`() {
mockNet = MockNetwork(cordappPackages = cordappPackages)
ledger(MockServices(cordappPackages), initialiseSerialization = false) {
ledger(MockServices(cordappPackages)) {
runWithError(false, true, "Issuances have a time-window")
}
}

View File

@ -382,7 +382,7 @@ class IRSTests {
val ld = LocalDate.of(2016, 3, 8)
val bd = BigDecimal("0.0063518")
return ledger(initialiseSerialization = false) {
return ledger {
transaction("Agreement") {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement") { singleIRS() }
@ -415,7 +415,7 @@ class IRSTests {
@Test
fun `ensure failure occurs when there are inbound states for an agreement command`() {
val irs = singleIRS()
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
input(IRS_PROGRAM_ID, irs)
output(IRS_PROGRAM_ID, "irs post agreement", irs)
@ -429,7 +429,7 @@ class IRSTests {
fun `ensure failure occurs when no events in fix schedule`() {
val irs = singleIRS()
val emptySchedule = mutableMapOf<LocalDate, FixedRatePaymentEvent>()
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(calculation = irs.calculation.copy(fixedLegPaymentSchedule = emptySchedule)))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -442,7 +442,7 @@ class IRSTests {
fun `ensure failure occurs when no events in floating schedule`() {
val irs = singleIRS()
val emptySchedule = mutableMapOf<LocalDate, FloatingRatePaymentEvent>()
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(calculation = irs.calculation.copy(floatingLegPaymentSchedule = emptySchedule)))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -454,7 +454,7 @@ class IRSTests {
@Test
fun `ensure notionals are non zero`() {
val irs = singleIRS()
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(irs.fixedLeg.copy(notional = irs.fixedLeg.notional.copy(quantity = 0))))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -462,7 +462,7 @@ class IRSTests {
this `fails with` "All notionals must be non zero"
}
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(irs.fixedLeg.copy(notional = irs.floatingLeg.notional.copy(quantity = 0))))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -475,7 +475,7 @@ class IRSTests {
fun `ensure positive rate on fixed leg`() {
val irs = singleIRS()
val modifiedIRS = irs.copy(fixedLeg = irs.fixedLeg.copy(fixedRate = FixedRate(PercentageRatioUnit("-0.1"))))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -491,7 +491,7 @@ class IRSTests {
fun `ensure same currency notionals`() {
val irs = singleIRS()
val modifiedIRS = irs.copy(fixedLeg = irs.fixedLeg.copy(notional = Amount(irs.fixedLeg.notional.quantity, Currency.getInstance("JPY"))))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -504,7 +504,7 @@ class IRSTests {
fun `ensure notional amounts are equal`() {
val irs = singleIRS()
val modifiedIRS = irs.copy(fixedLeg = irs.fixedLeg.copy(notional = Amount(irs.floatingLeg.notional.quantity + 1, irs.floatingLeg.notional.token)))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -517,7 +517,7 @@ class IRSTests {
fun `ensure trade date and termination date checks are done pt1`() {
val irs = singleIRS()
val modifiedIRS1 = irs.copy(fixedLeg = irs.fixedLeg.copy(terminationDate = irs.fixedLeg.effectiveDate.minusDays(1)))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS1)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -526,7 +526,7 @@ class IRSTests {
}
val modifiedIRS2 = irs.copy(floatingLeg = irs.floatingLeg.copy(terminationDate = irs.floatingLeg.effectiveDate.minusDays(1)))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS2)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -540,7 +540,7 @@ class IRSTests {
val irs = singleIRS()
val modifiedIRS3 = irs.copy(floatingLeg = irs.floatingLeg.copy(terminationDate = irs.fixedLeg.terminationDate.minusDays(1)))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS3)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -550,7 +550,7 @@ class IRSTests {
val modifiedIRS4 = irs.copy(floatingLeg = irs.floatingLeg.copy(effectiveDate = irs.fixedLeg.effectiveDate.minusDays(1)))
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS4)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -565,7 +565,7 @@ class IRSTests {
val ld = LocalDate.of(2016, 3, 8)
val bd = BigDecimal("0.0063518")
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement") { singleIRS() }
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
@ -579,7 +579,7 @@ class IRSTests {
oldIRS.calculation.applyFixing(ld, FixedRate(RatioUnit(bd))),
oldIRS.common)
transaction(initialiseSerialization = false) {
transaction {
attachments(IRS_PROGRAM_ID)
input(IRS_PROGRAM_ID, oldIRS)
@ -657,7 +657,7 @@ class IRSTests {
val irs = singleIRS()
return ledger(initialiseSerialization = false) {
return ledger {
transaction("Agreement") {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement1") {

View File

@ -25,17 +25,9 @@ import java.nio.file.Path
@JvmOverloads
fun ledger(
services: ServiceHub = MockServices(),
initialiseSerialization: Boolean = true,
dsl: LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter>.() -> Unit
): LedgerDSL<TestTransactionDSLInterpreter, TestLedgerDSLInterpreter> {
val serializationEnv = initialiseTestSerialization(initialiseSerialization)
try {
val ledgerDsl = LedgerDSL(TestLedgerDSLInterpreter(services))
dsl(ledgerDsl)
return ledgerDsl
} finally {
serializationEnv.resetTestSerialization()
}
return LedgerDSL(TestLedgerDSLInterpreter(services)).also { dsl(it) }
}
/**
@ -46,10 +38,9 @@ fun ledger(
@JvmOverloads
fun transaction(
transactionBuilder: TransactionBuilder = TransactionBuilder(notary = DUMMY_NOTARY),
initialiseSerialization: Boolean = true,
cordappPackages: List<String> = emptyList(),
dsl: TransactionDSL<TransactionDSLInterpreter>.() -> EnforceVerifyOrFail
) = ledger(services = MockServices(cordappPackages), initialiseSerialization = initialiseSerialization) {
) = ledger(services = MockServices(cordappPackages)) {
dsl(TransactionDSL(TestTransactionDSLInterpreter(this.interpreter, transactionBuilder)))
}