mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Retired BankOfCordaRPCClientTest as it's mostly duplicated by BankOfCordaCordformTest (#3565)
This commit is contained in:
parent
ed25d8f1be
commit
dc3bd8de7a
@ -38,10 +38,14 @@ fun Iterable<ContractState>.sumCashOrZero(currency: Issued<Currency>): Amount<Is
|
||||
}
|
||||
|
||||
/** Sums the asset states in the list, returning null if there are none. */
|
||||
fun <T : Any> Iterable<ContractState>.sumFungibleOrNull() = filterIsInstance<FungibleAsset<T>>().map { it.amount }.sumOrNull()
|
||||
fun <T : Any> Iterable<ContractState>.sumFungibleOrNull(): Amount<Issued<T>>? {
|
||||
return filterIsInstance<FungibleAsset<T>>().map { it.amount }.sumOrNull()
|
||||
}
|
||||
|
||||
/** Sums the asset states in the list, returning zero of the given token if there are none. */
|
||||
fun <T : Any> Iterable<ContractState>.sumFungibleOrZero(token: Issued<T>) = filterIsInstance<FungibleAsset<T>>().map { it.amount }.sumOrZero(token)
|
||||
fun <T : Any> Iterable<ContractState>.sumFungibleOrZero(token: Issued<T>): Amount<Issued<T>> {
|
||||
return filterIsInstance<FungibleAsset<T>>().map { it.amount }.sumOrZero(token)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums the obligation states in the list, throwing an exception if there are none. All state objects in the
|
||||
|
@ -1,16 +1,32 @@
|
||||
package net.corda.bank
|
||||
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.contracts.withoutIssuer
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.finance.DOLLARS
|
||||
import net.corda.finance.POUNDS
|
||||
import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.finance.utils.sumCash
|
||||
import net.corda.testing.core.BOC_NAME
|
||||
import net.corda.testing.node.internal.demorun.nodeRunner
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
|
||||
class BankOfCordaCordformTest {
|
||||
@Test
|
||||
fun `run demo`() {
|
||||
BankOfCordaCordform().nodeRunner().scanPackages(listOf("net.corda.finance")).deployAndRunNodesThen {
|
||||
IssueCash.requestWebIssue(30000.POUNDS)
|
||||
BankOfCordaCordform().nodeRunner().scanPackages(listOf("net.corda.finance")).deployAndRunNodesAndThen {
|
||||
IssueCash.requestRpcIssue(20000.DOLLARS)
|
||||
CordaRPCClient(NetworkHostAndPort("localhost", BOC_RPC_PORT)).use(BOC_RPC_USER, BOC_RPC_PWD) {
|
||||
assertThat(it.proxy.vaultQuery(Cash.State::class.java).states).isEmpty() // All of the issued cash is transferred
|
||||
}
|
||||
CordaRPCClient(NetworkHostAndPort("localhost", BIGCORP_RPC_PORT)).use(BIGCORP_RPC_USER, BIGCORP_RPC_PWD) {
|
||||
val cashStates = it.proxy.vaultQuery(Cash.State::class.java).states.map { it.state.data }
|
||||
val knownOwner = it.proxy.wellKnownPartyFromAnonymous(cashStates.map { it.owner }.toSet().single())
|
||||
assertThat(knownOwner?.name).isEqualTo(BIGCORP_NAME)
|
||||
val totalCash = cashStates.sumCash()
|
||||
assertThat(totalCash.token.issuer.party.nameOrNull()).isEqualTo(BOC_NAME)
|
||||
assertThat(totalCash.withoutIssuer()).isEqualTo(20000.DOLLARS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +0,0 @@
|
||||
package net.corda.bank
|
||||
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.node.services.Vault
|
||||
import net.corda.core.node.services.vault.QueryCriteria
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.finance.DOLLARS
|
||||
import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.finance.flows.CashIssueAndPaymentFlow
|
||||
import net.corda.node.services.Permissions.Companion.invokeRpc
|
||||
import net.corda.node.services.Permissions.Companion.startFlow
|
||||
import net.corda.testing.core.BOC_NAME
|
||||
import net.corda.testing.core.expect
|
||||
import net.corda.testing.core.expectEvents
|
||||
import net.corda.testing.core.sequence
|
||||
import net.corda.testing.driver.DriverParameters
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.node.User
|
||||
import org.junit.Test
|
||||
|
||||
class BankOfCordaRPCClientTest {
|
||||
@Test
|
||||
fun `issuer flow via RPC`() {
|
||||
val commonPermissions = setOf(
|
||||
invokeRpc("vaultTrackByCriteria"),
|
||||
invokeRpc(CordaRPCOps::wellKnownPartyFromX500Name),
|
||||
invokeRpc(CordaRPCOps::notaryIdentities)
|
||||
)
|
||||
driver(DriverParameters(extraCordappPackagesToScan = listOf("net.corda.finance"))) {
|
||||
val bocManager = User("bocManager", "password1", permissions = setOf(
|
||||
startFlow<CashIssueAndPaymentFlow>()) + commonPermissions)
|
||||
val bigCorpCFO = User("bigCorpCFO", "password2", permissions = emptySet<String>() + commonPermissions)
|
||||
val (nodeBankOfCorda, nodeBigCorporation) = listOf(
|
||||
startNode(providedName = BOC_NAME, rpcUsers = listOf(bocManager)),
|
||||
startNode(providedName = BIGCORP_NAME, rpcUsers = listOf(bigCorpCFO))
|
||||
).map { it.getOrThrow() }
|
||||
|
||||
// Bank of Corda RPC Client
|
||||
val bocClient = CordaRPCClient(nodeBankOfCorda.rpcAddress)
|
||||
val bocProxy = bocClient.start("bocManager", "password1").proxy
|
||||
|
||||
// Big Corporation RPC Client
|
||||
val bigCorpClient = CordaRPCClient(nodeBigCorporation.rpcAddress)
|
||||
val bigCorpProxy = bigCorpClient.start("bigCorpCFO", "password2").proxy
|
||||
|
||||
// Register for Bank of Corda Vault updates
|
||||
val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL)
|
||||
val vaultUpdatesBoc = bocProxy.vaultTrackByCriteria(Cash.State::class.java, criteria).updates
|
||||
|
||||
// Register for Big Corporation Vault updates
|
||||
val vaultUpdatesBigCorp = bigCorpProxy.vaultTrackByCriteria(Cash.State::class.java, criteria).updates
|
||||
|
||||
val bigCorporation = bigCorpProxy.wellKnownPartyFromX500Name(BIGCORP_NAME)!!
|
||||
|
||||
// Kick-off actual Issuer Flow
|
||||
val anonymous = true
|
||||
bocProxy.startFlow(::CashIssueAndPaymentFlow,
|
||||
1000.DOLLARS, OpaqueBytes.of(1),
|
||||
bigCorporation,
|
||||
anonymous,
|
||||
defaultNotaryIdentity).returnValue.getOrThrow()
|
||||
|
||||
// Check Bank of Corda Vault Updates
|
||||
vaultUpdatesBoc.expectEvents {
|
||||
sequence(
|
||||
// ISSUE
|
||||
expect { update ->
|
||||
require(update.consumed.isEmpty()) { "Expected 0 consumed states, actual: $update" }
|
||||
require(update.produced.size == 1) { "Expected 1 produced states, actual: $update" }
|
||||
},
|
||||
// MOVE
|
||||
expect { update ->
|
||||
require(update.consumed.size == 1) { "Expected 1 consumed states, actual: $update" }
|
||||
require(update.produced.isEmpty()) { "Expected 0 produced states, actual: $update" }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Check Big Corporation Vault Updates
|
||||
vaultUpdatesBigCorp.expectEvents {
|
||||
sequence(
|
||||
// MOVE
|
||||
expect { (consumed, produced) ->
|
||||
require(consumed.isEmpty()) { consumed.size }
|
||||
require(produced.size == 1) { produced.size }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,10 +21,17 @@ import kotlin.system.exitProcess
|
||||
|
||||
val BIGCORP_NAME = CordaX500Name(organisation = "BigCorporation", locality = "New York", country = "US")
|
||||
private val NOTARY_NAME = CordaX500Name(organisation = "Notary Service", locality = "Zurich", country = "CH")
|
||||
private const val BOC_RPC_PORT = 10006
|
||||
const val BOC_RPC_PORT = 10006
|
||||
const val BIGCORP_RPC_PORT = 10009
|
||||
private const val BOC_RPC_ADMIN_PORT = 10015
|
||||
private const val BOC_WEB_PORT = 10007
|
||||
|
||||
const val BOC_RPC_USER = "bankUser"
|
||||
const val BOC_RPC_PWD = "test"
|
||||
|
||||
const val BIGCORP_RPC_USER = "bigCorpUser"
|
||||
const val BIGCORP_RPC_PWD = "test"
|
||||
|
||||
class BankOfCordaCordform : CordformDefinition() {
|
||||
|
||||
init {
|
||||
@ -47,18 +54,18 @@ class BankOfCordaCordform : CordformDefinition() {
|
||||
adminAddress("localhost:$BOC_RPC_ADMIN_PORT")
|
||||
}
|
||||
webPort(BOC_WEB_PORT)
|
||||
rpcUsers(User("bankUser", "test", setOf(all())))
|
||||
rpcUsers(User(BOC_RPC_USER, BOC_RPC_PWD, setOf(all())))
|
||||
devMode(true)
|
||||
}
|
||||
node {
|
||||
name(BIGCORP_NAME)
|
||||
p2pPort(10008)
|
||||
rpcSettings {
|
||||
address("localhost:10009")
|
||||
address("localhost:$BIGCORP_RPC_PORT")
|
||||
adminAddress("localhost:10011")
|
||||
}
|
||||
webPort(10010)
|
||||
rpcUsers(User("bigCorpUser", "test", setOf(all())))
|
||||
rpcUsers(User(BIGCORP_RPC_USER, BIGCORP_RPC_PWD, setOf(all())))
|
||||
devMode(true)
|
||||
}
|
||||
}
|
||||
@ -113,8 +120,7 @@ object IssueCash {
|
||||
return BankOfCordaClientApi.requestRPCIssue(NetworkHostAndPort("localhost", BOC_RPC_PORT), createParams(amount, NOTARY_NAME))
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun requestWebIssue(amount: Amount<Currency>) {
|
||||
private fun requestWebIssue(amount: Amount<Currency>) {
|
||||
BankOfCordaClientApi.requestWebIssue(NetworkHostAndPort("localhost", BOC_WEB_PORT), createParams(amount, NOTARY_NAME))
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.corda.bank.api
|
||||
|
||||
import net.corda.bank.BOC_RPC_PWD
|
||||
import net.corda.bank.BOC_RPC_USER
|
||||
import net.corda.bank.api.BankOfCordaWebApi.IssueRequestParams
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.messaging.startFlow
|
||||
@ -31,7 +33,7 @@ object BankOfCordaClientApi {
|
||||
fun requestRPCIssue(rpcAddress: NetworkHostAndPort, params: IssueRequestParams): SignedTransaction {
|
||||
val client = CordaRPCClient(rpcAddress)
|
||||
// TODO: privileged security controls required
|
||||
client.start("bankUser", "test").use { connection ->
|
||||
client.start(BOC_RPC_USER, BOC_RPC_PWD).use { connection ->
|
||||
val rpc = connection.proxy
|
||||
rpc.waitUntilNetworkReady().getOrThrow()
|
||||
|
||||
|
@ -17,7 +17,7 @@ fun CordformDefinition.nodeRunner() = CordformNodeRunner(this)
|
||||
/**
|
||||
* A node runner creates and runs nodes for a given [[CordformDefinition]].
|
||||
*/
|
||||
class CordformNodeRunner(val cordformDefinition: CordformDefinition) {
|
||||
class CordformNodeRunner(private val cordformDefinition: CordformDefinition) {
|
||||
private var extraPackagesToScan = emptyList<String>()
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ class CordformNodeRunner(val cordformDefinition: CordformDefinition) {
|
||||
* Deploy the nodes specified in the given [CordformDefinition] and then execute the given [block] once all the nodes
|
||||
* and webservers are up. After execution all these processes will be terminated.
|
||||
*/
|
||||
fun deployAndRunNodesThen(block: () -> Unit) {
|
||||
fun deployAndRunNodesAndThen(block: () -> Unit) {
|
||||
runNodes(waitForAllNodesToFinish = false, block = block)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user