Merge remote-tracking branch 'corda/master' into christians_os_merge_20171031

This commit is contained in:
Christian Sailer 2017-11-02 14:50:49 +00:00
parent 3e61d13ffe
commit 0f2a98af91
18 changed files with 53 additions and 83 deletions

View File

@ -21,7 +21,7 @@ import kotlin.test.*
class PartialMerkleTreeTest {
@Rule
@JvmField
private val testSerialization = SerializationEnvironmentRule()
val testSerialization = SerializationEnvironmentRule()
private val nodes = "abcdef"
private val hashed = nodes.map { node ->
withTestSerialization {

View File

@ -17,16 +17,6 @@ import java.util.*
import net.corda.nodeapi.internal.serialization.carpenter.Field as CarpenterField
import net.corda.nodeapi.internal.serialization.carpenter.Schema as CarpenterSchema
/**
* R3 AMQP assigned enterprise number
*
* see [here](https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers)
*
* Repeated here for brevity:
* 50530 - R3 - Mike Hearn - mike&r3.com
*/
const val DESCRIPTOR_TOP_32BITS: Long = 0xc5620000
const val DESCRIPTOR_DOMAIN: String = "net.corda"
// "corda" + majorVersionByte + minorVersionMSB + minorVersionLSB

View File

@ -79,7 +79,6 @@ class EvolvabilityTests {
// Original version of the class as it was serialised
// data class C(val a: Int)
// File(URI("$localPath/$resource")).writeBytes( SerializationOutput(sf).serialize(C(A))
.bytes)
data class C(val a: Int, val b: Int?)

View File

@ -566,7 +566,7 @@ abstract class AbstractNode(config: NodeConfiguration,
protected abstract fun myAddresses(): List<NetworkHostAndPort>
open protected fun checkNetworkMapIsInitialized() {
if (!services.networkMapCache.loadDBSuccess || configuration.noNetworkMapServiceMode) {
if (!services.networkMapCache.loadDBSuccess ) {
// TODO: There should be a consistent approach to configuration error exceptions.
throw NetworkMapCacheEmptyException()
}

View File

@ -5,21 +5,21 @@ import com.jcraft.jsch.JSchException
import net.corda.core.internal.Emoji
import net.corda.core.utilities.loggerFor
import net.corda.node.VersionInfo
import net.corda.node.services.config.FullNodeConfiguration
import net.corda.node.services.config.NodeConfiguration
import net.corda.node.services.config.RelayConfiguration
import net.corda.nodeapi.internal.ServiceInfo
import org.fusesource.jansi.Ansi
import org.fusesource.jansi.AnsiConsole
import java.io.IOException
class EnterpriseNode(configuration: FullNodeConfiguration,
class EnterpriseNode(configuration: NodeConfiguration,
versionInfo: VersionInfo) : Node(configuration, versionInfo) {
companion object {
private val logger by lazy { loggerFor<EnterpriseNode>() }
}
class Startup(args: Array<String>) : NodeStartup(args) {
override fun preNetworkRegistration(conf: FullNodeConfiguration) {
override fun preNetworkRegistration(conf: NodeConfiguration) {
super.preNetworkRegistration(conf)
conf.relay?.let { connectToRelay(it, conf.p2pAddress.port) }
}
@ -66,7 +66,7 @@ D""".trimStart()
return tips[(Math.random() * tips.size).toInt()]
}
override fun createNode(conf: FullNodeConfiguration, versionInfo: VersionInfo) = EnterpriseNode(conf, versionInfo)
override fun createNode(conf: NodeConfiguration, versionInfo: VersionInfo) = EnterpriseNode(conf, versionInfo)
private fun connectToRelay(config: RelayConfiguration, localBrokerPort: Int) {
with(config) {

View File

@ -174,7 +174,7 @@ open class Node(override val configuration: NodeConfiguration,
private fun getAdvertisedAddress(): NetworkHostAndPort {
return with(configuration) {
if (relay != null) {
NetworkHostAndPort(relay.relayHost, relay.remoteInboundPort)
NetworkHostAndPort(relay!!.relayHost, relay!!.remoteInboundPort)
} else {
val useHost = if (detectPublicIp) {
tryDetectIfNotPublicHost(p2pAddress.host) ?: p2pAddress.host

View File

@ -40,6 +40,7 @@ interface NodeConfiguration : NodeSSLConfiguration {
// TODO Move into DevModeOptions
val useTestClock: Boolean get() = false
val detectPublicIp: Boolean get() = true
val relay: RelayConfiguration?
}
data class NotaryConfig(val validating: Boolean,
@ -94,7 +95,7 @@ data class NodeConfigurationImpl(
override val useHTTPS: Boolean,
override val p2pAddress: NetworkHostAndPort,
override val rpcAddress: NetworkHostAndPort?,
val relay: RelayConfiguration?,
override val relay: RelayConfiguration?,
// TODO This field is slightly redundant as p2pAddress is sufficient to hold the address of the node's MQ broker.
// Instead this should be a Boolean indicating whether that broker is an internal one started by the node or an external one
override val messagingServerAddress: NetworkHostAndPort?,

View File

@ -13,7 +13,6 @@ import net.corda.core.utilities.debug
import net.corda.core.utilities.loggerFor
import net.corda.core.utilities.MAX_HASH_HEX_SIZE
import net.corda.node.utilities.AppendOnlyPersistentMap
import net.corda.node.utilities.MAX_HASH_HEX_SIZE
import net.corda.node.utilities.NODE_DATABASE_PREFIX
import org.bouncycastle.cert.X509CertificateHolder
import java.io.ByteArrayInputStream

View File

@ -7,7 +7,6 @@ import net.corda.core.node.services.KeyManagementService
import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.utilities.MAX_HASH_HEX_SIZE
import net.corda.node.utilities.AppendOnlyPersistentMap
import net.corda.node.utilities.MAX_HASH_HEX_SIZE
import net.corda.node.utilities.NODE_DATABASE_PREFIX
import org.bouncycastle.operator.ContentSigner
import java.security.KeyPair

View File

@ -20,14 +20,6 @@ import java.util.concurrent.CopyOnWriteArrayList
*/
const val NODE_DATABASE_PREFIX = "node_"
/**
* The maximum supported field-size for hash HEX-encoded outputs (e.g. database fields).
* This value is enough to support hash functions with outputs up to 512 bits (e.g. SHA3-512), in which
* case 128 HEX characters are required.
* 130 was selected instead of 128, to allow for 2 extra characters that will be used as hash-scheme identifiers.
*/
internal const val MAX_HASH_HEX_SIZE = 130
//HikariDataSource implements Closeable which allows CordaPersistence to be Closeable
class CordaPersistence(var dataSource: HikariDataSource, private val schemaService: SchemaService,
private val createIdentityService: () -> IdentityService, databaseProperties: Properties) : Closeable {

View File

@ -51,5 +51,6 @@ class NodeConfigurationImplTest {
notary = null,
certificateChainCheckPolicies = emptyList(),
devMode = true,
activeMQServer = ActiveMqServerConfiguration(BridgeConfiguration(0, 0, 0.0)))
activeMQServer = ActiveMqServerConfiguration(BridgeConfiguration(0, 0, 0.0)),
relay = null)
}

View File

@ -216,8 +216,7 @@ class CommercialPaperTestsGeneric {
// @Test
@Ignore
fun `issue move and then redeem`() {
initialiseTestSerialization()
fun `issue move and then redeem`() = withTestSerialization{
val aliceDatabaseAndServices = MockServices.makeTestDatabaseAndMockServices(keys = listOf(ALICE_KEY))
val databaseAlice = aliceDatabaseAndServices.first
aliceServices = aliceDatabaseAndServices.second
@ -297,6 +296,5 @@ class CommercialPaperTestsGeneric {
validRedemption.toLedgerTransaction(aliceServices).verify()
// soft lock not released after success either!!! (as transaction not recorded)
}
resetTestSerialization()
}
}

View File

@ -80,7 +80,7 @@ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount<Currency>,
}
class CashTests : TestDependencyInjectionBase() {
class CashTests {
private val defaultRef = OpaqueBytes(ByteArray(1, { 1 }))
private val defaultIssuer = MEGA_CORP.ref(defaultRef)
private val inState = Cash.State(
@ -102,7 +102,7 @@ class CashTests : TestDependencyInjectionBase() {
private lateinit var vaultStatesUnconsumed: List<StateAndRef<Cash.State>>
@Before
fun setUp() {
fun setUp() = withTestSerialization {
LogHelper.setLevel(NodeVaultService::class)
megaCorpServices = MockServices(listOf("com.r3.corda.enterprise.perftestcordapp.contracts.asset"), MEGA_CORP_KEY)
val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = listOf("com.r3.corda.enterprise.perftestcordapp.contracts.asset"), keys = listOf(MINI_CORP_KEY, MEGA_CORP_KEY, OUR_KEY))
@ -123,7 +123,6 @@ class CashTests : TestDependencyInjectionBase() {
database.transaction {
vaultStatesUnconsumed = miniCorpServices.vaultService.queryBy<Cash.State>().states
}
resetTestSerialization()
}
@After
@ -205,8 +204,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateIssueRaw() {
initialiseTestSerialization()
fun generateIssueRaw() = withTestSerialization {
// Test generation works.
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
Cash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
@ -221,8 +219,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateIssueFromAmount() {
initialiseTestSerialization()
fun generateIssueFromAmount() = withTestSerialization {
// Test issuance from an issued amount
val amount = 100.DOLLARS `issued by` MINI_CORP.ref(12, 34)
val tx: WireTransaction = TransactionBuilder(notary = null).apply {
@ -290,8 +287,7 @@ class CashTests : TestDependencyInjectionBase() {
* cash inputs.
*/
@Test(expected = IllegalStateException::class)
fun `reject issuance with inputs`() {
initialiseTestSerialization()
fun `reject issuance with inputs`() = withTestSerialization {
// Issue some cash
var ptx = TransactionBuilder(DUMMY_NOTARY)
@ -302,6 +298,7 @@ class CashTests : TestDependencyInjectionBase() {
ptx = TransactionBuilder(DUMMY_NOTARY)
ptx.addInputState(tx.tx.outRef<Cash.State>(0))
Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY)
Unit
}
@Test
@ -566,8 +563,7 @@ class CashTests : TestDependencyInjectionBase() {
* Try exiting an amount which matches a single state.
*/
@Test
fun generateSimpleExit() {
initialiseTestSerialization()
fun generateSimpleExit() = withTestSerialization {
val wtx = makeExit(miniCorpServices, 100.DOLLARS, MEGA_CORP, 1)
assertEquals(WALLET[0].ref, wtx.inputs[0])
assertEquals(0, wtx.outputs.size)
@ -582,8 +578,7 @@ class CashTests : TestDependencyInjectionBase() {
* Try exiting an amount smaller than the smallest available input state, and confirm change is generated correctly.
*/
@Test
fun generatePartialExit() {
initialiseTestSerialization()
fun generatePartialExit() = withTestSerialization {
val wtx = makeExit(miniCorpServices, 50.DOLLARS, MEGA_CORP, 1)
val actualInput = wtx.inputs.single()
// Filter the available inputs and confirm exactly one has been used
@ -600,53 +595,52 @@ class CashTests : TestDependencyInjectionBase() {
* Try exiting a currency we don't have.
*/
@Test
fun generateAbsentExit() {
initialiseTestSerialization()
fun generateAbsentExit() = withTestSerialization {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, MEGA_CORP, 1) }
Unit
}
/**
* Try exiting with a reference mis-match.
*/
@Test
fun generateInvalidReferenceExit() {
initialiseTestSerialization()
fun generateInvalidReferenceExit() = withTestSerialization {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, MEGA_CORP, 2) }
Unit
}
/**
* Try exiting an amount greater than the maximum available.
*/
@Test
fun generateInsufficientExit() {
initialiseTestSerialization()
fun generateInsufficientExit() = withTestSerialization {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 1000.DOLLARS, MEGA_CORP, 1) }
Unit
}
/**
* Try exiting for an owner with no states
*/
@Test
fun generateOwnerWithNoStatesExit() {
initialiseTestSerialization()
fun generateOwnerWithNoStatesExit() = withTestSerialization {
assertFailsWith<InsufficientBalanceException> { makeExit(miniCorpServices, 100.POUNDS, CHARLIE, 1) }
Unit
}
/**
* Try exiting when vault is empty
*/
@Test
fun generateExitWithEmptyVault() {
initialiseTestSerialization()
fun generateExitWithEmptyVault() = withTestSerialization {
assertFailsWith<IllegalArgumentException> {
val tx = TransactionBuilder(DUMMY_NOTARY)
Cash().generateExit(tx, Amount(100, Issued(CHARLIE.ref(1), GBP)), emptyList(), OUR_IDENTITY_1)
}
Unit
}
@Test
fun generateSimpleDirectSpend() {
initialiseTestSerialization()
fun generateSimpleDirectSpend() = withTestSerialization {
val wtx =
database.transaction {
makeSpend(100.DOLLARS, THEIR_IDENTITY_1)
@ -660,8 +654,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateSimpleSpendWithParties() {
initialiseTestSerialization()
fun generateSimpleSpendWithParties() = withTestSerialization {
database.transaction {
val tx = TransactionBuilder(DUMMY_NOTARY)
@ -672,8 +665,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateSimpleSpendWithChange() {
initialiseTestSerialization()
fun generateSimpleSpendWithChange() = withTestSerialization {
val wtx =
database.transaction {
makeSpend(10.DOLLARS, THEIR_IDENTITY_1)
@ -698,8 +690,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateSpendWithTwoInputs() {
initialiseTestSerialization()
fun generateSpendWithTwoInputs() = withTestSerialization {
val wtx =
database.transaction {
makeSpend(500.DOLLARS, THEIR_IDENTITY_1)
@ -715,8 +706,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateSpendMixedDeposits() {
initialiseTestSerialization()
fun generateSpendMixedDeposits() = withTestSerialization {
val wtx =
database.transaction {
val wtx = makeSpend(580.DOLLARS, THEIR_IDENTITY_1)
@ -737,8 +727,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun generateSpendInsufficientBalance() {
initialiseTestSerialization()
fun generateSpendInsufficientBalance() = withTestSerialization {
database.transaction {
val e: InsufficientBalanceException = assertFailsWith("balance") {
@ -750,6 +739,7 @@ class CashTests : TestDependencyInjectionBase() {
makeSpend(81.SWISS_FRANCS, THEIR_IDENTITY_1)
}
}
Unit
}
/**
@ -876,8 +866,7 @@ class CashTests : TestDependencyInjectionBase() {
}
@Test
fun multiSpend() {
initialiseTestSerialization()
fun multiSpend() = withTestSerialization {
val tx = TransactionBuilder(DUMMY_NOTARY)
database.transaction {
val payments = listOf(

View File

@ -37,7 +37,7 @@ fun <A> springDriver(
driverDirectory: Path = defaultParameters.driverDirectory,
portAllocation: PortAllocation = defaultParameters.portAllocation,
debugPortAllocation: PortAllocation = defaultParameters.debugPortAllocation,
systemProperties: Map<String, String> = defaultParameters.systemProperties,
systemProperties: Map<String, String> = defaultParameters.extraSystemProperties,
useTestClock: Boolean = defaultParameters.useTestClock,
initialiseSerialization: Boolean = defaultParameters.initialiseSerialization,
startNodesInProcess: Boolean = defaultParameters.startNodesInProcess,

View File

@ -12,6 +12,7 @@ import net.corda.node.services.statemachine.StateMachineManager
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.DUMMY_REGULATOR
import net.corda.testing.node.*
import net.corda.testing.node.MockNetwork.MockNode
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
import rx.Observable
import rx.subjects.PublishSubject
@ -24,7 +25,7 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletableFuture.allOf
import java.util.concurrent.Future
internal val MockNode.place get() = configuration.myLegalName.locality.let { CityDatabase[it] }!!
internal val MockNetwork.MockNode.place get() = configuration.myLegalName.locality.let { CityDatabase[it] }!!
/**
* Base class for network simulations that are based on the unit test / mock environment.
@ -49,11 +50,11 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
val bankLocations = listOf(Pair("London", "GB"), Pair("Frankfurt", "DE"), Pair("Rome", "IT"))
object RatesOracleFactory : MockNetwork.Factory<MockNode> {
object RatesOracleFactory : MockNetwork.Factory<MockNetwork.MockNode> {
// TODO: Make a more realistic legal name
val RATES_SERVICE_NAME = CordaX500Name(organisation = "Rates Service Provider", locality = "Madrid", country = "ES")
override fun create(args: MockNodeArgs): MockNode {
override fun create(args: MockNodeArgs): MockNetwork.MockNode {
return object : MockNode(args) {
override fun start() = super.start().apply {
registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)

View File

@ -225,7 +225,7 @@ fun <A> rpcDriver(
driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()),
portAllocation: PortAllocation = globalPortAllocation,
debugPortAllocation: PortAllocation = globalDebugPortAllocation,
extraSystemProperties: Map<String, String> = emptyMap(),
systemProperties: Map<String, String> = emptyMap(),
useTestClock: Boolean = false,
initialiseSerialization: Boolean = true,
startNodesInProcess: Boolean = false,
@ -236,7 +236,7 @@ fun <A> rpcDriver(
DriverDSL(
portAllocation = portAllocation,
debugPortAllocation = debugPortAllocation,
extraSystemProperties = extraSystemProperties,
extraSystemProperties = systemProperties,
driverDirectory = driverDirectory.toAbsolutePath(),
useTestClock = useTestClock,
isDebug = isDebug,

View File

@ -315,7 +315,7 @@ data class NodeParameters(
* and may be specified in [DriverDSL.startNode].
* @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental.
* @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental.
* @param extraSystemProperties A Map of extra system properties which will be given to each new node. Defaults to empty.
* @param systemProperties A Map of extra system properties which will be given to each new node. Defaults to empty.
* @param useTestClock If true the test clock will be used in Node.
* @param startNodesInProcess Provides the default behaviour of whether new nodes should start inside this process or
* not. Note that this may be overridden in [DriverDSLExposedInterface.startNode].
@ -434,7 +434,7 @@ fun <DI : DriverDSLExposedInterface, D : DriverDSLInternalInterface, A> genericD
driverDirectory: Path = defaultParameters.driverDirectory,
portAllocation: PortAllocation = defaultParameters.portAllocation,
debugPortAllocation: PortAllocation = defaultParameters.debugPortAllocation,
systemProperties: Map<String, String> = defaultParameters.systemProperties,
systemProperties: Map<String, String> = defaultParameters.extraSystemProperties,
useTestClock: Boolean = defaultParameters.useTestClock,
initialiseSerialization: Boolean = defaultParameters.initialiseSerialization,
startNodesInProcess: Boolean = defaultParameters.startNodesInProcess,
@ -448,7 +448,7 @@ fun <DI : DriverDSLExposedInterface, D : DriverDSLInternalInterface, A> genericD
DriverDSL(
portAllocation = portAllocation,
debugPortAllocation = debugPortAllocation,
systemProperties = systemProperties,
extraSystemProperties = systemProperties,
driverDirectory = driverDirectory.toAbsolutePath(),
useTestClock = useTestClock,
isDebug = isDebug,
@ -752,7 +752,7 @@ class DriverDSL(
"noNetworkMapServiceMode" to true
) + customOverrides
)
return startNodeInternal(name, config, webAddress, startInSameProcess, maximumHeapSize, logLevel)
return startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize)
}
override fun startNotaryNode(providedName: CordaX500Name,
@ -779,7 +779,7 @@ class DriverDSL(
"noNetworkMapServiceMode" to true
)
)
startNodeInternal(name, config, webAddress, startInSameProcess, maximumHeapSize)
startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize)
}
}
@ -925,7 +925,7 @@ class DriverDSL(
countObservables.remove(nodeConfiguration.myLegalName)
}
if (startInProcess ?: startNodesInProcess) {
val nodeAndThreadFuture = startInProcessNode(executorService, nodeConfiguration, enhancedConfig, cordappPackages)
val nodeAndThreadFuture = startInProcessNode(executorService, nodeConfiguration, config, cordappPackages)
shutdownManager.registerShutdown(
nodeAndThreadFuture.map { (node, thread) ->
{
@ -943,7 +943,7 @@ class DriverDSL(
}
} else {
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
val processFuture = startOutOfProcessNode(executorService, nodeConfiguration, enhancedConfig, quasarJarPath, debugPort, systemProperties, cordappPackages, maximumHeapSize, logLevel)
val processFuture = startOutOfProcessNode(executorService, nodeConfiguration, config, quasarJarPath, debugPort, systemProperties, cordappPackages, maximumHeapSize)
registerProcess(processFuture)
return processFuture.flatMap { process ->
val processDeathFuture = poll(executorService, "process death") {

View File

@ -39,6 +39,7 @@ import net.corda.node.utilities.AffinityExecutor
import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor
import net.corda.nodeapi.internal.ServiceInfo
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.initialiseTestSerialization
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
import net.corda.testing.testNodeConfiguration