mirror of
https://github.com/corda/corda.git
synced 2024-12-24 07:06:44 +00:00
Test DSL: only "unverified" transactions get filled with dummy data to make them valid WireTransactions.
Recording is removed for a ledger with a single transaction.
This commit is contained in:
parent
65a59f680b
commit
210cb4658a
@ -1,6 +1,5 @@
|
||||
package net.corda.finance.contracts.asset;
|
||||
|
||||
import kotlin.Unit;
|
||||
import net.corda.core.contracts.PartyAndReference;
|
||||
import net.corda.core.identity.AnonymousParty;
|
||||
import net.corda.core.utilities.OpaqueBytes;
|
||||
@ -22,8 +21,7 @@ public class CashTestsJava {
|
||||
|
||||
@Test
|
||||
public void trivial() {
|
||||
ledger(lg -> {
|
||||
lg.transaction(tx -> {
|
||||
transaction(tx -> {
|
||||
tx.input(inState);
|
||||
|
||||
tx.tweak(tw -> {
|
||||
@ -59,7 +57,5 @@ public class CashTestsJava {
|
||||
return tw.verifies();
|
||||
});
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,9 @@ fun getFreeLocalPorts(hostName: String, numberToAlloc: Int): List<NetworkHostAnd
|
||||
transactionBuilder: TransactionBuilder = TransactionBuilder(notary = DUMMY_NOTARY),
|
||||
initialiseSerialization: Boolean = true,
|
||||
dsl: TransactionDSL<TransactionDSLInterpreter>.() -> EnforceVerifyOrFail
|
||||
) = ledger(initialiseSerialization = initialiseSerialization) { this.transaction(transactionLabel, transactionBuilder, dsl) }
|
||||
) = ledger(initialiseSerialization = initialiseSerialization) {
|
||||
dsl(TransactionDSL(TestTransactionDSLInterpreter(this.interpreter, transactionBuilder)))
|
||||
}
|
||||
|
||||
fun testNodeConfiguration(
|
||||
baseDirectory: Path,
|
||||
|
@ -244,11 +244,13 @@ data class TestLedgerDSLInterpreter private constructor(
|
||||
transactionLabel: String?,
|
||||
transactionBuilder: TransactionBuilder,
|
||||
dsl: TransactionDSL<TestTransactionDSLInterpreter>.() -> R,
|
||||
transactionMap: HashMap<SecureHash, WireTransactionWithLocation> = HashMap()
|
||||
transactionMap: HashMap<SecureHash, WireTransactionWithLocation> = HashMap(),
|
||||
/** If set to true, will add dummy components to [transactionBuilder] to make it valid. */
|
||||
fillTransaction: Boolean = false
|
||||
): WireTransaction {
|
||||
val transactionLocation = getCallerLocation()
|
||||
val transactionInterpreter = interpretTransactionDsl(transactionBuilder, dsl)
|
||||
makeTxValid(transactionBuilder)
|
||||
if (fillTransaction) fillTransaction(transactionBuilder)
|
||||
// Create the WireTransaction
|
||||
val wireTransaction = transactionInterpreter.toWireTransaction()
|
||||
// Record the output states
|
||||
@ -271,7 +273,7 @@ data class TestLedgerDSLInterpreter private constructor(
|
||||
* The base transaction may not be valid, but it still gets recorded to the ledger. This causes a test failure,
|
||||
* even though is not being used for anything afterwards.
|
||||
*/
|
||||
private fun makeTxValid(transactionBuilder: TransactionBuilder) {
|
||||
private fun fillTransaction(transactionBuilder: TransactionBuilder) {
|
||||
if (transactionBuilder.commands().isEmpty()) transactionBuilder.addCommand(dummyCommand())
|
||||
if (transactionBuilder.inputStates().isEmpty() && transactionBuilder.outputStates().isEmpty()) {
|
||||
transactionBuilder.addOutputState(DummyContract.SingleOwnerState(owner = ALICE))
|
||||
@ -288,7 +290,7 @@ data class TestLedgerDSLInterpreter private constructor(
|
||||
transactionLabel: String?,
|
||||
transactionBuilder: TransactionBuilder,
|
||||
dsl: TransactionDSL<TestTransactionDSLInterpreter>.() -> Unit
|
||||
) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations)
|
||||
) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations, fillTransaction = true)
|
||||
|
||||
override fun tweak(
|
||||
dsl: LedgerDSL<TestTransactionDSLInterpreter,
|
||||
|
Loading…
Reference in New Issue
Block a user