From f0c7d7665a7e9601a332ec9b22e6f103493afa48 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Fri, 4 Aug 2017 11:50:52 +0100 Subject: [PATCH] Remove deprecated signing functions * Remove TransactionBuilder.signWith() * Remove TransactionBuilder.addSignatureUnchecked() * Rename signInitialTransaction to toSignedTransaction * Remove checkAndAddSignature() * Require all unit tests sign transactions via services --- .../kotlin/net/corda/core/node/ServiceHub.kt | 5 +- .../core/transactions/SignedTransaction.kt | 11 +- .../core/transactions/TransactionBuilder.kt | 63 +-- docs/source/api-service-hub.rst | 2 +- docs/source/changelog.rst | 2 +- docs/source/hello-world-flow.rst | 6 +- docs/source/tut-two-party-flow.rst | 4 +- docs/source/tutorial-contract.rst | 2 +- docs/source/using-a-notary.rst | 4 +- .../net/corda/flows/TwoPartyDealFlow.kt | 22 +- .../corda/contracts/CommercialPaperTests.kt | 5 +- .../net/corda/contracts/asset/CashTests.kt | 16 +- .../services/vault/VaultQueryJavaTests.java | 57 +- .../node/messaging/TwoPartyTradeFlowTests.kt | 18 +- .../database/HibernateConfigurationTest.kt | 70 ++- .../services/vault/NodeVaultServiceTest.kt | 63 ++- .../node/services/vault/VaultQueryTests.kt | 493 +++++++++--------- .../node/services/vault/VaultWithCashTest.kt | 19 +- .../kotlin/net/corda/irs/flows/FixingFlow.kt | 11 +- .../net/corda/irs/flows/RatesFixFlow.kt | 7 +- .../corda/testing/contracts/VaultFiller.kt | 82 +-- 21 files changed, 468 insertions(+), 494 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt index fabc939101..0a885130d9 100644 --- a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt +++ b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt @@ -137,10 +137,7 @@ interface ServiceHub : ServicesForResolution { // Helper method to construct an initial partially signed transaction from a [TransactionBuilder]. private fun signInitialTransaction(builder: TransactionBuilder, publicKey: PublicKey, signatureMetadata: SignatureMetadata): SignedTransaction { - val signableData = SignableData(builder.toWireTransaction().id, signatureMetadata) - val sig = keyManagementService.sign(signableData, publicKey) - builder.addSignatureUnchecked(sig) - return builder.toSignedTransaction(false) + return builder.toSignedTransaction(keyManagementService, publicKey, signatureMetadata) } /** diff --git a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt index 427b3804d5..c2afc3f2ec 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt @@ -1,15 +1,16 @@ package net.corda.core.transactions import net.corda.core.contracts.* -import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.TransactionSignature +import net.corda.core.crypto.* import net.corda.core.identity.Party +import net.corda.core.internal.VisibleForTesting import net.corda.core.node.ServiceHub import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize import net.corda.core.utilities.getOrThrow +import java.security.KeyPair import java.security.PublicKey import java.security.SignatureException import java.util.* @@ -74,6 +75,12 @@ data class SignedTransaction(val txBits: SerializedBytes, return descriptions } + @VisibleForTesting + fun withAdditionalSignature(keyPair: KeyPair, signatureMetadata: SignatureMetadata): SignedTransaction { + val signableData = SignableData(tx.id, signatureMetadata) + return withAdditionalSignature(keyPair.sign(signableData)) + } + /** Returns the same transaction but with an additional (unchecked) signature. */ fun withAdditionalSignature(sig: TransactionSignature) = copyWithCache(listOf(sig)) diff --git a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt index a675de64b3..5e10965370 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt @@ -6,9 +6,9 @@ import net.corda.core.crypto.* import net.corda.core.identity.Party import net.corda.core.internal.FlowStateMachine import net.corda.core.node.ServiceHub +import net.corda.core.node.services.KeyManagementService import java.security.KeyPair import java.security.PublicKey -import java.security.SignatureException import java.time.Duration import java.time.Instant import java.util.* @@ -149,59 +149,14 @@ open class TransactionBuilder( fun outputStates(): List> = ArrayList(outputs) fun commands(): List> = ArrayList(commands) - /** The signatures that have been collected so far - might be incomplete! */ - @Deprecated("Signatures should be gathered on a SignedTransaction instead.") - protected val currentSigs = arrayListOf() - - @Deprecated("Use ServiceHub.signInitialTransaction() instead.") - fun signWith(key: KeyPair): TransactionBuilder { - val signableData = SignableData(toWireTransaction().id, SignatureMetadata(1, Crypto.findSignatureScheme(key.public).schemeNumberID)) // A dummy platformVersion. - addSignatureUnchecked(key.sign(signableData)) - return this - } - - /** Adds the signature directly to the transaction, without checking it for validity. */ - @Deprecated("Use ServiceHub.signInitialTransaction() instead.") - fun addSignatureUnchecked(sig: TransactionSignature): TransactionBuilder { - currentSigs.add(sig) - return this - } - - @Deprecated("Use ServiceHub.signInitialTransaction() instead.") - fun toSignedTransaction(checkSufficientSignatures: Boolean = true): SignedTransaction { - if (checkSufficientSignatures) { - val gotKeys = currentSigs.map { it.by }.toSet() - val requiredKeys = commands.flatMap { it.signers }.toSet() - val missing: Set = requiredKeys.filter { !it.isFulfilledBy(gotKeys) }.toSet() - if (missing.isNotEmpty()) - throw IllegalStateException("Missing signatures on the transaction for the public keys: ${missing.joinToString()}") - } + /** + * Sign the built transaction and return it. This is an internal function for use by the service hub, please use + * [ServiceHub.signInitialTransaction] instead. + */ + fun toSignedTransaction(keyManagementService: KeyManagementService, publicKey: PublicKey, signatureMetadata: SignatureMetadata): SignedTransaction { val wtx = toWireTransaction() - return SignedTransaction(wtx, ArrayList(currentSigs)) - } - - /** - * Checks that the given signature matches one of the commands and that it is a correct signature over the tx, then - * adds it. - * - * @throws SignatureException if the signature didn't match the transaction contents. - * @throws IllegalArgumentException if the signature key doesn't appear in any command. - */ - @Deprecated("Use WireTransaction.checkSignature() instead.") - fun checkAndAddSignature(sig: TransactionSignature) { - checkSignature(sig) - addSignatureUnchecked(sig) - } - - /** - * Checks that the given signature matches one of the commands and that it is a correct signature over the tx. - * - * @throws SignatureException if the signature didn't match the transaction contents. - * @throws IllegalArgumentException if the signature key doesn't appear in any command. - */ - @Deprecated("Use WireTransaction.checkSignature() instead.") - fun checkSignature(sig: TransactionSignature) { - require(commands.any { it.signers.any { sig.by in it.keys } }) { "Signature key doesn't match any command" } - sig.verify(toWireTransaction().id) + val signableData = SignableData(wtx.id, signatureMetadata) + val sig = keyManagementService.sign(signableData, publicKey) + return SignedTransaction(wtx, listOf(sig)) } } \ No newline at end of file diff --git a/docs/source/api-service-hub.rst b/docs/source/api-service-hub.rst index d3cea14024..62e84fb209 100644 --- a/docs/source/api-service-hub.rst +++ b/docs/source/api-service-hub.rst @@ -24,7 +24,7 @@ Additional, ``ServiceHub`` exposes the following properties: * ``ServiceHub.loadState`` and ``ServiceHub.toStateAndRef`` to resolve a ``StateRef`` into a ``TransactionState`` or a ``StateAndRef`` -* ``ServiceHub.signInitialTransaction`` to sign a ``TransactionBuilder`` and convert it into a ``SignedTransaction`` +* ``ServiceHub.toSignedTransaction`` to sign a ``TransactionBuilder`` and convert it into a ``SignedTransaction`` * ``ServiceHub.createSignature`` and ``ServiceHub.addSignature`` to create and add signatures to a ``SignedTransaction`` Finally, ``ServiceHub`` exposes the node's legal identity key (via ``ServiceHub.legalIdentityKey``) and its notary diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index b2e41c9ba3..9accc7730f 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -276,7 +276,7 @@ Milestone 12 with the ``PrivateKey`` kept internally to the service. * Flows which used to acquire a node's ``KeyPair``, typically via ``ServiceHub.legalIdentityKey``, should instead use the helper methods on ``ServiceHub``. In particular to freeze a ``TransactionBuilder`` and - generate an initial partially signed ``SignedTransaction`` the flow should use ``ServiceHub.signInitialTransaction``. + generate an initial partially signed ``SignedTransaction`` the flow should use ``ServiceHub.toSignedTransaction``. Flows generating additional party signatures should use ``ServiceHub.createSignature``. Each of these methods is provided with two signatures. One version that signs with the default node key, the other which allows key selection by passing in the ``PublicKey`` partner of the desired signing key. diff --git a/docs/source/hello-world-flow.rst b/docs/source/hello-world-flow.rst index b23a61b30d..c86c81191e 100644 --- a/docs/source/hello-world-flow.rst +++ b/docs/source/hello-world-flow.rst @@ -79,7 +79,7 @@ the following: txBuilder.verify(serviceHub) // Signing the transaction. - val signedTx = serviceHub.signInitialTransaction(txBuilder) + val signedTx = serviceHub.toSignedTransaction(txBuilder) // Finalising the transaction. subFlow(FinalityFlow(signedTx)) @@ -141,7 +141,7 @@ the following: txBuilder.verify(getServiceHub()); // Signing the transaction. - final SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder); + final SignedTransaction signedTx = getServiceHub().toSignedTransaction(txBuilder); // Finalising the transaction. subFlow(new FinalityFlow(signedTx)); @@ -229,7 +229,7 @@ Signing the transaction Now that we have a valid transaction proposal, we need to sign it. Once the transaction is signed, no-one will be able to modify the transaction without invalidating our signature, effectively making the transaction immutable. -The call to ``ServiceHub.signInitialTransaction`` returns a ``SignedTransaction`` - an object that pairs the +The call to ``ServiceHub.toSignedTransaction`` returns a ``SignedTransaction`` - an object that pairs the transaction itself with a list of signatures over that transaction. Finalising the transaction diff --git a/docs/source/tut-two-party-flow.rst b/docs/source/tut-two-party-flow.rst index 00a2658441..bd5b5a87fc 100644 --- a/docs/source/tut-two-party-flow.rst +++ b/docs/source/tut-two-party-flow.rst @@ -36,7 +36,7 @@ In ``IOUFlow.java``/``IOUFlow.kt``, update ``IOUFlow.call`` as follows: txBuilder.verify(serviceHub) // Signing the transaction. - val signedTx = serviceHub.signInitialTransaction(txBuilder) + val signedTx = serviceHub.toSignedTransaction(txBuilder) // Obtaining the counterparty's signature val fullySignedTx = subFlow(CollectSignaturesFlow(signedTx)) @@ -56,7 +56,7 @@ In ``IOUFlow.java``/``IOUFlow.kt``, update ``IOUFlow.call`` as follows: txBuilder.verify(getServiceHub()); // Signing the transaction. - final SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder); + final SignedTransaction signedTx = getServiceHub().toSignedTransaction(txBuilder); // Obtaining the counterparty's signature final SignedTransaction fullySignedTx = subFlow(new CollectSignaturesFlow(signedTx, null)); diff --git a/docs/source/tutorial-contract.rst b/docs/source/tutorial-contract.rst index a1acf7997a..181c772724 100644 --- a/docs/source/tutorial-contract.rst +++ b/docs/source/tutorial-contract.rst @@ -707,7 +707,7 @@ from the ledger). Finally, we add a Redeem command that should be signed by the A ``TransactionBuilder`` is not by itself ready to be used anywhere, so first, we must convert it to something that is recognised by the network. The most important next step is for the participating entities to sign it. Typically, -an initiating flow will create an initial partially signed ``SignedTransaction`` by calling the ``serviceHub.signInitialTransaction`` method. +an initiating flow will create an initial partially signed ``SignedTransaction`` by calling the ``serviceHub.toSignedTransaction`` method. Then the frozen ``SignedTransaction`` can be passed to other nodes by the flow, these can sign using ``serviceHub.createSignature`` and distribute. The ``CollectSignaturesFlow`` provides a generic implementation of this process that can be used as a ``subFlow`` . diff --git a/docs/source/using-a-notary.rst b/docs/source/using-a-notary.rst index 14dae86307..08517c6eaa 100644 --- a/docs/source/using-a-notary.rst +++ b/docs/source/using-a-notary.rst @@ -64,7 +64,7 @@ We then sign the transaction, build and record it to our transaction storage: .. sourcecode:: kotlin val mySigningKey: PublicKey = serviceHub.legalIdentityKey - val issueTransaction = serviceHub.signInitialTransaction(issueTransaction, mySigningKey) + val issueTransaction = serviceHub.toSignedTransaction(issueTransaction, mySigningKey) serviceHub.recordTransactions(issueTransaction) The transaction is recorded and we now have a state (asset) in possession that we can transfer to someone else. Note @@ -98,7 +98,7 @@ Again we sign the transaction, and build it: // We build it and add our default identity signature without checking if all signatures are present, // Note we know that the notary signature is missing, so thie SignedTransaction is still partial. - val moveTransaction = serviceHub.signInitialTransaction(moveTransactionBuilder) + val moveTransaction = serviceHub.toSignedTransaction(moveTransactionBuilder) Next we need to obtain a signature from the notary for the transaction to be valid. Prior to signing, the notary will commit our old (input) state so it cannot be used again. diff --git a/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt b/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt index ad16e4241d..6c91bb4a78 100644 --- a/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt @@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.contracts.DealState import net.corda.core.contracts.requireThat import net.corda.core.crypto.SecureHash +import net.corda.core.crypto.TransactionSignature import net.corda.core.flows.CollectSignaturesFlow import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FlowLogic @@ -12,11 +13,11 @@ import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.node.NodeInfo import net.corda.core.node.services.ServiceType -import net.corda.core.utilities.seconds import net.corda.core.serialization.CordaSerializable import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.ProgressTracker +import net.corda.core.utilities.seconds import net.corda.core.utilities.trace import net.corda.core.utilities.unwrap import java.security.PublicKey @@ -92,8 +93,12 @@ object TwoPartyDealFlow { val handshake = receiveAndValidateHandshake() progressTracker.currentStep = SIGNING - val (utx, additionalSigningPubKeys) = assembleSharedTX(handshake) - val ptx = signWithOurKeys(additionalSigningPubKeys, utx) + val (utx, additionalSigningPubKeys, additionalSignatures) = assembleSharedTX(handshake) + val ptx = if (additionalSignatures.any()) { + serviceHub.signInitialTransaction(utx, additionalSigningPubKeys).withAdditionalSignatures(additionalSignatures) + } else { + serviceHub.signInitialTransaction(utx, additionalSigningPubKeys) + } logger.trace { "Signed proposed transaction." } @@ -136,13 +141,8 @@ object TwoPartyDealFlow { return handshake.unwrap { validateHandshake(it) } } - private fun signWithOurKeys(signingPubKeys: List, ptx: TransactionBuilder): SignedTransaction { - // Now sign the transaction with whatever keys we need to move the cash. - return serviceHub.signInitialTransaction(ptx, signingPubKeys) - } - @Suspendable protected abstract fun validateHandshake(handshake: Handshake): Handshake - @Suspendable protected abstract fun assembleSharedTX(handshake: Handshake): Pair> + @Suspendable protected abstract fun assembleSharedTX(handshake: Handshake): Triple, List> } @CordaSerializable @@ -178,14 +178,14 @@ object TwoPartyDealFlow { return handshake.copy(payload = autoOffer.copy(dealBeingOffered = deal)) } - override fun assembleSharedTX(handshake: Handshake): Pair> { + override fun assembleSharedTX(handshake: Handshake): Triple, List> { val deal = handshake.payload.dealBeingOffered val ptx = deal.generateAgreement(handshake.payload.notary) // We set the transaction's time-window: it may be that none of the contracts need this! // But it can't hurt to have one. ptx.setTimeWindow(serviceHub.clock.instant(), 30.seconds) - return Pair(ptx, arrayListOf(deal.participants.single { it == serviceHub.myInfo.legalIdentity as AbstractParty }.owningKey)) + return Triple(ptx, arrayListOf(deal.participants.single { it == serviceHub.myInfo.legalIdentity as AbstractParty }.owningKey), emptyList()) } } } diff --git a/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt b/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt index 8adf55f286..ccd8c5b5e9 100644 --- a/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/CommercialPaperTests.kt @@ -204,6 +204,7 @@ class CommercialPaperTestsGeneric { private lateinit var alicesVault: Vault private val notaryServices = MockServices(DUMMY_NOTARY_KEY) + private val issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY) private lateinit var moveTX: SignedTransaction @@ -216,7 +217,7 @@ class CommercialPaperTestsGeneric { aliceVaultService = aliceServices.vaultService databaseAlice.transaction { - alicesVault = aliceServices.fillWithSomeTestCash(9000.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1) + alicesVault = aliceServices.fillWithSomeTestCash(9000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) aliceVaultService = aliceServices.vaultService } @@ -226,7 +227,7 @@ class CommercialPaperTestsGeneric { bigCorpVaultService = bigCorpServices.vaultService databaseBigCorp.transaction { - bigCorpVault = bigCorpServices.fillWithSomeTestCash(13000.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1) + bigCorpVault = bigCorpServices.fillWithSomeTestCash(13000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) bigCorpVaultService = bigCorpServices.vaultService } diff --git a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt index 5b51d8fc1b..ba6d23b4c4 100644 --- a/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt +++ b/finance/src/test/kotlin/net/corda/contracts/asset/CashTests.kt @@ -6,17 +6,11 @@ import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party -import net.corda.core.node.services.IdentityService -import net.corda.core.node.services.VaultQueryService import net.corda.core.node.services.VaultService import net.corda.core.node.services.queryBy import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.WireTransaction import net.corda.core.utilities.OpaqueBytes -import net.corda.node.services.database.HibernateConfiguration -import net.corda.node.services.identity.InMemoryIdentityService -import net.corda.node.services.schema.NodeSchemaService -import net.corda.node.services.vault.HibernateVaultQueryImpl import net.corda.node.services.vault.NodeVaultService import net.corda.node.utilities.CordaPersistence import net.corda.testing.* @@ -47,6 +41,7 @@ class CashTests : TestDependencyInjectionBase() { ) lateinit var miniCorpServices: MockServices + lateinit var megaCorpServices: MockServices val vault: VaultService get() = miniCorpServices.vaultService lateinit var database: CordaPersistence lateinit var vaultStatesUnconsumed: List> @@ -54,19 +49,20 @@ class CashTests : TestDependencyInjectionBase() { @Before fun setUp() { LogHelper.setLevel(NodeVaultService::class) + megaCorpServices = MockServices(MEGA_CORP_KEY) val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(MINI_CORP_KEY, MEGA_CORP_KEY, OUR_KEY)) database = databaseAndServices.first miniCorpServices = databaseAndServices.second database.transaction { miniCorpServices.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - issuedBy = MEGA_CORP.ref(1), issuerKey = MEGA_CORP_KEY, ownedBy = OUR_IDENTITY_1) + ownedBy = OUR_IDENTITY_1, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) miniCorpServices.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - issuedBy = MEGA_CORP.ref(1), issuerKey = MEGA_CORP_KEY, ownedBy = OUR_IDENTITY_1) + ownedBy = OUR_IDENTITY_1, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) miniCorpServices.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - issuedBy = MINI_CORP.ref(1), issuerKey = MINI_CORP_KEY, ownedBy = OUR_IDENTITY_1) + ownedBy = OUR_IDENTITY_1, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) miniCorpServices.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - issuedBy = MINI_CORP.ref(1), issuerKey = MINI_CORP_KEY, ownedBy = OUR_IDENTITY_1) + ownedBy = OUR_IDENTITY_1, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) vaultStatesUnconsumed = miniCorpServices.vaultQueryService.queryBy().states } diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index 72b70bb8a0..aedbfb70af 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -17,8 +17,8 @@ import net.corda.core.node.services.vault.QueryCriteria.LinearStateQueryCriteria import net.corda.core.node.services.vault.QueryCriteria.VaultCustomQueryCriteria; import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria; import net.corda.core.utilities.OpaqueBytes; +import net.corda.node.services.identity.InMemoryIdentityService; import net.corda.node.utilities.CordaPersistence; -import net.corda.node.services.identity.*; import net.corda.schemas.CashSchemaV1; import net.corda.testing.TestConstants; import net.corda.testing.TestDependencyInjectionBase; @@ -44,13 +44,14 @@ import static net.corda.core.node.services.vault.QueryCriteriaUtils.DEFAULT_PAGE import static net.corda.core.node.services.vault.QueryCriteriaUtils.MAX_PAGE_SIZE; import static net.corda.core.utilities.ByteArrays.toHexString; import static net.corda.testing.CoreTestUtils.*; -import static net.corda.testing.node.MockServicesKt.makeTestDatabaseAndMockServices; import static net.corda.testing.TestConstants.*; +import static net.corda.testing.node.MockServicesKt.makeTestDatabaseAndMockServices; import static org.assertj.core.api.Assertions.assertThat; public class VaultQueryJavaTests extends TestDependencyInjectionBase { private MockServices services; + private MockServices issuerServices; private VaultService vaultSvc; private VaultQueryService vaultQuerySvc; private CordaPersistence database; @@ -59,8 +60,10 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { public void setUp() { ArrayList keys = new ArrayList<>(); keys.add(getMEGA_CORP_KEY()); + keys.add(getDUMMY_NOTARY_KEY()); InMemoryIdentityService identityService = new InMemoryIdentityService(getMOCK_IDENTITIES(), Collections.emptyMap(), getDUMMY_CA().getCertificate()); Pair databaseAndServices = makeTestDatabaseAndMockServices(Collections.EMPTY_SET, keys); + issuerServices = new MockServices(getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); database = databaseAndServices.getFirst(); services = databaseAndServices.getSecond(); vaultSvc = services.getVaultService(); @@ -129,16 +132,16 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { VaultFiller.fillWithSomeTestCash(services, new Amount<>(100, Currency.getInstance("USD")), + issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(), new OpaqueBytes("1".getBytes()), null, - getDUMMY_CASH_ISSUER(), - getDUMMY_CASH_ISSUER_KEY() ); + getDUMMY_CASH_ISSUER()); - VaultFiller.consumeCash(services, amount); + VaultFiller.consumeCash(services, amount, getDUMMY_NOTARY()); // DOCSTART VaultJavaQueryExample1 VaultQueryCriteria criteria = new VaultQueryCriteria(Vault.StateStatus.CONSUMED); @@ -163,8 +166,8 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Vault dealStates = VaultFiller.fillWithSomeTestDeals(services, dealIds); // consume states - VaultFiller.consumeDeals(services, (List>) dealStates.getStates()); - VaultFiller.consumeLinearStates(services, Collections.singletonList(linearState)); + VaultFiller.consumeDeals(services, (List>) dealStates.getStates(), getDUMMY_NOTARY()); + VaultFiller.consumeLinearStates(services, Collections.singletonList(linearState), getDUMMY_NOTARY()); // DOCSTART VaultJavaQueryExample2 Vault.StateStatus status = Vault.StateStatus.CONSUMED; @@ -202,10 +205,10 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Amount dollars10 = new Amount<>(10, Currency.getInstance("USD")); Amount dollars1 = new Amount<>(1, Currency.getInstance("USD")); - VaultFiller.fillWithSomeTestCash(services, pounds, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars100, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars10, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars1, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); + VaultFiller.fillWithSomeTestCash(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars10, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars1, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); try { // DOCSTART VaultJavaQueryExample3 @@ -242,14 +245,14 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { database.transaction(tx -> { VaultFiller.fillWithSomeTestCash(services, new Amount<>(100, Currency.getInstance("USD")), + issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(), new OpaqueBytes("1".getBytes()), null, - getDUMMY_CASH_ISSUER(), - getDUMMY_CASH_ISSUER_KEY() ); + getDUMMY_CASH_ISSUER()); // DOCSTART VaultJavaQueryExample4 @SuppressWarnings("unchecked") @@ -320,11 +323,11 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Amount pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); - VaultFiller.fillWithSomeTestCash(services, dollars100, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars200, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars300, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, pounds, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, swissfrancs, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); + VaultFiller.fillWithSomeTestCash(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); try { // DOCSTART VaultJavaQueryExample21 @@ -365,11 +368,11 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Amount pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); - VaultFiller.fillWithSomeTestCash(services, dollars100, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars200, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars300, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, pounds, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, swissfrancs, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); + VaultFiller.fillWithSomeTestCash(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); try { // DOCSTART VaultJavaQueryExample22 @@ -435,10 +438,10 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Amount pounds300 = new Amount<>(300, Currency.getInstance("GBP")); Amount pounds400 = new Amount<>(400, Currency.getInstance("GBP")); - VaultFiller.fillWithSomeTestCash(services, dollars100, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, dollars200, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getBOC().ref(new OpaqueBytes("1".getBytes())), getBOC_KEY()); - VaultFiller.fillWithSomeTestCash(services, pounds300, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER(), getDUMMY_CASH_ISSUER_KEY()); - VaultFiller.fillWithSomeTestCash(services, pounds400, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getBOC().ref(new OpaqueBytes("1".getBytes())), getBOC_KEY()); + VaultFiller.fillWithSomeTestCash(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), new OpaqueBytes("1".getBytes()), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); + VaultFiller.fillWithSomeTestCash(services, pounds300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), new OpaqueBytes("1".getBytes()), null, getDUMMY_CASH_ISSUER()); + VaultFiller.fillWithSomeTestCash(services, pounds400, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), new OpaqueBytes("1".getBytes()), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); try { // DOCSTART VaultJavaQueryExample23 diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index 03f8ea9c62..6883111993 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -96,17 +96,19 @@ class TwoPartyTradeFlowTests { val aliceNode = basketOfNodes.partyNodes[0] val bobNode = basketOfNodes.partyNodes[1] val bankNode = basketOfNodes.partyNodes[2] - val issuer = bankNode.info.legalIdentity.ref(1, 2, 3) + val cashIssuer = bankNode.info.legalIdentity.ref(1) + val cpIssuer = bankNode.info.legalIdentity.ref(1, 2, 3) aliceNode.disableDBCloseOnStop() bobNode.disableDBCloseOnStop() bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, outputNotary = notaryNode.info.notaryIdentity) + bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notaryNode.info.notaryIdentity, + issuedBy = cashIssuer) } val alicesFakePaper = aliceNode.database.transaction { - fillUpForSeller(false, issuer, aliceNode.info.legalIdentity, + fillUpForSeller(false, cpIssuer, aliceNode.info.legalIdentity, 1200.DOLLARS `issued by` bankNode.info.legalIdentity.ref(0), null, notaryNode.info.notaryIdentity).second } @@ -142,14 +144,16 @@ class TwoPartyTradeFlowTests { val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name) val bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name) val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name) + val cashIssuer = bankNode.info.legalIdentity.ref(1) val cpIssuer = bankNode.info.legalIdentity.ref(1, 2, 3) aliceNode.disableDBCloseOnStop() bobNode.disableDBCloseOnStop() val cashStates = bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, notaryNode.info.notaryIdentity, 3, 3) - } + bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, notaryNode.info.notaryIdentity, 3, 3, + issuedBy = cashIssuer) + } val alicesFakePaper = aliceNode.database.transaction { fillUpForSeller(false, cpIssuer, aliceNode.info.legalIdentity, @@ -194,6 +198,7 @@ class TwoPartyTradeFlowTests { val aliceNode = mockNet.createPartyNode(notaryNode.network.myAddress, ALICE.name) var bobNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOB.name) val bankNode = mockNet.createPartyNode(notaryNode.network.myAddress, BOC.name) + val cashIssuer = bankNode.info.legalIdentity.ref(1) val cpIssuer = bankNode.info.legalIdentity.ref(1, 2, 3) aliceNode.services.identityService.registerIdentity(bobNode.info.legalIdentityAndCert) @@ -207,7 +212,8 @@ class TwoPartyTradeFlowTests { mockNet.runNetwork() // Clear network map registration messages bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, outputNotary = notaryNode.info.notaryIdentity) + bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notaryNode.info.notaryIdentity, + issuedBy = cashIssuer) } val alicesFakePaper = aliceNode.database.transaction { fillUpForSeller(false, cpIssuer, aliceNode.info.legalIdentity, diff --git a/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt index e19300c60b..e4ac1bf76f 100644 --- a/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/database/HibernateConfigurationTest.kt @@ -1,14 +1,10 @@ package net.corda.node.services.database -import net.corda.contracts.asset.Cash -import net.corda.contracts.asset.DUMMY_CASH_ISSUER -import net.corda.contracts.asset.DummyFungibleContract -import net.corda.contracts.asset.sumCash +import net.corda.contracts.asset.* import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash import net.corda.core.crypto.toBase58String import net.corda.core.node.services.Vault -import net.corda.core.node.services.VaultQueryService import net.corda.core.node.services.VaultService import net.corda.core.schemas.CommonSchemaV1 import net.corda.core.schemas.PersistentStateRef @@ -17,8 +13,6 @@ import net.corda.core.transactions.SignedTransaction import net.corda.node.services.identity.InMemoryIdentityService import net.corda.node.services.schema.HibernateObserver import net.corda.node.services.schema.NodeSchemaService -import net.corda.node.services.vault.HibernateVaultQueryImpl -import net.corda.node.services.vault.NodeVaultService import net.corda.node.services.vault.VaultSchemaV1 import net.corda.node.utilities.CordaPersistence import net.corda.node.utilities.configureDatabase @@ -52,6 +46,7 @@ import javax.persistence.criteria.CriteriaBuilder class HibernateConfigurationTest : TestDependencyInjectionBase() { lateinit var services: MockServices + lateinit var issuerServices: MockServices lateinit var database: CordaPersistence val vault: VaultService get() = services.vaultService @@ -67,6 +62,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { @Before fun setUp() { + issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, BOB_KEY, BOC_KEY) val dataSourceProps = makeTestDataSourceProperties() val defaultDatabaseProperties = makeTestDatabaseProperties() database = configureDatabase(dataSourceProps, defaultDatabaseProperties) @@ -74,7 +70,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { database.transaction { val identityService = InMemoryIdentityService(MOCK_IDENTITIES, trustRoot = DUMMY_CA.certificate) hibernateConfig = HibernateConfiguration(NodeSchemaService(customSchemas), makeTestDatabaseProperties(), identityService) - services = object : MockServices(BOB_KEY) { + services = object : MockServices(BOB_KEY, BOC_KEY, DUMMY_NOTARY_KEY) { override val vaultService: VaultService = makeVaultService(dataSourceProps, hibernateConfig) override fun recordTransactions(txs: Iterable) { @@ -102,7 +98,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { private fun setUpDb() { database.transaction { - cashStates = services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)).states.toList() + cashStates = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)).states.toList() } } @@ -121,7 +117,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { @Test fun `consumed states`() { database.transaction { - services.consumeCash(50.DOLLARS) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) } // structure query @@ -200,11 +196,11 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { fun `with sorting by state ref desc and asc`() { // generate additional state ref indexes database.transaction { - services.consumeCash(1.DOLLARS) - services.consumeCash(2.DOLLARS) - services.consumeCash(3.DOLLARS) - services.consumeCash(4.DOLLARS) - services.consumeCash(5.DOLLARS) + services.consumeCash(1.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(2.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(3.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(4.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(5.DOLLARS, notary = DUMMY_NOTARY) } // structure query @@ -230,11 +226,11 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { fun `with sorting by state ref index and txId desc and asc`() { // generate additional state ref indexes database.transaction { - services.consumeCash(1.DOLLARS) - services.consumeCash(2.DOLLARS) - services.consumeCash(3.DOLLARS) - services.consumeCash(4.DOLLARS) - services.consumeCash(5.DOLLARS) + services.consumeCash(1.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(2.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(3.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(4.DOLLARS, notary = DUMMY_NOTARY) + services.consumeCash(5.DOLLARS, notary = DUMMY_NOTARY) } // structure query @@ -261,7 +257,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { fun `with pagination`() { // add 100 additional cash entries database.transaction { - services.fillWithSomeTestCash(1000.POUNDS, DUMMY_NOTARY, 100, 100, Random(0L)) + services.fillWithSomeTestCash(1000.POUNDS, issuerServices, DUMMY_NOTARY, 100, 100, Random(0L), issuedBy = DUMMY_CASH_ISSUER) } // structure query @@ -363,11 +359,11 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { fun `calculate cash balances`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) // +$100 = $200 - services.fillWithSomeTestCash(50.POUNDS, DUMMY_NOTARY, 5, 5, Random(0L)) // £50 = £50 - services.fillWithSomeTestCash(25.POUNDS, DUMMY_NOTARY, 5, 5, Random(0L)) // +£25 = £175 - services.fillWithSomeTestCash(500.SWISS_FRANCS, DUMMY_NOTARY, 10, 10, Random(0L)) // CHF500 = CHF500 - services.fillWithSomeTestCash(250.SWISS_FRANCS, DUMMY_NOTARY, 5, 5, Random(0L)) // +CHF250 = CHF750 + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) // +$100 = $200 + services.fillWithSomeTestCash(50.POUNDS, issuerServices, DUMMY_NOTARY, 5, 5, Random(0L)) // £50 = £50 + services.fillWithSomeTestCash(25.POUNDS, issuerServices, DUMMY_NOTARY, 5, 5, Random(0L)) // +£25 = £175 + services.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) // CHF500 = CHF500 + services.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 5, 5, Random(0L)) // +CHF250 = CHF750 } // structure query @@ -396,8 +392,8 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { @Test fun `calculate cash balance for single currency`() { database.transaction { - services.fillWithSomeTestCash(50.POUNDS, DUMMY_NOTARY, 5, 5, Random(0L)) // £50 = £50 - services.fillWithSomeTestCash(25.POUNDS, DUMMY_NOTARY, 5, 5, Random(0L)) // +£25 = £175 + services.fillWithSomeTestCash(50.POUNDS, issuerServices, DUMMY_NOTARY, 5, 5, Random(0L)) // £50 = £50 + services.fillWithSomeTestCash(25.POUNDS, issuerServices, DUMMY_NOTARY, 5, 5, Random(0L)) // +£25 = £175 } // structure query @@ -427,9 +423,9 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { fun `calculate and order by cash balance for owner and currency`() { database.transaction { - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1), issuerKey = BOC_KEY) - services.fillWithSomeTestCash(300.POUNDS, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(400.POUNDS, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2), issuerKey = BOC_KEY) + services.fillWithSomeTestCash(200.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) + services.fillWithSomeTestCash(300.POUNDS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) + services.fillWithSomeTestCash(400.POUNDS, issuerServices, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2)) } // structure query @@ -618,9 +614,9 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), ownedBy = ALICE) - val cashStates = services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), - issuedBy = BOB.ref(0), issuerKey = BOB_KEY, ownedBy = (BOB)).states + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L), ownedBy = ALICE) + val cashStates = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L), + issuedBy = BOB.ref(0), ownedBy = (BOB)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data @@ -699,8 +695,8 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - val moreCash = services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), - issuedBy = BOB.ref(0), issuerKey = BOB_KEY, ownedBy = BOB).states + val moreCash = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L), + issuedBy = BOB.ref(0), ownedBy = BOB).states // persist additional cash states explicitly with V3 schema moreCash.forEach { val cashState = it.state.data @@ -708,7 +704,7 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - val cashStates = services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), ownedBy = (ALICE)).states + val cashStates = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L), ownedBy = (ALICE)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data diff --git a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt index a55801327b..418c62f631 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt @@ -3,6 +3,7 @@ package net.corda.node.services.vault import co.paralleluniverse.fibers.Suspendable import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER +import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.contracts.asset.sumCash import net.corda.contracts.getCashBalance import net.corda.core.contracts.* @@ -10,11 +11,7 @@ import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party -import net.corda.core.node.services.StatesNotAvailableException -import net.corda.core.node.services.Vault -import net.corda.core.node.services.VaultQueryService -import net.corda.core.node.services.VaultService -import net.corda.core.node.services.queryBy +import net.corda.core.node.services.* import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.node.services.vault.QueryCriteria.* import net.corda.core.transactions.NotaryChangeWireTransaction @@ -23,9 +20,6 @@ import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.toNonEmptySet -import net.corda.node.services.database.HibernateConfiguration -import net.corda.node.services.identity.InMemoryIdentityService -import net.corda.node.services.schema.NodeSchemaService import net.corda.node.utilities.CordaPersistence import net.corda.testing.* import net.corda.testing.contracts.fillWithSomeTestCash @@ -47,6 +41,7 @@ import kotlin.test.assertTrue class NodeVaultServiceTest : TestDependencyInjectionBase() { lateinit var services: MockServices + lateinit var issuerServices: MockServices val vaultSvc: VaultService get() = services.vaultService val vaultQuery: VaultQueryService get() = services.vaultQueryService lateinit var database: CordaPersistence @@ -54,9 +49,10 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { @Before fun setUp() { LogHelper.setLevel(NodeVaultService::class) - val databaseAndServices = makeTestDatabaseAndMockServices() + val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(BOC_KEY, DUMMY_CASH_ISSUER_KEY)) database = databaseAndServices.first services = databaseAndServices.second + issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, BOC_KEY) } @After @@ -88,7 +84,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `states not local to instance`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) val w1 = vaultQuery.queryBy().states assertThat(w1).hasSize(3) @@ -115,7 +111,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `states for refs`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) val w1 = vaultQuery.queryBy().states assertThat(w1).hasSize(3) @@ -129,7 +125,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `states soft locking reserve and release`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) val unconsumedStates = vaultQuery.queryBy().states assertThat(unconsumedStates).hasSize(3) @@ -180,7 +176,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -235,7 +231,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -263,7 +259,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -290,7 +286,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -312,7 +308,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `unconsumedStatesForSpending exact amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) val unconsumedStates = vaultQuery.queryBy().states assertThat(unconsumedStates).hasSize(1) @@ -330,8 +326,8 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `unconsumedStatesForSpending from two issuer parties`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), issuerKey = BOC_KEY) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1))) val spendableStatesUSD = vaultSvc.unconsumedCashStatesForSpending(200.DOLLARS, onlyFromIssuerParties = setOf(DUMMY_CASH_ISSUER.party, BOC)) @@ -347,10 +343,10 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `unconsumedStatesForSpending from specific issuer party and refs`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(1)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(2)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(2)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(3)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(3)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), ref = OpaqueBytes.of(1)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(2)), ref = OpaqueBytes.of(2)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(3)), ref = OpaqueBytes.of(3)) val unconsumedStates = vaultQuery.queryBy().states assertThat(unconsumedStates).hasSize(4) @@ -369,7 +365,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `unconsumedStatesForSpending insufficient amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) val unconsumedStates = vaultQuery.queryBy().states assertThat(unconsumedStates).hasSize(1) @@ -386,7 +382,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `unconsumedStatesForSpending small amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) val unconsumedStates = vaultQuery.queryBy().states assertThat(unconsumedStates).hasSize(2) @@ -404,9 +400,9 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { fun `states soft locking query granularity`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 10, 10, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) var unlockedStates = 30 val allStates = vaultQuery.queryBy().states @@ -535,21 +531,20 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { // Issue some cash val issueTxBuilder = TransactionBuilder(notary).apply { Cash().generateIssue(this, amount, anonymousIdentity.party, notary) - signWith(BOC_KEY) } + val issueStx = services.signInitialTransaction(issueTxBuilder) // We need to record the issue transaction so inputs can be resolved for the notary change transaction - services.validatedTransactions.addTransaction(issueTxBuilder.toSignedTransaction()) + services.validatedTransactions.addTransaction(issueStx) - val issueTx = issueTxBuilder.toWireTransaction() - val initialCashState = StateAndRef(issueTx.outputs.single(), StateRef(issueTx.id, 0)) + val initialCashState = StateAndRef(issueStx.tx.outputs.single(), StateRef(issueStx.id, 0)) // Change notary val newNotary = DUMMY_NOTARY - val changeNotaryTx = NotaryChangeWireTransaction(listOf(initialCashState.ref), issueTx.notary!!, newNotary) + val changeNotaryTx = NotaryChangeWireTransaction(listOf(initialCashState.ref), issueStx.notary!!, newNotary) val cashStateWithNewNotary = StateAndRef(initialCashState.state.copy(notary = newNotary), StateRef(changeNotaryTx.id, 0)) database.transaction { - service.notifyAll(listOf(issueTx, changeNotaryTx)) + service.notifyAll(listOf(issueStx.tx, changeNotaryTx)) } // Move cash diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 5f145243ca..3dacf3f2c1 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -5,6 +5,7 @@ import net.corda.contracts.Commodity import net.corda.contracts.DealState import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER +import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash import net.corda.core.crypto.entropyToKeyPair @@ -52,15 +53,17 @@ import java.util.* class VaultQueryTests : TestDependencyInjectionBase() { lateinit var services: MockServices + lateinit var notaryServices: MockServices val vaultSvc: VaultService get() = services.vaultService val vaultQuerySvc: VaultQueryService get() = services.vaultQueryService lateinit var database: CordaPersistence @Before fun setUp() { - val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(MEGA_CORP_KEY)) + val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(MEGA_CORP_KEY, DUMMY_NOTARY_KEY)) database = databaseAndServices.first services = databaseAndServices.second + notaryServices = MockServices(DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) } @After @@ -86,7 +89,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { _database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val linearStatesXYZ = services.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesJKL = services.fillWithSomeTestLinearStates(2, "JKL") services.fillWithSomeTestLinearStates(3, "ABC") @@ -97,10 +100,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { sleep(delay) // consume some states - services.consumeLinearStates(linearStatesXYZ.states.toList()) - services.consumeLinearStates(linearStatesJKL.states.toList()) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }) - services.consumeCash(50.DOLLARS) + services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10 // Total consumed states = 6 + 1 + 2 + 1 = 10 @@ -130,7 +133,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states simple`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -157,7 +160,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states verbose`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -173,10 +176,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states with count`() { database.transaction { - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) @@ -184,7 +187,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) - services.consumeCash(75.DOLLARS) + services.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED) val resultsAfterConsume = vaultQuerySvc.queryBy(consumedCriteria, paging) @@ -197,7 +200,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash states simple`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -212,7 +215,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash states verbose`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -230,11 +233,11 @@ class VaultQueryTests : TestDependencyInjectionBase() { val stateRefs: MutableList = mutableListOf() - val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) + val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val issuedStateRefs = issuedStates.states.map { it.ref }.toList() stateRefs.addAll(issuedStateRefs) - val spentStates = services.consumeCash(25.DOLLARS) + val spentStates = services.consumeCash(25.DOLLARS, notary = DUMMY_NOTARY) val consumedStateRefs = spentStates.consumed.map { it.ref }.toList() val producedStateRefs = spentStates.produced.map { it.ref }.toList() stateRefs.addAll(consumedStateRefs.plus(producedStateRefs)) @@ -259,10 +262,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Test fun `unconsumed cash states sorted by state ref txnId and index`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val consumed = mutableSetOf() - services.consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash } - services.consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash } + services.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } + services.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } val sortAttributeTxnId = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_TXN_ID) val sortAttributeIndex = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_INDEX) @@ -305,7 +308,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Test fun `unconsumed states for contract state types`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -322,14 +325,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Test fun `consumed states`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId services.fillWithSomeTestLinearStates(8) val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.consumeLinearStates(linearStates.states.toList()) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }) - services.consumeCash(50.DOLLARS) + services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultQuerySvc.queryBy(criteria) @@ -341,10 +344,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `consumed states with count`() { database.transaction { - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) @@ -352,7 +355,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) - services.consumeCash(75.DOLLARS) + services.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val resultsAfterConsume = vaultQuerySvc.queryBy(consumedCriteria, paging) @@ -364,14 +367,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Test fun `all states`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID services.fillWithSomeTestLinearStates(8) val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.consumeLinearStates(linearStates.states.toList()) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }) - services.consumeCash(50.DOLLARS) // generates a new change state! + services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // generates a new change state! val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val results = vaultQuerySvc.queryBy(criteria) @@ -383,7 +386,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `all states with count`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) @@ -391,7 +394,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(resultsBeforeConsume.states).hasSize(1) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(1) - services.consumeCash(50.DOLLARS) // consumed 100 (spent), produced 50 (change) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // consumed 100 (spent), produced 50 (change) val resultsAfterConsume = vaultQuerySvc.queryBy(criteria, paging) assertThat(resultsAfterConsume.states).hasSize(2) @@ -406,7 +409,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states by notary`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, CASH_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -454,7 +457,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states with soft locking`() { database.transaction { - val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, CASH_NOTARY, 10, 10, Random(0L)).states.toList() + val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)).states.toList() vaultSvc.softLockReserve(UUID.randomUUID(), NonEmptySet.of(issuedStates[1].ref, issuedStates[2].ref, issuedStates[3].ref)) val lockId1 = UUID.randomUUID() vaultSvc.softLockReserve(lockId1, NonEmptySet.of(issuedStates[4].ref, issuedStates[5].ref)) @@ -498,9 +501,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator EQUAL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -513,9 +516,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator NOT EQUAL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notEqual(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -528,9 +531,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator GREATER_THAN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -543,9 +546,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator GREATER_THAN_OR_EQUAL`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -558,9 +561,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator LESS_THAN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -573,9 +576,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator LESS_THAN_OR_EQUAL`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -588,9 +591,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator BETWEEN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.between(500L, 1500L) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -603,9 +606,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator IN`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.`in`(currencies) } @@ -619,9 +622,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator NOT IN`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notIn(currencies) } @@ -635,9 +638,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator LIKE`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.like("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -650,9 +653,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator NOT LIKE`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notLike("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -665,9 +668,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator IS_NULL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerParty.isNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -680,9 +683,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `logical operator NOT_NULL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerParty.notNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -695,11 +698,11 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `aggregate functions without group clause`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) + services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) // DOCSTART VaultQueryExample21 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum() } @@ -737,11 +740,11 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `aggregate functions with single group clause`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) + services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) // DOCSTART VaultQueryExample22 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } @@ -797,10 +800,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `aggregate functions sum by issuer and currency and sort by aggregate sum`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1), issuerKey = BOC_KEY) - services.fillWithSomeTestCash(300.POUNDS, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(400.POUNDS, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2), issuerKey = BOC_KEY) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) + services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) + services.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) + services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2)) // DOCSTART VaultQueryExample23 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::issuerParty, @@ -832,7 +835,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `aggregate functions count by contract type`() { database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, CASH_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)) services.fillWithSomeTestLinearStates(1, "XYZ") services.fillWithSomeTestLinearStates(2, "JKL") services.fillWithSomeTestLinearStates(3, "ABC") @@ -858,7 +861,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `aggregate functions count by contract type and state status`() { database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val linearStatesXYZ = services.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesJKL = services.fillWithSomeTestLinearStates(2, "JKL") services.fillWithSomeTestLinearStates(3, "ABC") @@ -881,10 +884,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(dealStateCount).isEqualTo(3L) // consume some states - services.consumeLinearStates(linearStatesXYZ.states.toList()) - services.consumeLinearStates(linearStatesJKL.states.toList()) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }) - val cashUpdates = services.consumeCash(50.DOLLARS) + services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + val cashUpdates = services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // UNCONSUMED states (default) @@ -924,7 +927,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed states recorded between two time intervals`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, CASH_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) // DOCSTART VaultQueryExample6 val start = TODAY @@ -950,11 +953,11 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `states consumed after time`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.consumeCash(100.DOLLARS) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) val asOfDateTime = TODAY val consumedAfterExpression = TimeCondition( @@ -972,7 +975,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `all states with paging specification - first page`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 100, 100, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) // DOCSTART VaultQueryExample7 val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, 10) @@ -989,7 +992,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `all states with paging specification - last`() { database.transaction { - services.fillWithSomeTestCash(95.DOLLARS, DUMMY_NOTARY, 95, 95, Random(0L)) + services.fillWithSomeTestCash(95.DOLLARS, notaryServices, DUMMY_NOTARY, 95, 95, Random(0L)) // Last page implies we need to perform a row count for the Query first, // and then re-query for a given offset defined by (count - pageSize) @@ -1010,7 +1013,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 100, 100, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) val pagingSpec = PageSpecification(0, 10) @@ -1027,7 +1030,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 100, 100, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, MAX_PAGE_SIZE + 1) // overflow = -2147483648 val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -1043,7 +1046,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { - services.fillWithSomeTestCash(201.DOLLARS, DUMMY_NOTARY, 201, 201, Random(0L)) + services.fillWithSomeTestCash(201.DOLLARS, notaryServices, DUMMY_NOTARY, 201, 201, Random(0L)) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) vaultQuerySvc.queryBy(criteria) @@ -1083,8 +1086,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) services.fillWithSomeTestLinearStates(10) val results = vaultQuerySvc.queryBy>() @@ -1096,9 +1099,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `consumed fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.consumeCash(50.DOLLARS) - services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) services.fillWithSomeTestLinearStates(10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) @@ -1111,7 +1114,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) val results = vaultQuerySvc.queryBy() @@ -1123,8 +1126,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash fungible assets after spending`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.consumeCash(50.DOLLARS) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change) val results = vaultQuerySvc.queryBy(FungibleAssetQueryCriteria()) @@ -1137,10 +1140,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `consumed cash fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.consumeCash(50.DOLLARS) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val linearStates = services.fillWithSomeTestLinearStates(10) - services.consumeLinearStates(linearStates.states.toList()) + services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultQuerySvc.queryBy(criteria) @@ -1152,7 +1155,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed linear heads`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) services.fillWithSomeTestLinearStates(10) services.fillWithSomeTestDeals(listOf("123", "456", "789")) @@ -1165,14 +1168,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `consumed linear heads`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId services.fillWithSomeTestLinearStates(8) val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.consumeLinearStates(linearStates.states.toList()) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }) - services.consumeCash(50.DOLLARS) + services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultQuerySvc.queryBy(criteria) @@ -1219,9 +1222,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { val txns = services.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() val linearId = linearState.state.data.linearId - services.evolveLinearState(linearState) // consume current and produce new state reference - services.evolveLinearState(linearState) // consume current and produce new state reference - services.evolveLinearState(linearState) // consume current and produce new state reference + services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference + services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference + services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" // DOCSTART VaultQueryExample9 @@ -1239,9 +1242,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { val txns = services.fillWithSomeTestLinearStates(2, "TEST") val linearStates = txns.states.toList() - services.evolveLinearStates(linearStates) // consume current and produce new state reference - services.evolveLinearStates(linearStates) // consume current and produce new state reference - services.evolveLinearStates(linearStates) // consume current and produce new state reference + services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference + services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference + services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" val linearStateCriteria = LinearStateQueryCriteria(linearId = linearStates.map { it.state.data.linearId }, status = Vault.StateStatus.ALL) @@ -1303,7 +1306,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Custom(DummyLinearStateSchemaV1.PersistentDummyLinearState::class.java, "linearString"), Sort.Direction.DESC))) val results = vaultQuerySvc.queryBy((vaultCriteria), sorting = sorting) - results.states.forEach { println("${it.state.data.linearString}") } + results.states.forEach { println(it.state.data.linearString) } assertThat(results.states).hasSize(6) } } @@ -1314,9 +1317,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { val txns = services.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() - val linearState2 = services.evolveLinearState(linearState) // consume current and produce new state reference - val linearState3 = services.evolveLinearState(linearState2) // consume current and produce new state reference - services.evolveLinearState(linearState3) // consume current and produce new state reference + val linearState2 = services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference + val linearState3 = services.evolveLinearState(linearState2, DUMMY_NOTARY) // consume current and produce new state reference + services.evolveLinearState(linearState3, DUMMY_NOTARY) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" val linearStateCriteria = LinearStateQueryCriteria(linearId = txns.states.map { it.state.data.linearId }, status = Vault.StateStatus.CONSUMED) @@ -1399,10 +1402,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets for specific issuer party and refs`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(1)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(2)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(2)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(3)), issuerKey = BOC_KEY, ref = OpaqueBytes.of(3)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), ref = OpaqueBytes.of(1)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(2)), ref = OpaqueBytes.of(2)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(3)), ref = OpaqueBytes.of(3)) val criteria = FungibleAssetQueryCriteria(issuerPartyName = listOf(BOC), issuerRef = listOf(BOC.ref(1).reference, BOC.ref(2).reference)) @@ -1414,21 +1417,24 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Test fun `unconsumed fungible assets for selected issuer parties`() { // GBP issuer - val GBP_CASH_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(1001)) } - val GBP_CASH_ISSUER by lazy { Party(X500Name("CN=British Pounds Cash Issuer,O=R3,OU=corda,L=London,C=GB"), GBP_CASH_ISSUER_KEY.public).ref(1) } + val gbpCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1001)) + val gbpCashIssuer = Party(X500Name("CN=British Pounds Cash Issuer,O=R3,OU=corda,L=London,C=GB"), gbpCashIssuerKey.public).ref(1) + val gbpCashIssuerServices = MockServices(gbpCashIssuerKey) // USD issuer - val USD_CASH_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(1002)) } - val USD_CASH_ISSUER by lazy { Party(X500Name("CN=US Dollars Cash Issuer,O=R3,OU=corda,L=New York,C=US"), USD_CASH_ISSUER_KEY.public).ref(1) } + val usdCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1002)) + val usdCashIssuer = Party(X500Name("CN=US Dollars Cash Issuer,O=R3,OU=corda,L=New York,C=US"), usdCashIssuerKey.public).ref(1) + val usdCashIssuerServices = MockServices(usdCashIssuerKey) // CHF issuer - val CHF_CASH_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(1003)) } - val CHF_CASH_ISSUER by lazy { Party(X500Name("CN=Swiss Francs Cash Issuer,O=R3,OU=corda,L=Zurich,C=CH"), CHF_CASH_ISSUER_KEY.public).ref(1) } + val chfCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1003)) + val chfCashIssuer = Party(X500Name("CN=Swiss Francs Cash Issuer,O=R3,OU=corda,L=Zurich,C=CH"), chfCashIssuerKey.public).ref(1) + val chfCashIssuerServices = MockServices(chfCashIssuerKey) database.transaction { - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (GBP_CASH_ISSUER), issuerKey = (GBP_CASH_ISSUER_KEY)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (USD_CASH_ISSUER), issuerKey = (USD_CASH_ISSUER_KEY)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (CHF_CASH_ISSUER), issuerKey = (CHF_CASH_ISSUER_KEY)) + services.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (gbpCashIssuer)) + services.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (usdCashIssuer)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (chfCashIssuer)) - val criteria = FungibleAssetQueryCriteria(issuerPartyName = listOf(GBP_CASH_ISSUER.party, USD_CASH_ISSUER.party)) + val criteria = FungibleAssetQueryCriteria(issuerPartyName = listOf(gbpCashIssuer.party, usdCashIssuer.party)) val results = vaultQuerySvc.queryBy>(criteria) assertThat(results.states).hasSize(2) } @@ -1438,9 +1444,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets by owner`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = MEGA_CORP.ref(0), issuerKey = MEGA_CORP_KEY, ownedBy = (MEGA_CORP)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + issuedBy = MEGA_CORP.ref(0), ownedBy = (MEGA_CORP)) val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP)) val results = vaultQuerySvc.queryBy>(criteria) @@ -1453,14 +1459,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible states for owners`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, CASH_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = MEGA_CORP.ref(0), issuerKey = MEGA_CORP_KEY, ownedBy = (MEGA_CORP)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = MINI_CORP.ref(0), issuerKey = MINI_CORP_KEY, ownedBy = (MINI_CORP)) // irrelevant to this vault + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + issuedBy = MEGA_CORP.ref(0), ownedBy = (MEGA_CORP)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + issuedBy = BOC.ref(0), ownedBy = (MINI_CORP)) // irrelevant to this vault // DOCSTART VaultQueryExample5.2 - val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP,MINI_CORP)) + val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP, BOC)) val results = vaultQuerySvc.queryBy(criteria) // DOCEND VaultQueryExample5.2 @@ -1474,9 +1480,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) // DOCSTART VaultQueryExample12 val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(USD.currencyCode) } @@ -1492,8 +1498,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash balance for single currency`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -1513,12 +1519,12 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed cash balances for all currencies`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.POUNDS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, DUMMY_NOTARY, 5, 5, Random(0L)) - services.fillWithSomeTestCash(600.SWISS_FRANCS, DUMMY_NOTARY, 6, 6, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) + services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(600.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 6, 6, Random(0L)) val ccyIndex = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val criteria = VaultCustomQueryCriteria(ccyIndex) @@ -1538,10 +1544,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets for quantity greater than`() { database.transaction { - services.fillWithSomeTestCash(10.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(25.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(50.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(25.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) // DOCSTART VaultQueryExample13 val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(2500L) }) @@ -1556,8 +1562,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets for issuer party`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), issuerKey = BOC_KEY) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1))) // DOCSTART VaultQueryExample14 val criteria = FungibleAssetQueryCriteria(issuerPartyName = listOf(BOC)) @@ -1572,10 +1578,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `unconsumed fungible assets for single currency and quantity greater than`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(50.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val customCriteria = VaultCustomQueryCriteria(ccyIndex) @@ -1598,21 +1604,22 @@ class VaultQueryTests : TestDependencyInjectionBase() { // MegaCorp™ issues $10,000 of commercial paper, to mature in 30 days, owned by itself. val faceValue = 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER val commercialPaper = - CommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { - setTimeWindow(TEST_TX_TIME, 30.seconds) - signWith(MEGA_CORP_KEY) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + CommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY).let { builder -> + builder.setTimeWindow(TEST_TX_TIME, 30.seconds) + val stx = services.signInitialTransaction(builder, MEGA_CORP_PUBKEY) + notaryServices.addSignature(stx, DUMMY_NOTARY_KEY.public) + } + services.recordTransactions(commercialPaper) // MegaCorp™ now issues £10,000 of commercial paper, to mature in 30 days, owned by itself. val faceValue2 = 10000.POUNDS `issued by` DUMMY_CASH_ISSUER val commercialPaper2 = - CommercialPaper().generateIssue(issuance, faceValue2, TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { - setTimeWindow(TEST_TX_TIME, 30.seconds) - signWith(MEGA_CORP_KEY) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + CommercialPaper().generateIssue(issuance, faceValue2, TEST_TX_TIME + 30.days, DUMMY_NOTARY).let { builder -> + builder.setTimeWindow(TEST_TX_TIME, 30.seconds) + val stx = services.signInitialTransaction(builder, MEGA_CORP_PUBKEY) + notaryServices.addSignature(stx, DUMMY_NOTARY_KEY.public) + } services.recordTransactions(commercialPaper2) val ccyIndex = builder { CommercialPaperSchemaV1.PersistentCommercialPaperState::currency.equal(USD.currencyCode) } @@ -1635,21 +1642,23 @@ class VaultQueryTests : TestDependencyInjectionBase() { // MegaCorp™ issues $10,000 of commercial paper, to mature in 30 days, owned by itself. val faceValue = 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER val commercialPaper = - CommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { - setTimeWindow(TEST_TX_TIME, 30.seconds) - signWith(MEGA_CORP_KEY) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + CommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY).let { builder -> + builder.setTimeWindow(TEST_TX_TIME, 30.seconds) + val stx = services.signInitialTransaction(builder, MEGA_CORP_PUBKEY) + notaryServices.addSignature(stx, DUMMY_NOTARY_KEY.public) + } + commercialPaper.verifyRequiredSignatures() services.recordTransactions(commercialPaper) // MegaCorp™ now issues £5,000 of commercial paper, to mature in 30 days, owned by itself. val faceValue2 = 5000.POUNDS `issued by` DUMMY_CASH_ISSUER val commercialPaper2 = - CommercialPaper().generateIssue(issuance, faceValue2, TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { - setTimeWindow(TEST_TX_TIME, 30.seconds) - signWith(MEGA_CORP_KEY) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + CommercialPaper().generateIssue(issuance, faceValue2, TEST_TX_TIME + 30.days, DUMMY_NOTARY).let { builder -> + builder.setTimeWindow(TEST_TX_TIME, 30.seconds) + val stx = services.signInitialTransaction(builder, MEGA_CORP_PUBKEY) + notaryServices.addSignature(stx, DUMMY_NOTARY_KEY.public) + } + commercialPaper2.verifyRequiredSignatures() services.recordTransactions(commercialPaper2) val result = builder { @@ -1675,9 +1684,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { fun `query attempting to use unregistered schema`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // CashSchemaV3 NOT registered with NodeSchemaService val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) } @@ -1697,10 +1706,10 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(1.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // DOCSTART VaultQueryExample20 val generalCriteria = VaultQueryCriteria(Vault.StateStatus.ALL) @@ -1800,7 +1809,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { services.fillWithSomeTestLinearStates(1, "TEST1") val aState = services.fillWithSomeTestLinearStates(1, "TEST2").states - services.consumeLinearStates(aState.toList()) + services.consumeLinearStates(aState.toList(), DUMMY_NOTARY) val uuid = services.fillWithSomeTestLinearStates(1, "TEST3").states.first().state.data.linearId.id // 2 unconsumed states with same external ID, 1 with different external ID @@ -1871,7 +1880,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val updates = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(10).states val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states @@ -1883,14 +1892,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(snapshot.statesMetadata).hasSize(5) // add more cash - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) // consume stuff - services.consumeCash(100.DOLLARS) - services.consumeDeals(dealStates.toList()) - services.consumeLinearStates(linearStates.toList()) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) updates } @@ -1899,12 +1908,12 @@ class VaultQueryTests : TestDependencyInjectionBase() { sequence( expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 5) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 1) {} } ) @@ -1916,17 +1925,17 @@ class VaultQueryTests : TestDependencyInjectionBase() { val updates = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(10).states val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) // consume stuff - services.consumeCash(100.POUNDS) + services.consumeCash(100.POUNDS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val (snapshot, updates) = vaultQuerySvc.trackBy(criteria) @@ -1935,9 +1944,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(snapshot.statesMetadata).hasSize(1) // consume more stuff - services.consumeCash(100.DOLLARS) - services.consumeDeals(dealStates.toList()) - services.consumeLinearStates(linearStates.toList()) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) updates } @@ -1947,12 +1956,12 @@ class VaultQueryTests : TestDependencyInjectionBase() { expect { (consumed, produced, flowId) -> require(flowId == null) {} require(consumed.size == 1) {} - require(produced.size == 0) {} + require(produced.isEmpty()) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} require(consumed.size == 5) {} - require(produced.size == 0) {} + require(produced.isEmpty()) {} } ) } @@ -1963,17 +1972,17 @@ class VaultQueryTests : TestDependencyInjectionBase() { val updates = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 5, 5, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(10).states val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) // consume stuff - services.consumeCash(99.POUNDS) + services.consumeCash(99.POUNDS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val (snapshot, updates) = vaultQuerySvc.trackBy(criteria) @@ -1982,9 +1991,9 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(snapshot.statesMetadata).hasSize(7) // consume more stuff - services.consumeCash(100.DOLLARS) - services.consumeDeals(dealStates.toList()) - services.consumeLinearStates(linearStates.toList()) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) updates } @@ -1993,12 +2002,12 @@ class VaultQueryTests : TestDependencyInjectionBase() { sequence( expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 5) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 1) {} }, expect { (consumed, produced, flowId) -> @@ -2009,7 +2018,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { expect { (consumed, produced, flowId) -> require(flowId == null) {} require(consumed.size == 5) {} - require(produced.size == 0) {} + require(produced.isEmpty()) {} } ) } @@ -2020,7 +2029,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val updates = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(10).states val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states @@ -2033,14 +2042,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(snapshot.statesMetadata).hasSize(13) // add more cash - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) // consume stuff - services.consumeCash(100.DOLLARS) - services.consumeDeals(dealStates.toList()) - services.consumeLinearStates(linearStates.toList()) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) updates } @@ -2049,17 +2058,17 @@ class VaultQueryTests : TestDependencyInjectionBase() { sequence( expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 10) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 3) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 1) {} } ) @@ -2071,7 +2080,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val updates = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) val linearStates = services.fillWithSomeTestLinearStates(10).states val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states @@ -2083,14 +2092,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { assertThat(snapshot.statesMetadata).hasSize(3) // add more cash - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) // consume stuff - services.consumeCash(100.DOLLARS) - services.consumeDeals(dealStates.toList()) - services.consumeLinearStates(linearStates.toList()) + services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) updates } @@ -2099,12 +2108,12 @@ class VaultQueryTests : TestDependencyInjectionBase() { sequence( expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 3) {} }, expect { (consumed, produced, flowId) -> require(flowId == null) {} - require(consumed.size == 0) {} + require(consumed.isEmpty()) {} require(produced.size == 1) {} } ) diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index ad16be499f..ac5c358897 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -2,6 +2,7 @@ package net.corda.node.services.vault import net.corda.contracts.asset.Cash import net.corda.contracts.asset.DUMMY_CASH_ISSUER +import net.corda.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.contracts.getCashBalance import net.corda.core.contracts.* import net.corda.core.identity.AnonymousParty @@ -34,6 +35,7 @@ import kotlin.test.assertEquals class VaultWithCashTest : TestDependencyInjectionBase() { lateinit var services: MockServices + lateinit var issuerServices: MockServices val vault: VaultService get() = services.vaultService val vaultQuery: VaultQueryService get() = services.vaultQueryService lateinit var database: CordaPersistence @@ -42,9 +44,10 @@ class VaultWithCashTest : TestDependencyInjectionBase() { @Before fun setUp() { LogHelper.setLevel(VaultWithCashTest::class) - val databaseAndServices = makeTestDatabaseAndMockServices() + val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(DUMMY_CASH_ISSUER_KEY, DUMMY_NOTARY_KEY)) database = databaseAndServices.first services = databaseAndServices.second + issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) } @After @@ -57,7 +60,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() { fun splits() { database.transaction { // Fix the PRNG so that we get the same splits every time. - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) val w = vaultQuery.queryBy().states assertEquals(3, w.size) @@ -117,10 +120,8 @@ class VaultWithCashTest : TestDependencyInjectionBase() { database.transaction { // A tx that sends us money. - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L), - issuedBy = MEGA_CORP.ref(1), - issuerKey = MEGA_CORP_KEY, - ownedBy = AnonymousParty(freshKey)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L), ownedBy = AnonymousParty(freshKey), + issuedBy = MEGA_CORP.ref(1)) println("Cash balance: ${services.getCashBalance(USD)}") assertThat(vaultQuery.queryBy().states).hasSize(10) @@ -269,9 +270,9 @@ class VaultWithCashTest : TestDependencyInjectionBase() { val freshKey = services.keyManagementService.freshKey() database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 3, 3, Random(0L), ownedBy = AnonymousParty(freshKey)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, DUMMY_NOTARY, 1, 1, Random(0L)) + services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), ownedBy = AnonymousParty(freshKey)) + services.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) + services.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) val cash = vaultQuery.queryBy().states cash.forEach { println(it.state.data.amount) } diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt index a6a616cf9c..a902252889 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/FixingFlow.kt @@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.contracts.Fix import net.corda.contracts.FixableDealState import net.corda.core.contracts.* +import net.corda.core.crypto.TransactionSignature import net.corda.core.crypto.toBase58String import net.corda.core.flows.FlowLogic import net.corda.core.flows.InitiatedBy @@ -12,13 +13,13 @@ import net.corda.core.flows.SchedulableFlow import net.corda.core.identity.Party import net.corda.core.node.NodeInfo import net.corda.core.node.services.ServiceType -import net.corda.core.utilities.seconds import net.corda.core.serialization.CordaSerializable import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.core.utilities.transient import net.corda.core.utilities.ProgressTracker +import net.corda.core.utilities.seconds import net.corda.core.utilities.trace +import net.corda.core.utilities.transient import net.corda.flows.TwoPartyDealFlow import java.math.BigDecimal import java.security.PublicKey @@ -52,7 +53,7 @@ object FixingFlow { } @Suspendable - override fun assembleSharedTX(handshake: TwoPartyDealFlow.Handshake): Pair> { + override fun assembleSharedTX(handshake: TwoPartyDealFlow.Handshake): Triple, List> { @Suppress("UNCHECKED_CAST") val fixOf = deal.nextFixingOf()!! @@ -85,9 +86,9 @@ object FixingFlow { } } } - subFlow(addFixing) + val sig = subFlow(addFixing) // DOCEND 1 - return Pair(ptx, arrayListOf(myOldParty.owningKey)) + return Triple(ptx, arrayListOf(myOldParty.owningKey), listOf(sig)) } } diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/RatesFixFlow.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/RatesFixFlow.kt index e73cbc5831..dde01b1226 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/RatesFixFlow.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/flows/RatesFixFlow.kt @@ -33,7 +33,7 @@ open class RatesFixFlow(protected val tx: TransactionBuilder, protected val fixOf: FixOf, protected val expectedRate: BigDecimal, protected val rateTolerance: BigDecimal, - override val progressTracker: ProgressTracker = RatesFixFlow.tracker(fixOf.name)) : FlowLogic() { + override val progressTracker: ProgressTracker = RatesFixFlow.tracker(fixOf.name)) : FlowLogic() { companion object { class QUERYING(val name: String) : ProgressTracker.Step("Querying oracle for $name interest rate") @@ -54,7 +54,7 @@ open class RatesFixFlow(protected val tx: TransactionBuilder, // DOCSTART 2 @Suspendable - override fun call() { + override fun call(): TransactionSignature { progressTracker.currentStep = progressTracker.steps[1] val fix = subFlow(FixQueryFlow(fixOf, oracle)) progressTracker.currentStep = WORKING @@ -63,8 +63,7 @@ open class RatesFixFlow(protected val tx: TransactionBuilder, beforeSigning(fix) progressTracker.currentStep = SIGNING val mtx = tx.toWireTransaction().buildFilteredTransaction(Predicate { filtering(it) }) - val signature = subFlow(FixSignFlow(tx, oracle, mtx)) - tx.addSignatureUnchecked(signature) + return subFlow(FixSignFlow(tx, oracle, mtx)) } // DOCEND 2 diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt index 34f4f4dda4..dfb30e6ebb 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt @@ -6,6 +6,8 @@ import net.corda.contracts.Commodity import net.corda.contracts.DealState import net.corda.contracts.asset.* import net.corda.core.contracts.* +import net.corda.core.crypto.Crypto +import net.corda.core.crypto.SignatureMetadata import net.corda.core.utilities.getOrThrow import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty @@ -19,7 +21,6 @@ import net.corda.core.utilities.OpaqueBytes import net.corda.testing.CHARLIE import net.corda.testing.DUMMY_NOTARY import net.corda.testing.DUMMY_NOTARY_KEY -import java.security.KeyPair import java.security.PublicKey import java.time.Duration import java.time.Instant @@ -28,17 +29,18 @@ import java.util.* @JvmOverloads fun ServiceHub.fillWithSomeTestDeals(dealIds: List, - participants: List = emptyList()) : Vault { + participants: List = emptyList(), + notary: Party = DUMMY_NOTARY) : Vault { val myKey: PublicKey = myInfo.legalIdentity.owningKey val me = AnonymousParty(myKey) val transactions: List = dealIds.map { // Issue a deal state - val dummyIssue = TransactionBuilder(notary = DUMMY_NOTARY).apply { + val dummyIssue = TransactionBuilder(notary = notary).apply { addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me))) - signWith(DUMMY_NOTARY_KEY) } - return@map signInitialTransaction(dummyIssue) + val stx = signInitialTransaction(dummyIssue) + return@map addSignature(stx, notary.owningKey) } recordTransactions(transactions) @@ -61,6 +63,8 @@ fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int, linearTimestamp: Instant = now()) : Vault { val myKey: PublicKey = myInfo.legalIdentity.owningKey val me = AnonymousParty(myKey) + val issuerKey = DUMMY_NOTARY_KEY + val signatureMetadata = SignatureMetadata(myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID) val transactions: List = (1..numberToCreate).map { // Issue a Linear state @@ -72,10 +76,9 @@ fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int, linearNumber = linearNumber, linearBoolean = linearBoolean, linearTimestamp = linearTimestamp)) - signWith(DUMMY_NOTARY_KEY) } - return@map signInitialTransaction(dummyIssue) + return@map signInitialTransaction(dummyIssue).withAdditionalSignature(issuerKey, signatureMetadata) } recordTransactions(transactions) @@ -95,18 +98,19 @@ fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int, * * The service hub needs to provide at least a key management service and a storage service. * + * @param issuerServices service hub of the issuer node, which will be used to sign the transaction. * @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary. * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!). */ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount, + issuerServices: ServiceHub = this, outputNotary: Party = DUMMY_NOTARY, atLeastThisManyStates: Int = 3, atMostThisManyStates: Int = 10, rng: Random = Random(), ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })), ownedBy: AbstractParty? = null, - issuedBy: PartyAndReference = DUMMY_CASH_ISSUER, - issuerKey: KeyPair = DUMMY_CASH_ISSUER_KEY): Vault { + issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault { val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) val myKey: PublicKey = ownedBy?.owningKey ?: myInfo.legalIdentity.owningKey @@ -117,9 +121,8 @@ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount, val transactions: List = amounts.map { pennies -> val issuance = TransactionBuilder(null as Party?) cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy.copy(reference = ref), howMuch.token)), me, outputNotary) - issuance.signWith(issuerKey) - return@map issuance.toSignedTransaction(true) + return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) } recordTransactions(transactions) @@ -132,21 +135,26 @@ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount, return Vault(states) } +/** + * + * @param issuerServices service hub of the issuer node, which will be used to sign the transaction. + * @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary. + * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!). + */ // TODO: need to make all FungibleAsset commands (issue, move, exit) generic fun ServiceHub.fillWithSomeTestCommodity(amount: Amount, + issuerServices: ServiceHub = this, outputNotary: Party = DUMMY_NOTARY, ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })), ownedBy: AbstractParty? = null, - issuedBy: PartyAndReference = DUMMY_OBLIGATION_ISSUER.ref(1), - issuerKey: KeyPair = DUMMY_OBLIGATION_ISSUER_KEY): Vault { + issuedBy: PartyAndReference = DUMMY_OBLIGATION_ISSUER.ref(1)): Vault { val myKey: PublicKey = ownedBy?.owningKey ?: myInfo.legalIdentity.owningKey val me = AnonymousParty(myKey) val commodity = CommodityContract() val issuance = TransactionBuilder(null as Party?) commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy.copy(reference = ref), amount.token)), me, outputNotary) - issuance.signWith(issuerKey) - val transaction = issuance.toSignedTransaction(true) + val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) recordTransactions(transaction) @@ -181,62 +189,62 @@ fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, return amounts } -fun ServiceHub.consume(states: List>) { +fun ServiceHub.consume(states: List>, notary: Party) { // Create a txn consuming different contract types states.forEach { - val consumedTx = TransactionBuilder(notary = DUMMY_NOTARY).apply { + val builder = TransactionBuilder(notary = notary).apply { addInputState(it) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + } + val consumedTx = signInitialTransaction(builder, notary.owningKey) recordTransactions(consumedTx) } } -fun ServiceHub.consumeAndProduce(stateAndRef: StateAndRef): StateAndRef { +fun ServiceHub.consumeAndProduce(stateAndRef: StateAndRef, notary: Party): StateAndRef { // Create a txn consuming different contract types - val consumedTx = TransactionBuilder(notary = DUMMY_NOTARY).apply { + var builder = TransactionBuilder(notary = notary).apply { addInputState(stateAndRef) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + } + val consumedTx = signInitialTransaction(builder, notary.owningKey) recordTransactions(consumedTx) // Create a txn consuming different contract types - val producedTx = TransactionBuilder(notary = DUMMY_NOTARY).apply { + builder = TransactionBuilder(notary = notary).apply { addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId, participants = stateAndRef.state.data.participants)) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction() + } + val producedTx = signInitialTransaction(builder, notary.owningKey) recordTransactions(producedTx) return producedTx.tx.outRef(0) } -fun ServiceHub.consumeAndProduce(states: List>) { +fun ServiceHub.consumeAndProduce(states: List>, notary: Party) { states.forEach { - consumeAndProduce(it) + consumeAndProduce(it, notary) } } -fun ServiceHub.consumeDeals(dealStates: List>) = consume(dealStates) -fun ServiceHub.consumeLinearStates(linearStates: List>) = consume(linearStates) -fun ServiceHub.evolveLinearStates(linearStates: List>) = consumeAndProduce(linearStates) -fun ServiceHub.evolveLinearState(linearState: StateAndRef) : StateAndRef = consumeAndProduce(linearState) +fun ServiceHub.consumeDeals(dealStates: List>, notary: Party) = consume(dealStates, notary) +fun ServiceHub.consumeLinearStates(linearStates: List>, notary: Party) = consume(linearStates, notary) +fun ServiceHub.evolveLinearStates(linearStates: List>, notary: Party) = consumeAndProduce(linearStates, notary) +fun ServiceHub.evolveLinearState(linearState: StateAndRef, notary: Party) : StateAndRef = consumeAndProduce(linearState, notary) @JvmOverloads -fun ServiceHub.consumeCash(amount: Amount, to: Party = CHARLIE): Vault.Update { +fun ServiceHub.consumeCash(amount: Amount, to: Party = CHARLIE, notary: Party): Vault.Update { val update = vaultService.rawUpdates.toFuture() val services = this // A tx that spends our money. - val spendTX = TransactionBuilder(DUMMY_NOTARY).apply { + val builder = TransactionBuilder(notary).apply { Cash.generateSpend(services, this, amount, to) - signWith(DUMMY_NOTARY_KEY) - }.toSignedTransaction(checkSufficientSignatures = false) + } + val spendTx = signInitialTransaction(builder, notary.owningKey) - recordTransactions(spendTX) + recordTransactions(spendTx) return update.getOrThrow(Duration.ofSeconds(3)) }