Skip to content

Commit

Permalink
Update integration tests to handle new transaction constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
adagys committed Aug 29, 2017
1 parent 73664c3 commit 65a59f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package net.corda.node.services
import com.nhaarman.mockito_kotlin.whenever
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateRef
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.composite.CompositeKey
import net.corda.core.internal.div
import net.corda.core.flows.NotaryError
import net.corda.core.flows.NotaryException
import net.corda.core.flows.NotaryFlow
import net.corda.core.identity.Party
import net.corda.core.internal.div
import net.corda.core.node.services.ServiceInfo
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.Try
Expand All @@ -23,6 +23,7 @@ import net.corda.node.services.transactions.minClusterSize
import net.corda.node.services.transactions.minCorrectReplicas
import net.corda.node.utilities.ServiceIdentityGenerator
import net.corda.testing.contracts.DummyContract
import net.corda.testing.dummyCommand
import net.corda.testing.node.MockNetwork
import org.bouncycastle.asn1.x500.X500Name
import org.junit.After
Expand Down Expand Up @@ -70,7 +71,9 @@ class BFTNotaryServiceTests {
fun `all replicas start even if there is a new consensus during startup`() {
val notary = bftNotaryCluster(minClusterSize(1), true) // This true adds a sleep to expose the race.
val f = node.run {
val trivialTx = signInitialTransaction(notary) {}
val trivialTx = signInitialTransaction(notary) {
addOutputState(DummyContract.SingleOwnerState(owner = info.legalIdentity))
}
// Create a new consensus while the redundant replica is sleeping:
services.startFlow(NotaryFlow.Client(trivialTx)).resultFuture
}
Expand Down Expand Up @@ -99,7 +102,7 @@ class BFTNotaryServiceTests {
services.recordTransactions(issueTx)
}
val spendTxs = (1..10).map {
signInitialTransaction(notary, true) {
signInitialTransaction(notary) {
addInputState(issueTx.tx.outRef<ContractState>(0))
}
}
Expand Down Expand Up @@ -137,11 +140,11 @@ class BFTNotaryServiceTests {

private fun AbstractNode.signInitialTransaction(
notary: Party,
makeUnique: Boolean = false,
block: TransactionBuilder.() -> Any?
) = services.signInitialTransaction(TransactionBuilder(notary).apply {
block()
if (makeUnique) {
addAttachment(SecureHash.randomSHA256())
}
})
): SignedTransaction {
return services.signInitialTransaction(
TransactionBuilder(notary).apply {
addCommand(dummyCommand(services.legalIdentityKey))
block()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package net.corda.node.services

import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.testing.contracts.DummyContract
import net.corda.core.identity.Party
import net.corda.testing.DUMMY_BANK_A
import net.corda.core.flows.NotaryError
import net.corda.core.flows.NotaryException
import net.corda.core.flows.NotaryFlow
import net.corda.core.identity.Party
import net.corda.core.internal.concurrent.map
import net.corda.core.internal.concurrent.transpose
import net.corda.core.utilities.getOrThrow
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow
import net.corda.node.internal.AbstractNode
import net.corda.testing.DUMMY_BANK_A
import net.corda.testing.contracts.DummyContract
import net.corda.testing.dummyCommand
import net.corda.testing.node.NodeBasedTest
import org.bouncycastle.asn1.x500.X500Name
import org.junit.Test
Expand All @@ -34,7 +35,9 @@ class RaftNotaryServiceTests : NodeBasedTest() {

val inputState = issueState(bankA, notaryParty)

val firstTxBuilder = TransactionBuilder(notaryParty).withItems(inputState)
val firstTxBuilder = TransactionBuilder(notaryParty)
.addInputState(inputState)
.addCommand(dummyCommand(bankA.services.legalIdentityKey))
val firstSpendTx = bankA.services.signInitialTransaction(firstTxBuilder)

val firstSpend = bankA.services.startFlow(NotaryFlow.Client(firstSpendTx))
Expand All @@ -43,6 +46,7 @@ class RaftNotaryServiceTests : NodeBasedTest() {
val secondSpendBuilder = TransactionBuilder(notaryParty).withItems(inputState).run {
val dummyState = DummyContract.SingleOwnerState(0, bankA.info.legalIdentity)
addOutputState(dummyState)
addCommand(dummyCommand(bankA.services.legalIdentityKey))
this
}
val secondSpendTx = bankA.services.signInitialTransaction(secondSpendBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package net.corda.node.services.statemachine

import co.paralleluniverse.fibers.Suspendable
import net.corda.core.internal.InputStreamAndHash
import net.corda.core.crypto.SecureHash
import net.corda.core.flows.*
import net.corda.core.identity.Party
import net.corda.core.internal.InputStreamAndHash
import net.corda.core.messaging.startFlow
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.unwrap
import net.corda.testing.BOB
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.aliceBobAndNotary
import net.corda.testing.contracts.DummyState
import net.corda.testing.driver.driver
import net.corda.testing.dummyCommand
import org.junit.Test
import kotlin.test.assertEquals

Expand All @@ -28,6 +27,7 @@ class LargeTransactionsTest {
override fun call() {
val tx = TransactionBuilder(notary = DUMMY_NOTARY)
.addOutputState(DummyState())
.addCommand(dummyCommand(serviceHub.legalIdentityKey))
.addAttachment(hash1)
.addAttachment(hash2)
.addAttachment(hash3)
Expand Down

0 comments on commit 65a59f6

Please sign in to comment.