mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Ensure transactions in tests have commands (#1200)
* Ensure transactions in tests have commands
This commit is contained in:
parent
435dcf6af4
commit
1e0a26e8e5
@ -7,6 +7,7 @@ import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.MockServices
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@ -50,7 +51,11 @@ class LedgerTransactionQueryTests : TestDependencyInjectionBase() {
|
||||
|
||||
private fun makeDummyStateAndRef(data: Any): StateAndRef<*> {
|
||||
val dummyState = makeDummyState(data)
|
||||
val fakeIssueTx = services.signInitialTransaction(TransactionBuilder(notary = DUMMY_NOTARY).addOutputState(dummyState))
|
||||
val fakeIssueTx = services.signInitialTransaction(
|
||||
TransactionBuilder(notary = DUMMY_NOTARY)
|
||||
.addOutputState(dummyState)
|
||||
.addCommand(dummyCommand())
|
||||
)
|
||||
services.recordTransactions(fakeIssueTx)
|
||||
val dummyStateRef = StateRef(fakeIssueTx.id, 0)
|
||||
return StateAndRef(TransactionState(dummyState, DUMMY_NOTARY, null), dummyStateRef)
|
||||
|
@ -34,14 +34,15 @@ class TransactionGraphSearchTests : TestDependencyInjectionBase() {
|
||||
val notaryServices = MockServices(DUMMY_NOTARY_KEY)
|
||||
|
||||
val originBuilder = TransactionBuilder(DUMMY_NOTARY)
|
||||
originBuilder.addOutputState(DummyState(random31BitValue()))
|
||||
originBuilder.addCommand(command, MEGA_CORP_PUBKEY)
|
||||
.addOutputState(DummyState(random31BitValue()))
|
||||
.addCommand(command, MEGA_CORP_PUBKEY)
|
||||
|
||||
val originPtx = megaCorpServices.signInitialTransaction(originBuilder)
|
||||
val originTx = notaryServices.addSignature(originPtx)
|
||||
|
||||
val inputBuilder = TransactionBuilder(DUMMY_NOTARY)
|
||||
inputBuilder.addInputState(originTx.tx.outRef<DummyState>(0))
|
||||
.addInputState(originTx.tx.outRef<DummyState>(0))
|
||||
.addCommand(dummyCommand(MEGA_CORP_PUBKEY))
|
||||
|
||||
val inputPtx = megaCorpServices.signInitialTransaction(inputBuilder)
|
||||
val inputTx = megaCorpServices.addSignature(inputPtx)
|
||||
|
@ -488,7 +488,8 @@ class Obligation<P : Any> : Contract {
|
||||
*/
|
||||
fun generateCloseOutNetting(tx: TransactionBuilder,
|
||||
signer: AbstractParty,
|
||||
vararg states: State<P>) {
|
||||
vararg inputs: StateAndRef<State<P>>) {
|
||||
val states = inputs.map { it.state.data }
|
||||
val netState = states.firstOrNull()?.bilateralNetState
|
||||
|
||||
requireThat {
|
||||
@ -498,6 +499,7 @@ class Obligation<P : Any> : Contract {
|
||||
"signer is in the state parties" using (signer in netState!!.partyKeys)
|
||||
}
|
||||
|
||||
tx.withItems(*inputs)
|
||||
val out = states.reduce(State<P>::net)
|
||||
if (out.quantity > 0L)
|
||||
tx.addOutputState(out)
|
||||
@ -567,10 +569,14 @@ class Obligation<P : Any> : Contract {
|
||||
fun generatePaymentNetting(tx: TransactionBuilder,
|
||||
issued: Issued<Obligation.Terms<P>>,
|
||||
notary: Party,
|
||||
vararg states: State<P>) {
|
||||
vararg inputs: StateAndRef<State<P>>) {
|
||||
val states = inputs.map { it.state.data }
|
||||
requireThat {
|
||||
"all states are in the normal lifecycle state " using (states.all { it.lifecycle == Lifecycle.NORMAL })
|
||||
}
|
||||
|
||||
tx.withItems(*inputs)
|
||||
|
||||
val groups = states.groupBy { it.multilateralNetState }
|
||||
val partyLookup = HashMap<PublicKey, AbstractParty>()
|
||||
val signers = states.map { it.beneficiary }.union(states.map { it.obligor }).toSet()
|
||||
|
@ -69,15 +69,16 @@ class ObligationTests {
|
||||
fun trivial() {
|
||||
transaction {
|
||||
input { inState }
|
||||
this `fails with` "the amounts balance"
|
||||
|
||||
tweak {
|
||||
output { outState.copy(quantity = 2000.DOLLARS.quantity) }
|
||||
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
tweak {
|
||||
output { outState }
|
||||
// No command arguments
|
||||
command(CHARLIE.owningKey) { DummyCommandData }
|
||||
// Invalid command
|
||||
this `fails with` "required net.corda.contracts.asset.Obligation.Commands.Move command"
|
||||
}
|
||||
tweak {
|
||||
@ -225,8 +226,8 @@ class ObligationTests {
|
||||
@Test
|
||||
fun `generate close-out net transaction`() {
|
||||
initialiseTestSerialization()
|
||||
val obligationAliceToBob = oneMillionDollars.OBLIGATION between Pair(ALICE, BOB)
|
||||
val obligationBobToAlice = oneMillionDollars.OBLIGATION between Pair(BOB, ALICE)
|
||||
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB))
|
||||
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE))
|
||||
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
|
||||
Obligation<Currency>().generateCloseOutNetting(this, ALICE, obligationAliceToBob, obligationBobToAlice)
|
||||
}.toWireTransaction()
|
||||
@ -237,8 +238,8 @@ class ObligationTests {
|
||||
@Test
|
||||
fun `generate close-out net transaction with remainder`() {
|
||||
initialiseTestSerialization()
|
||||
val obligationAliceToBob = (2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(ALICE, BOB)
|
||||
val obligationBobToAlice = oneMillionDollars.OBLIGATION between Pair(BOB, ALICE)
|
||||
val obligationAliceToBob = getStateAndRef((2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(ALICE, BOB))
|
||||
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE))
|
||||
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
|
||||
Obligation<Currency>().generateCloseOutNetting(this, ALICE, obligationAliceToBob, obligationBobToAlice)
|
||||
}.toWireTransaction()
|
||||
@ -252,10 +253,10 @@ class ObligationTests {
|
||||
@Test
|
||||
fun `generate payment net transaction`() {
|
||||
initialiseTestSerialization()
|
||||
val obligationAliceToBob = oneMillionDollars.OBLIGATION between Pair(ALICE, BOB)
|
||||
val obligationBobToAlice = oneMillionDollars.OBLIGATION between Pair(BOB, ALICE)
|
||||
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB))
|
||||
val obligationBobToAlice = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(BOB, ALICE))
|
||||
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
|
||||
Obligation<Currency>().generatePaymentNetting(this, obligationAliceToBob.amount.token, DUMMY_NOTARY, obligationAliceToBob, obligationBobToAlice)
|
||||
Obligation<Currency>().generatePaymentNetting(this, obligationAliceToBob.state.data.amount.token, DUMMY_NOTARY, obligationAliceToBob, obligationBobToAlice)
|
||||
}.toWireTransaction()
|
||||
assertEquals(0, tx.outputs.size)
|
||||
}
|
||||
@ -264,17 +265,25 @@ class ObligationTests {
|
||||
@Test
|
||||
fun `generate payment net transaction with remainder`() {
|
||||
initialiseTestSerialization()
|
||||
val obligationAliceToBob = oneMillionDollars.OBLIGATION between Pair(ALICE, BOB)
|
||||
val obligationBobToAlice = (2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(BOB, ALICE)
|
||||
val tx = TransactionBuilder(null).apply {
|
||||
Obligation<Currency>().generatePaymentNetting(this, obligationAliceToBob.amount.token, DUMMY_NOTARY, obligationAliceToBob, obligationBobToAlice)
|
||||
val obligationAliceToBob = getStateAndRef(oneMillionDollars.OBLIGATION between Pair(ALICE, BOB))
|
||||
val obligationAliceToBobState = obligationAliceToBob.state.data
|
||||
val obligationBobToAlice = getStateAndRef((2000000.DOLLARS `issued by` defaultIssuer).OBLIGATION between Pair(BOB, ALICE))
|
||||
val obligationBobToAliceState = obligationBobToAlice.state.data
|
||||
val tx = TransactionBuilder(DUMMY_NOTARY).apply {
|
||||
Obligation<Currency>().generatePaymentNetting(this, obligationAliceToBobState.amount.token, DUMMY_NOTARY, obligationAliceToBob, obligationBobToAlice)
|
||||
}.toWireTransaction()
|
||||
assertEquals(1, tx.outputs.size)
|
||||
val expected = obligationBobToAlice.copy(quantity = obligationBobToAlice.quantity - obligationAliceToBob.quantity)
|
||||
val expected = obligationBobToAliceState.copy(quantity = obligationBobToAliceState.quantity - obligationAliceToBobState.quantity)
|
||||
val actual = tx.getOutput(0)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
private inline fun <reified T: ContractState> getStateAndRef(state: T): StateAndRef<T> {
|
||||
val txState = TransactionState(state, DUMMY_NOTARY)
|
||||
return StateAndRef(txState, StateRef(SecureHash.randomSHA256(), 0))
|
||||
|
||||
}
|
||||
|
||||
/** Test generating a transaction to mark outputs as having defaulted. */
|
||||
@Test
|
||||
fun `generate set lifecycle`() {
|
||||
@ -597,15 +606,20 @@ class ObligationTests {
|
||||
@Test
|
||||
fun zeroSizedValues() {
|
||||
transaction {
|
||||
input { inState }
|
||||
input { inState.copy(quantity = 0L) }
|
||||
this `fails with` "zero sized inputs"
|
||||
}
|
||||
transaction {
|
||||
input { inState }
|
||||
output { inState }
|
||||
output { inState.copy(quantity = 0L) }
|
||||
this `fails with` "zero sized outputs"
|
||||
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
|
||||
tweak {
|
||||
input { inState }
|
||||
input { inState.copy(quantity = 0L) }
|
||||
|
||||
this `fails with` "zero sized inputs"
|
||||
}
|
||||
tweak {
|
||||
input { inState }
|
||||
output { inState }
|
||||
output { inState.copy(quantity = 0L) }
|
||||
|
||||
this `fails with` "zero sized outputs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,6 +629,7 @@ class ObligationTests {
|
||||
transaction {
|
||||
input { inState }
|
||||
output { outState `issued by` MINI_CORP }
|
||||
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
// Can't mix currencies.
|
||||
@ -622,6 +637,7 @@ class ObligationTests {
|
||||
input { inState }
|
||||
output { outState.copy(quantity = 80000, template = megaCorpDollarSettlement) }
|
||||
output { outState.copy(quantity = 20000, template = megaCorpPoundSettlement) }
|
||||
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
transaction {
|
||||
@ -634,6 +650,7 @@ class ObligationTests {
|
||||
)
|
||||
}
|
||||
output { outState.copy(quantity = 115000) }
|
||||
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
// Can't have superfluous input states from different issuers.
|
||||
@ -704,12 +721,14 @@ class ObligationTests {
|
||||
// Can't merge them together.
|
||||
tweak {
|
||||
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY), quantity = 200000L) }
|
||||
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
// Missing MiniCorp deposit
|
||||
tweak {
|
||||
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
|
||||
output { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
|
||||
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
|
||||
this `fails with` "the amounts balance"
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.getTestPartyAndCertificate
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
@ -168,7 +169,7 @@ fun issueState(node: AbstractNode, notaryNode: AbstractNode): StateAndRef<*> {
|
||||
fun issueMultiPartyState(nodeA: AbstractNode, nodeB: AbstractNode, notaryNode: AbstractNode): StateAndRef<DummyContract.MultiOwnerState> {
|
||||
val state = TransactionState(DummyContract.MultiOwnerState(0,
|
||||
listOf(nodeA.info.legalIdentity, nodeB.info.legalIdentity)), notaryNode.info.notaryIdentity)
|
||||
val tx = TransactionBuilder(notary = notaryNode.info.notaryIdentity).withItems(state)
|
||||
val tx = TransactionBuilder(notary = notaryNode.info.notaryIdentity).withItems(state, dummyCommand())
|
||||
val signedByA = nodeA.services.signInitialTransaction(tx)
|
||||
val signedByAB = nodeB.services.addSignature(signedByA)
|
||||
val stx = notaryNode.services.addSignature(signedByAB, notaryNode.services.notaryIdentityKey)
|
||||
|
@ -19,6 +19,7 @@ import net.corda.node.utilities.CordaPersistence
|
||||
import net.corda.node.utilities.configureDatabase
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.makeTestDataSourceProperties
|
||||
import net.corda.testing.node.makeTestDatabaseProperties
|
||||
import net.corda.testing.node.makeTestIdentityService
|
||||
@ -204,7 +205,7 @@ class RequeryConfigurationTest : TestDependencyInjectionBase() {
|
||||
inputs = listOf(StateRef(SecureHash.randomSHA256(), index)),
|
||||
attachments = emptyList(),
|
||||
outputs = emptyList(),
|
||||
commands = emptyList(),
|
||||
commands = listOf(dummyCommand()),
|
||||
notary = DUMMY_NOTARY,
|
||||
timeWindow = null
|
||||
)
|
||||
|
@ -22,6 +22,7 @@ import net.corda.node.services.statemachine.StateMachineManager
|
||||
import net.corda.node.services.transactions.ValidatingNotaryService
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertTrue
|
||||
@ -71,7 +72,8 @@ class ScheduledFlowTests {
|
||||
|
||||
val notary = serviceHub.networkMapCache.getAnyNotary()
|
||||
val builder = TransactionBuilder(notary)
|
||||
builder.withItems(scheduledState)
|
||||
.addOutputState(scheduledState)
|
||||
.addCommand(dummyCommand(serviceHub.legalIdentityKey))
|
||||
val tx = serviceHub.signInitialTransaction(builder)
|
||||
subFlow(FinalityFlow(tx, setOf(serviceHub.myInfo.legalIdentity)))
|
||||
}
|
||||
@ -91,7 +93,9 @@ class ScheduledFlowTests {
|
||||
val notary = state.state.notary
|
||||
val newStateOutput = scheduledState.copy(processed = true)
|
||||
val builder = TransactionBuilder(notary)
|
||||
builder.withItems(state, newStateOutput)
|
||||
.addInputState(state)
|
||||
.addOutputState(newStateOutput)
|
||||
.addCommand(dummyCommand(serviceHub.legalIdentityKey))
|
||||
val tx = serviceHub.signInitialTransaction(builder)
|
||||
subFlow(FinalityFlow(tx, setOf(scheduledState.source, scheduledState.destination)))
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import net.corda.core.contracts.StateRef
|
||||
import net.corda.core.crypto.Crypto
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.SignatureMetadata
|
||||
import net.corda.core.node.services.VaultService
|
||||
import net.corda.core.crypto.TransactionSignature
|
||||
import net.corda.core.node.services.VaultService
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
import net.corda.core.toFuture
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
@ -220,7 +220,7 @@ class DBTransactionStorageTests : TestDependencyInjectionBase() {
|
||||
inputs = listOf(StateRef(SecureHash.randomSHA256(), 0)),
|
||||
attachments = emptyList(),
|
||||
outputs = emptyList(),
|
||||
commands = emptyList(),
|
||||
commands = listOf(dummyCommand()),
|
||||
notary = DUMMY_NOTARY,
|
||||
timeWindow = null
|
||||
)
|
||||
|
@ -593,7 +593,8 @@ class FlowFrameworkTests {
|
||||
@Test
|
||||
fun `wait for transaction`() {
|
||||
val ptx = TransactionBuilder(notary = notary1.info.notaryIdentity)
|
||||
ptx.addOutputState(DummyState())
|
||||
.addOutputState(DummyState())
|
||||
.addCommand(dummyCommand(node1.services.legalIdentityKey))
|
||||
val stx = node1.services.signInitialTransaction(ptx)
|
||||
|
||||
val committerFiber = node1.registerFlowFactory(WaitingFlows.Waiter::class) {
|
||||
@ -607,7 +608,8 @@ class FlowFrameworkTests {
|
||||
@Test
|
||||
fun `committer throws exception before calling the finality flow`() {
|
||||
val ptx = TransactionBuilder(notary = notary1.info.notaryIdentity)
|
||||
ptx.addOutputState(DummyState())
|
||||
.addOutputState(DummyState())
|
||||
.addCommand(dummyCommand())
|
||||
val stx = node1.services.signInitialTransaction(ptx)
|
||||
|
||||
node1.registerFlowFactory(WaitingFlows.Waiter::class) {
|
||||
@ -623,7 +625,8 @@ class FlowFrameworkTests {
|
||||
@Test
|
||||
fun `verify vault query service is tokenizable by force checkpointing within a flow`() {
|
||||
val ptx = TransactionBuilder(notary = notary1.info.notaryIdentity)
|
||||
ptx.addOutputState(DummyState())
|
||||
.addOutputState(DummyState())
|
||||
.addCommand(dummyCommand(node1.services.legalIdentityKey))
|
||||
val stx = node1.services.signInitialTransaction(ptx)
|
||||
|
||||
node1.registerFlowFactory(VaultQueryFlow::class) {
|
||||
|
@ -16,6 +16,7 @@ import net.corda.node.internal.AbstractNode
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.After
|
||||
@ -50,8 +51,10 @@ class NotaryServiceTests {
|
||||
fun `should sign a unique transaction with a valid time-window`() {
|
||||
val stx = run {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
tx.setTimeWindow(Instant.now(), 30.seconds)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
.setTimeWindow(Instant.now(), 30.seconds)
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
@ -64,7 +67,9 @@ class NotaryServiceTests {
|
||||
fun `should sign a unique transaction without a time-window`() {
|
||||
val stx = run {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
@ -77,8 +82,10 @@ class NotaryServiceTests {
|
||||
fun `should report error for transaction with an invalid time-window`() {
|
||||
val stx = run {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
tx.setTimeWindow(Instant.now().plusSeconds(3600), 30.seconds)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
.setTimeWindow(Instant.now().plusSeconds(3600), 30.seconds)
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
@ -92,7 +99,9 @@ class NotaryServiceTests {
|
||||
fun `should sign identical transaction multiple times (signing is idempotent)`() {
|
||||
val stx = run {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
@ -110,12 +119,16 @@ class NotaryServiceTests {
|
||||
fun `should report conflict when inputs are reused across transactions`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val stx = run {
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
val stx2 = run {
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
tx.addInputState(issueState(clientNode))
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addInputState(issueState(clientNode))
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.MEGA_CORP_KEY
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.dummyCommand
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.After
|
||||
@ -52,7 +53,9 @@ class ValidatingNotaryServiceTests {
|
||||
fun `should report error for invalid transaction dependency`() {
|
||||
val stx = run {
|
||||
val inputState = issueInvalidState(clientNode, notaryNode.info.notaryIdentity)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
val tx = TransactionBuilder(notaryNode.info.notaryIdentity)
|
||||
.addInputState(inputState)
|
||||
.addCommand(dummyCommand(clientNode.services.legalIdentityKey))
|
||||
clientNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
|
@ -222,6 +222,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
|
||||
val dummyIssueBuilder = TransactionBuilder(notary = DUMMY_NOTARY).apply {
|
||||
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
addCommand(dummyCommand(notaryServices.legalIdentityKey))
|
||||
}
|
||||
val dummyIssue = notaryServices.signInitialTransaction(dummyIssueBuilder)
|
||||
|
||||
@ -241,7 +242,8 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
|
||||
|
||||
// Issue a linear state
|
||||
val dummyIssueBuilder = TransactionBuilder(notary = DUMMY_NOTARY)
|
||||
dummyIssueBuilder.addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
.addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
.addCommand(dummyCommand(notaryServices.legalIdentityKey))
|
||||
val dummyIssuePtx = notaryServices.signInitialTransaction(dummyIssueBuilder)
|
||||
val dummyIssue = services.addSignature(dummyIssuePtx)
|
||||
|
||||
@ -251,10 +253,10 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
|
||||
assertThat(vaultQuery.queryBy<DummyLinearContract.State>().states).hasSize(1)
|
||||
|
||||
// Move the same state
|
||||
val dummyMoveBuilder = TransactionBuilder(notary = DUMMY_NOTARY).apply {
|
||||
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
addInputState(dummyIssue.tx.outRef<LinearState>(0))
|
||||
}
|
||||
val dummyMoveBuilder = TransactionBuilder(notary = DUMMY_NOTARY)
|
||||
.addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
|
||||
.addInputState(dummyIssue.tx.outRef<LinearState>(0))
|
||||
.addCommand(dummyCommand(notaryServices.legalIdentityKey))
|
||||
|
||||
val dummyMove = notaryServices.signInitialTransaction(dummyMoveBuilder)
|
||||
|
||||
@ -318,6 +320,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
|
||||
addOutputState(DummyDealContract.State(ref = "999", participants = listOf(freshIdentity)))
|
||||
addInputState(linearStates.first())
|
||||
addInputState(deals.first())
|
||||
addCommand(dummyCommand(notaryServices.legalIdentityKey))
|
||||
}
|
||||
|
||||
val dummyMove = notaryServices.signInitialTransaction(dummyMoveBuilder)
|
||||
|
@ -123,7 +123,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
@Test
|
||||
fun `refuse to sign with no relevant commands`() {
|
||||
database.transaction {
|
||||
val tx = makeTX()
|
||||
val tx = makeFullTx()
|
||||
val wtx1 = tx.toWireTransaction()
|
||||
fun filterAllOutputs(elem: Any): Boolean {
|
||||
return when (elem) {
|
||||
@ -145,7 +145,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
@Test
|
||||
fun `sign successfully`() {
|
||||
database.transaction {
|
||||
val tx = makeTX()
|
||||
val tx = makePartialTX()
|
||||
val fix = oracle.query(listOf(NodeInterestRates.parseFixOf("LIBOR 2016-03-16 1M"))).first()
|
||||
tx.addCommand(fix, oracle.identity.owningKey)
|
||||
// Sign successfully.
|
||||
@ -159,7 +159,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
@Test
|
||||
fun `do not sign with unknown fix`() {
|
||||
database.transaction {
|
||||
val tx = makeTX()
|
||||
val tx = makePartialTX()
|
||||
val fixOf = NodeInterestRates.parseFixOf("LIBOR 2016-03-16 1M")
|
||||
val badFix = Fix(fixOf, BigDecimal("0.6789"))
|
||||
tx.addCommand(badFix, oracle.identity.owningKey)
|
||||
@ -173,7 +173,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
@Test
|
||||
fun `do not sign too many leaves`() {
|
||||
database.transaction {
|
||||
val tx = makeTX()
|
||||
val tx = makePartialTX()
|
||||
val fix = oracle.query(listOf(NodeInterestRates.parseFixOf("LIBOR 2016-03-16 1M"))).first()
|
||||
fun filtering(elem: Any): Boolean {
|
||||
return when (elem) {
|
||||
@ -191,7 +191,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
|
||||
@Test
|
||||
fun `empty partial transaction to sign`() {
|
||||
val tx = makeTX()
|
||||
val tx = makeFullTx()
|
||||
val wtx = tx.toWireTransaction()
|
||||
val ftx = wtx.buildFilteredTransaction(Predicate { false })
|
||||
assertFailsWith<MerkleTreeException> { oracle.sign(ftx) }
|
||||
@ -207,7 +207,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
n2.database.transaction {
|
||||
n2.installCordaService(NodeInterestRates.Oracle::class.java).knownFixes = TEST_DATA
|
||||
}
|
||||
val tx = TransactionBuilder(null)
|
||||
val tx = makePartialTX()
|
||||
val fixOf = NodeInterestRates.parseFixOf("LIBOR 2016-03-16 1M")
|
||||
val oracle = n2.info.serviceIdentities(NodeInterestRates.Oracle.type).first()
|
||||
val flow = FilteredRatesFlow(tx, oracle, fixOf, BigDecimal("0.675"), BigDecimal("0.1"))
|
||||
@ -238,6 +238,8 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeTX() = TransactionBuilder(DUMMY_NOTARY).withItems(
|
||||
private fun makePartialTX() = TransactionBuilder(DUMMY_NOTARY).withItems(
|
||||
1000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE `with notary` DUMMY_NOTARY)
|
||||
|
||||
private fun makeFullTx() = makePartialTX().withItems(dummyCommand())
|
||||
}
|
||||
|
@ -74,7 +74,9 @@ val DUMMY_CA: CertificateAndKeyPair by lazy {
|
||||
CertificateAndKeyPair(cert, DUMMY_CA_KEY)
|
||||
}
|
||||
|
||||
fun dummyCommand(vararg signers: PublicKey) = Command<TypeOnlyCommandData>(object : TypeOnlyCommandData() {}, signers.toList())
|
||||
fun dummyCommand(vararg signers: PublicKey = arrayOf(generateKeyPair().public) ) = Command<TypeOnlyCommandData>(DummyCommandData, signers.toList())
|
||||
|
||||
object DummyCommandData : TypeOnlyCommandData()
|
||||
|
||||
val DUMMY_IDENTITY_1: PartyAndCertificate get() = getTestPartyAndCertificate(DUMMY_PARTY)
|
||||
val DUMMY_PARTY: Party get() = Party(X500Name("CN=Dummy,O=Dummy,L=Madrid,C=ES"), DUMMY_KEY_1.public)
|
||||
|
@ -4,11 +4,13 @@ package net.corda.testing.contracts
|
||||
|
||||
import net.corda.contracts.Commodity
|
||||
import net.corda.contracts.DealState
|
||||
import net.corda.contracts.asset.*
|
||||
import net.corda.contracts.asset.Cash
|
||||
import net.corda.contracts.asset.CommodityContract
|
||||
import net.corda.contracts.asset.DUMMY_CASH_ISSUER
|
||||
import net.corda.contracts.asset.DUMMY_OBLIGATION_ISSUER
|
||||
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
|
||||
import net.corda.core.identity.Party
|
||||
@ -18,9 +20,11 @@ import net.corda.core.toFuture
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.testing.CHARLIE
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.DUMMY_NOTARY_KEY
|
||||
import net.corda.testing.dummyCommand
|
||||
import java.security.PublicKey
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
@ -38,6 +42,7 @@ fun ServiceHub.fillWithSomeTestDeals(dealIds: List<String>,
|
||||
// Issue a deal state
|
||||
val dummyIssue = TransactionBuilder(notary = notary).apply {
|
||||
addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)))
|
||||
addCommand(dummyCommand())
|
||||
}
|
||||
val stx = signInitialTransaction(dummyIssue)
|
||||
return@map addSignature(stx, notary.owningKey)
|
||||
@ -76,6 +81,7 @@ fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int,
|
||||
linearNumber = linearNumber,
|
||||
linearBoolean = linearBoolean,
|
||||
linearTimestamp = linearTimestamp))
|
||||
addCommand(dummyCommand())
|
||||
}
|
||||
|
||||
return@map signInitialTransaction(dummyIssue).withAdditionalSignature(issuerKey, signatureMetadata)
|
||||
@ -194,6 +200,7 @@ fun <T : LinearState> ServiceHub.consume(states: List<StateAndRef<T>>, notary: P
|
||||
states.forEach {
|
||||
val builder = TransactionBuilder(notary = notary).apply {
|
||||
addInputState(it)
|
||||
addCommand(dummyCommand(notary.owningKey))
|
||||
}
|
||||
val consumedTx = signInitialTransaction(builder, notary.owningKey)
|
||||
|
||||
@ -205,6 +212,7 @@ fun <T : LinearState> ServiceHub.consumeAndProduce(stateAndRef: StateAndRef<T>,
|
||||
// Create a txn consuming different contract types
|
||||
var builder = TransactionBuilder(notary = notary).apply {
|
||||
addInputState(stateAndRef)
|
||||
addCommand(dummyCommand(notary.owningKey))
|
||||
}
|
||||
val consumedTx = signInitialTransaction(builder, notary.owningKey)
|
||||
|
||||
@ -214,6 +222,7 @@ fun <T : LinearState> ServiceHub.consumeAndProduce(stateAndRef: StateAndRef<T>,
|
||||
builder = TransactionBuilder(notary = notary).apply {
|
||||
addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId,
|
||||
participants = stateAndRef.state.data.participants))
|
||||
addCommand(dummyCommand(notary.owningKey))
|
||||
}
|
||||
val producedTx = signInitialTransaction(builder, notary.owningKey)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user