Merge branch 'master' into shams-merge-master-041217

# Conflicts:
#	node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt
#	samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaCordform.kt
#	testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt
#	testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt
#	testing/node-driver/src/main/kotlin/net/corda/testing/internal/NodeBasedTest.kt
#	testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt
#	testing/node-driver/src/main/kotlin/net/corda/testing/node/NotarySpec.kt
#	verifier/src/integration-test/kotlin/net/corda/verifier/VerifierDriver.kt
This commit is contained in:
Shams Asari
2017-12-04 13:39:32 +00:00
104 changed files with 1057 additions and 990 deletions

View File

@ -7,7 +7,7 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.*
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import net.corda.nodeapi.User
import net.corda.nodeapi.internal.config.User
import net.corda.smoketesting.NodeConfig
import net.corda.smoketesting.NodeProcess
import net.corda.testing.common.internal.ProjectStructure

View File

@ -11,7 +11,7 @@ import net.corda.core.internal.list
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.unwrap
import net.corda.nodeapi.User
import net.corda.nodeapi.internal.config.User
import net.corda.smoketesting.NodeConfig
import net.corda.smoketesting.NodeProcess
import net.corda.smoketesting.NodeProcess.Companion.CORDAPPS_DIR_NAME

View File

@ -38,24 +38,20 @@ class PartialMerkleTreeTest {
testLedger = ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
output(Cash.PROGRAM_ID, "MEGA_CORP cash",
Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP
)
}
output(Cash.PROGRAM_ID, "dummy cash 1") {
owner = MEGA_CORP))
output(Cash.PROGRAM_ID, "dummy cash 1",
Cash.State(
amount = 900.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MINI_CORP
)
}
owner = MINI_CORP))
}
transaction {
attachments(Cash.PROGRAM_ID)
input("MEGA_CORP cash")
output(Cash.PROGRAM_ID, "MEGA_CORP cash".output<Cash.State>().copy(owner = MINI_CORP))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
timeWindow(TEST_TX_TIME)
this.verifies()
}

View File

@ -19,7 +19,7 @@ import net.corda.finance.flows.CashIssueFlow
import net.corda.node.internal.SecureCordaRPCOps
import net.corda.node.internal.StartedNode
import net.corda.node.services.Permissions.Companion.startFlow
import net.corda.nodeapi.User
import net.corda.nodeapi.internal.config.User
import net.corda.testing.*
import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyContractV2

View File

@ -20,6 +20,42 @@ class ReceiveMultipleFlowTests {
mockNet.stopNodes()
}
@Test
fun showcase_flows_as_closures() {
val answer = 10.0
val message = "Hello Ivan"
val counterParty = nodes[1].info.singleIdentity()
val initiatingFlow = @InitiatingFlow object : FlowLogic<Any>() {
@Suspendable
override fun call(): Any {
val session = initiateFlow(counterParty)
return session.sendAndReceive<Any>(message).unwrap { it }
}
}
nodes[1].registerInitiatedFlow(initiatingFlow::class) { session ->
object : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// this is a closure, meaning you can access variables outside its scope e.g., `answer`.
val receivedMessage = session.receive<String>().unwrap { it }
logger.info("Got message from counterParty: $receivedMessage.")
assertThat(receivedMessage).isEqualTo(message)
session.send(answer)
}
} as FlowLogic<Unit>
}
val flow = nodes[0].services.startFlow(initiatingFlow)
mockNet.runNetwork()
val receivedAnswer = flow.resultFuture.getOrThrow()
assertThat(receivedAnswer).isEqualTo(answer)
}
@Test
fun `receive all messages in parallel using map style`() {
val doubleValue = 5.0

View File

@ -55,10 +55,10 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input(Cash.PROGRAM_ID) { state }
output(Cash.PROGRAM_ID, encumbrance = 1) { stateWithNewOwner }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(Cash.PROGRAM_ID, encumbrance = 1, contractState = stateWithNewOwner)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
verifies()
}
}
@ -69,16 +69,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
// Un-encumber the output if the time of the transaction is later than the timelock.
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by 5pm time-lock")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
verifies()
}
@ -90,16 +90,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
// The time of the transaction is earlier than the time specified in the encumbering timelock.
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by 5pm time-lock")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { state }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, state)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FOUR_PM)
this `fails with` "the time specified in the time-lock has passed"
}
@ -111,14 +111,14 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", encumbrance = 1) { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", encumbrance = 1, contractState = state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
transaction {
attachments(Cash.PROGRAM_ID)
input("state encumbered by 5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
this `fails with` "Missing required encumbrance 1 in INPUT"
}
@ -130,9 +130,9 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { state }
output(Cash.PROGRAM_ID, encumbrance = 0) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(Cash.PROGRAM_ID, encumbrance = 0, contractState = stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
this `fails with` "Missing required encumbrance 0 in OUTPUT"
}
}
@ -143,10 +143,10 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input(Cash.PROGRAM_ID) { state }
output(TEST_TIMELOCK_ID, encumbrance = 2) { stateWithNewOwner }
output(TEST_TIMELOCK_ID) { timeLock }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(TEST_TIMELOCK_ID, encumbrance = 2, contractState = stateWithNewOwner)
output(TEST_TIMELOCK_ID, timeLock)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
this `fails with` "Missing required encumbrance 2 in OUTPUT"
}
}
@ -157,16 +157,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by some other state", encumbrance = 1) { state }
output(Cash.PROGRAM_ID, "some other state") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by some other state", encumbrance = 1, contractState = state)
output(Cash.PROGRAM_ID, "some other state", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by some other state")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
this `fails with` "Missing required encumbrance 1 in INPUT"
}