Hook up anonymised payment and add test for that + some code reformatting

This commit is contained in:
Christian Sailer 2017-11-24 14:54:57 +00:00
parent 0b7678b8ec
commit aab2ad58d9
2 changed files with 34 additions and 11 deletions

View File

@ -4,9 +4,11 @@ import co.paralleluniverse.fibers.Suspendable
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.OnLedgerAsset
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PartyAndAmount
import net.corda.confidential.SwapIdentitiesFlow
import net.corda.core.contracts.*
import net.corda.core.flows.StartableByRPC
import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes
@ -34,6 +36,7 @@ class CashIssueAndPaymentNoSelection(val amount: Amount<Currency>,
val notary: Party,
progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(request: CashIssueAndPaymentFlow.IssueAndPaymentRequest) : this(request.amount, request.issueRef, request.recipient, request.anonymous, request.notary, tracker())
constructor(amount: Amount<Currency>, issueRef: OpaqueBytes, payTo: Party, anonymous: Boolean, notary: Party) : this(amount, issueRef, payTo, anonymous, notary, tracker())
@Suspendable
override fun call(): Result {
@ -42,9 +45,20 @@ class CashIssueAndPaymentNoSelection(val amount: Amount<Currency>,
val issueResult = subFlow(CashIssueFlow(amount, issueRef, notary))
val cashStateAndRef = issueResult.stx.tx.outRef<Cash.State>(0)
progressTracker.currentStep = GENERATING_ID
val txIdentities = if (anonymous) {
subFlow(SwapIdentitiesFlow(recipient))
} else {
emptyMap<Party, AnonymousParty>()
}
val anonymousRecipient = txIdentities[recipient] ?: recipient
val changeIdentity = serviceHub.keyManagementService.freshKeyAndCert(ourIdentityAndCert, false)
progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary)
val (spendTx, keysForSigning) = OnLedgerAsset.generateSpend(builder, listOf(PartyAndAmount(recipient, amount)), listOf(cashStateAndRef),
val (spendTx, keysForSigning) = OnLedgerAsset.generateSpend(builder, listOf(PartyAndAmount(anonymousRecipient, amount)), listOf(cashStateAndRef),
changeIdentity.party.anonymise(),
{ state, quantity, owner -> deriveState(state, quantity, owner) },
{ Cash().generateMoveCommand() })
@ -56,7 +70,4 @@ class CashIssueAndPaymentNoSelection(val amount: Amount<Currency>,
val notarised = finaliseTx(tx, setOf(recipient), "Unable to notarise spend")
return Result(notarised, recipient)
}
constructor(amount: Amount<Currency>, issueRef: OpaqueBytes, payTo: Party, anonymous: Boolean, notary: Party) : this(amount, issueRef, payTo, anonymous, notary, tracker())
}
}

View File

@ -17,11 +17,19 @@ import net.corda.testing.node.MockNetwork.MockNode
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.test.assertEquals
class CashIssueAndPayNoSelectionTests {
@RunWith(Parameterized::class)
class CashIssueAndPayNoSelectionTests(private val anonymous: Boolean) {
companion object {
@Parameterized.Parameters(name = "Anonymous = {0}")
@JvmStatic
fun data() = listOf(false, true)
}
private lateinit var mockNet: MockNetwork
private val initialBalance = 2000.DOLLARS
private val ref = OpaqueBytes.of(0x01)
private lateinit var bankOfCordaNode: StartedNode<MockNode>
private lateinit var bankOfCorda: Party
@ -30,7 +38,8 @@ class CashIssueAndPayNoSelectionTests {
@Before
fun start() {
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("com.r3.corda.enterprise.perftestcordapp.contracts.asset"))
mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(),
cordappPackages = listOf("com.r3.corda.enterprise.perftestcordapp.contracts.asset"))
bankOfCordaNode = mockNet.createPartyNode(BOC.name)
aliceNode = mockNet.createPartyNode(ALICE.name)
bankOfCorda = bankOfCordaNode.info.chooseIdentity()
@ -51,10 +60,13 @@ class CashIssueAndPayNoSelectionTests {
bankOfCordaNode.database.transaction {
// Register for vault updates
val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL)
val (_, vaultUpdatesBoc) = bankOfCordaNode.services.vaultService.trackBy<Cash.State>(criteria)
val (_, vaultUpdatesBankClient) = aliceNode.services.vaultService.trackBy<Cash.State>(criteria)
val (_, vaultUpdatesBoc)
= bankOfCordaNode.services.vaultService.trackBy<Cash.State>(criteria)
val (_, vaultUpdatesBankClient)
= aliceNode.services.vaultService.trackBy<Cash.State>(criteria)
val future = bankOfCordaNode.services.startFlow(CashIssueAndPaymentNoSelection(expectedPayment, OpaqueBytes.of(1), payTo, false, notary)).resultFuture
val future = bankOfCordaNode.services.startFlow(CashIssueAndPaymentNoSelection(
expectedPayment, OpaqueBytes.of(1), payTo, anonymous, notary)).resultFuture
mockNet.runNetwork()
future.getOrThrow()