Ensure transactions in tests have commands (#1200)

* Ensure transactions in tests have commands
This commit is contained in:
Andrius Dagys
2017-08-16 10:06:46 +01:00
committed by GitHub
parent 435dcf6af4
commit 1e0a26e8e5
15 changed files with 135 additions and 63 deletions

View File

@ -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)

View File

@ -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
)

View File

@ -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)))
}

View File

@ -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
)

View File

@ -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) {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)