mirror of
https://github.com/corda/corda.git
synced 2025-05-09 12:02:56 +00:00
Re-apply previous fixes.
This commit is contained in:
parent
764af04608
commit
ccd5f5fd5b
@ -1,6 +1,7 @@
|
|||||||
package net.corda.behave.service.proxy
|
package net.corda.behave.service.proxy
|
||||||
|
|
||||||
import net.corda.behave.service.proxy.RPCProxyServer.Companion.initialiseSerialization
|
import net.corda.behave.service.proxy.RPCProxyServer.Companion.initialiseSerialization
|
||||||
|
import net.corda.behave.service.proxy.RPCProxyServer.Companion.log
|
||||||
import net.corda.client.rpc.internal.KryoClientSerializationScheme
|
import net.corda.client.rpc.internal.KryoClientSerializationScheme
|
||||||
import net.corda.core.serialization.internal.SerializationEnvironmentImpl
|
import net.corda.core.serialization.internal.SerializationEnvironmentImpl
|
||||||
import net.corda.core.serialization.internal.nodeSerializationEnv
|
import net.corda.core.serialization.internal.nodeSerializationEnv
|
||||||
@ -88,6 +89,6 @@ fun main(args: Array<String>) {
|
|||||||
initialiseSerialization()
|
initialiseSerialization()
|
||||||
val portNo = args.singleOrNull() ?: throw IllegalArgumentException("Please specify a port number")
|
val portNo = args.singleOrNull() ?: throw IllegalArgumentException("Please specify a port number")
|
||||||
val hostAndPort = NetworkHostAndPort("localhost", portNo.toIntOrNull() ?: 13000)
|
val hostAndPort = NetworkHostAndPort("localhost", portNo.toIntOrNull() ?: 13000)
|
||||||
println("Starting RPC Proxy Server on [$hostAndPort] ...")
|
log.info("Starting RPC Proxy Server on [$hostAndPort] ...")
|
||||||
RPCProxyServer(hostAndPort, webService = RPCProxyWebService(hostAndPort)).start()
|
RPCProxyServer(hostAndPort, webService = RPCProxyWebService(hostAndPort)).start()
|
||||||
}
|
}
|
@ -3,7 +3,6 @@ package net.corda.behave.service.proxy
|
|||||||
import net.corda.core.internal.checkOkResponse
|
import net.corda.core.internal.checkOkResponse
|
||||||
import net.corda.core.internal.openHttpConnection
|
import net.corda.core.internal.openHttpConnection
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.core.utilities.OpaqueBytes
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class RPCProxyServerTest {
|
class RPCProxyServerTest {
|
||||||
@ -16,18 +15,11 @@ class RPCProxyServerTest {
|
|||||||
RPCProxyServer(rpcProxyHostAndPort,
|
RPCProxyServer(rpcProxyHostAndPort,
|
||||||
webService = RPCProxyWebService(nodeHostAndPort)).use {
|
webService = RPCProxyWebService(nodeHostAndPort)).use {
|
||||||
it.start()
|
it.start()
|
||||||
it.doPost("rpcOps", OpaqueBytes.of(0).bytes)
|
it.doGet("my-ip")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun RPCProxyServer.doPost(path: String, payload: ByteArray) {
|
private fun RPCProxyServer.doGet(path: String) {
|
||||||
val url = java.net.URL("http://$rpcProxyHostAndPort/rpc/$path")
|
return java.net.URL("http://$rpcProxyHostAndPort/rpc/$path").openHttpConnection().checkOkResponse()
|
||||||
url.openHttpConnection().apply {
|
|
||||||
doOutput = true
|
|
||||||
requestMethod = "POST"
|
|
||||||
setRequestProperty("Content-Type", javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM)
|
|
||||||
outputStream.write(payload)
|
|
||||||
checkOkResponse()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,9 @@ package net.corda.behave.service.proxy
|
|||||||
|
|
||||||
import net.corda.core.internal.openHttpConnection
|
import net.corda.core.internal.openHttpConnection
|
||||||
import net.corda.core.internal.responseAs
|
import net.corda.core.internal.responseAs
|
||||||
|
import net.corda.core.internal.sumByLong
|
||||||
import net.corda.core.messaging.startFlow
|
import net.corda.core.messaging.startFlow
|
||||||
|
import net.corda.core.node.services.Vault
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.core.utilities.OpaqueBytes
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
@ -13,14 +15,19 @@ import net.corda.finance.contracts.asset.Cash
|
|||||||
import net.corda.finance.flows.CashExitFlow
|
import net.corda.finance.flows.CashExitFlow
|
||||||
import net.corda.finance.flows.CashIssueFlow
|
import net.corda.finance.flows.CashIssueFlow
|
||||||
import net.corda.finance.flows.CashPaymentFlow
|
import net.corda.finance.flows.CashPaymentFlow
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Assert.fail
|
import org.junit.Assert.fail
|
||||||
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class RPCProxyWebServiceTest {
|
class RPCProxyWebServiceTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* client -> HTTPtoRPCProxy -> Corda Node
|
* client -> HTTPtoRPCProxy -> Corda Node
|
||||||
|
*
|
||||||
|
* Please note these tests require a running network with at 3 Nodes
|
||||||
|
* (listening on ports 12002, 12007, and 12012) and a Notary
|
||||||
*/
|
*/
|
||||||
private val hostAndPort = NetworkHostAndPort("localhost", 13002)
|
private val hostAndPort = NetworkHostAndPort("localhost", 13002)
|
||||||
private val rpcProxyClient = CordaRPCProxyClient(hostAndPort)
|
private val rpcProxyClient = CordaRPCProxyClient(hostAndPort)
|
||||||
@ -42,24 +49,32 @@ class RPCProxyWebServiceTest {
|
|||||||
fun nodeInfo() {
|
fun nodeInfo() {
|
||||||
val response = rpcProxyClient.nodeInfo()
|
val response = rpcProxyClient.nodeInfo()
|
||||||
println(response)
|
println(response)
|
||||||
|
assertThat(response.toString()).matches("NodeInfo\\(addresses=\\[.*\\], legalIdentitiesAndCerts=\\[.*\\], platformVersion=.*, serial=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun registeredFlows() {
|
fun registeredFlows() {
|
||||||
val response = rpcProxyClient.registeredFlows()
|
val response = rpcProxyClient.registeredFlows()
|
||||||
println(response)
|
println(response)
|
||||||
|
// Node built-in flows
|
||||||
|
assertThat(response).contains("net.corda.core.flows.ContractUpgradeFlow\$Authorise",
|
||||||
|
"net.corda.core.flows.ContractUpgradeFlow\$Deauthorise",
|
||||||
|
"net.corda.core.flows.ContractUpgradeFlow\$Initiate")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun notaryIdentities() {
|
fun notaryIdentities() {
|
||||||
val response = rpcProxyClient.notaryIdentities()
|
val response = rpcProxyClient.notaryIdentities()
|
||||||
println(response)
|
println(response)
|
||||||
|
assertThat(response.first().name.toString()).isEqualTo("O=Notary, L=London, C=GB")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun networkMapSnapshot() {
|
fun networkMapSnapshot() {
|
||||||
val response = rpcProxyClient.networkMapSnapshot()
|
val response = rpcProxyClient.networkMapSnapshot()
|
||||||
println(response)
|
println(response)
|
||||||
|
assertThat(response).contains(rpcProxyClient.nodeInfo())
|
||||||
|
assertThat(response.size).isEqualTo(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -68,6 +83,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClient.startFlow(::CashIssueFlow, POUNDS(500), OpaqueBytes.of(1), notary)
|
val response = rpcProxyClient.startFlow(::CashIssueFlow, POUNDS(500), OpaqueBytes.of(1), notary)
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -76,6 +92,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClientB.startFlow(::CashIssueFlow, DOLLARS(1000), OpaqueBytes.of(1), notary)
|
val response = rpcProxyClientB.startFlow(::CashIssueFlow, DOLLARS(1000), OpaqueBytes.of(1), notary)
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -84,6 +101,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClientB.startFlow(::CashPaymentFlow, DOLLARS(100), recipient)
|
val response = rpcProxyClientB.startFlow(::CashPaymentFlow, DOLLARS(100), recipient)
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -92,6 +110,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClient.startFlow(::CashPaymentFlow, POUNDS(250), recipient)
|
val response = rpcProxyClient.startFlow(::CashPaymentFlow, POUNDS(250), recipient)
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -100,6 +119,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClientB.startFlow(::CashPaymentFlow, DOLLARS(500), recipient)
|
val response = rpcProxyClientB.startFlow(::CashPaymentFlow, DOLLARS(500), recipient)
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -107,6 +127,7 @@ class RPCProxyWebServiceTest {
|
|||||||
val response = rpcProxyClient.startFlow(::CashExitFlow, POUNDS(500), OpaqueBytes.of(1))
|
val response = rpcProxyClient.startFlow(::CashExitFlow, POUNDS(500), OpaqueBytes.of(1))
|
||||||
val result = response.returnValue.getOrThrow().stx
|
val result = response.returnValue.getOrThrow().stx
|
||||||
println(result)
|
println(result)
|
||||||
|
assertThat(result.toString()).matches("SignedTransaction\\(id=.*\\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -149,8 +170,11 @@ class RPCProxyWebServiceTest {
|
|||||||
responseB.states.forEach { state ->
|
responseB.states.forEach { state ->
|
||||||
println("PartyB: ${state.state.data.amount}")
|
println("PartyB: ${state.state.data.amount}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertVaultHoldsCash(responseA, responseB)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
fun startMultiABCPartyCashFlows() {
|
fun startMultiABCPartyCashFlows() {
|
||||||
val notary = rpcProxyClient.notaryIdentities()[0]
|
val notary = rpcProxyClient.notaryIdentities()[0]
|
||||||
@ -213,6 +237,7 @@ class RPCProxyWebServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enable Flow Draining on Node B
|
// enable Flow Draining on Node B
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
fun startMultiACPartyCashFlows() {
|
fun startMultiACPartyCashFlows() {
|
||||||
val notary = rpcProxyClient.notaryIdentities()[0]
|
val notary = rpcProxyClient.notaryIdentities()[0]
|
||||||
@ -279,6 +304,8 @@ class RPCProxyWebServiceTest {
|
|||||||
responseC.states.forEach { state ->
|
responseC.states.forEach { state ->
|
||||||
println("PartyC: ${state.state.data.amount}")
|
println("PartyC: ${state.state.data.amount}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertVaultHoldsCash(responseA, responseB, responseC)
|
||||||
}
|
}
|
||||||
catch (e: Exception) {
|
catch (e: Exception) {
|
||||||
println("Vault Cash query error: ${e.message}")
|
println("Vault Cash query error: ${e.message}")
|
||||||
@ -286,6 +313,15 @@ class RPCProxyWebServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun assertVaultHoldsCash(vararg vaultPages: Vault.Page<Cash.State>) {
|
||||||
|
vaultPages.forEach { vaultPage ->
|
||||||
|
assertThat(vaultPage.states.size).isGreaterThan(0)
|
||||||
|
vaultPage.states.groupBy { it.state.data.amount.token.product.currencyCode }.forEach { _, value ->
|
||||||
|
assertThat(value.sumByLong { it.state.data.amount.quantity }).isGreaterThan(0L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun <reified T : Any> doGet(path: String): T {
|
private inline fun <reified T : Any> doGet(path: String): T {
|
||||||
return java.net.URL("http://$hostAndPort/rpc/$path").openHttpConnection().responseAs()
|
return java.net.URL("http://$hostAndPort/rpc/$path").openHttpConnection().responseAs()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user