Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ see changes to this list.
* Kai-Michael Schramm
* Karel Hajek (Barclays Capital)
* karnauskas
* Karsten Leonhardt (Commerzbank AG)
* Kasia Streich (R3)
* Kat Baker (R3)
* Keerthi Nelaturu (Scotiabank)
Expand Down
36 changes: 35 additions & 1 deletion testing/node-driver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ task integrationTest(type: Test) {
classpath = sourceSets.integrationTest.runtimeClasspath
}

integrationTest {
useJUnitPlatform()
}

jar {
baseName 'corda-node-driver'
manifest {
Expand Down Expand Up @@ -99,4 +103,34 @@ scanApi {
"<init>(Lnet/corda/testing/node/InMemoryMessagingNetwork\$PeerHandle;Lnet/corda/node/services/messaging/Message;Lnet/corda/core/messaging/MessageRecipients;Lkotlin/jvm/internal/DefaultConstructorMarker;)V"
]
]
}
}

// quasar exclusions upon agent code instrumentation at run-time
quasar {
excludePackages.addAll(
"antlr**",
"com.codahale**",
"com.fasterxml.**",
"com.github.benmanes.caffeine.**",
"com.google.**",
"com.lmax.**",
"com.zaxxer.**",
"net.bytebuddy**",
"io.github.classgraph**",
"io.netty*",
"liquibase**",
"nonapi.io.github.classgraph.**",
"org.apiguardian.**",
"org.bouncycastle**",
"org.codehaus.**",
"org.h2**",
"org.hibernate**",
"org.jboss.**",
"org.objenesis**",
"org.w3c.**",
"org.xml**",
"org.yaml**",
"rx**",
"net.corda.testing.core**"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.core.contracts.Amount
import net.corda.core.messaging.vaultTrackBy
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.CashIssueFlow
import net.corda.finance.flows.CashPaymentFlow
import net.corda.finance.`issued by`
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOC_NAME
import net.corda.testing.core.expect
import net.corda.testing.core.expectEvents
import org.assertj.core.api.Assertions.assertThat
import java.util.Currency
import kotlin.test.assertEquals

class CashFlowsForTesting(cordaDriverJunitJupiter: CordaDriverJunitJupiter) {

private val ref = OpaqueBytes.of(0x01)

private val bankOfCordaNode = cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow().first {
it.nodeInfo.legalIdentities.first().name == BOC_NAME
}

private val aliceNode = cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow().first {
it.nodeInfo.legalIdentities.first().name == ALICE_NAME
}

private val defaultNotaryIdentity = cordaDriverJunitJupiter.getDefaultCordaNotaryHandleOrThrow().identity

private val bankOfCorda = bankOfCordaNode.nodeInfo.legalIdentities.first()
private val alice = aliceNode.nodeInfo.legalIdentities.first()

fun bankOfCordaIssues(
amountToIssue: Amount<Currency> = 2000.DOLLARS
) {

bankOfCordaNode.rpc.startFlowDynamic(
CashIssueFlow::class.java,
amountToIssue,
ref,
defaultNotaryIdentity
).returnValue.getOrThrow()
}

fun paySomeCash(
forceException: Boolean = false
) {

val expectedPayment = 500.DOLLARS
val expectedChange = 1500.DOLLARS

// Register for vault updates
val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL)
val (_, vaultUpdatesBoc) = bankOfCordaNode.rpc.vaultTrackBy<Cash.State>(criteria)
val (_, vaultUpdatesBankClient) = aliceNode.rpc.vaultTrackBy<Cash.State>(criteria)

bankOfCordaNode.rpc.startFlowDynamic(
CashPaymentFlow::class.java,
expectedPayment,
alice
).returnValue.getOrThrow()

// Check Bank of Corda vault updates - we take in some issued cash and split it into $500 to the notary
// and $1,500 back to us, so we expect to consume one state, produce one state for our own vault
vaultUpdatesBoc.expectEvents {
expect { (consumed, produced) ->
if (forceException) {
// use this to check whether exceptions are correctly thrown
assertThat(consumed).hasSize(2)
} else {
assertThat(consumed).hasSize(1)
}
assertThat(produced).hasSize(1)
val changeState = produced.single().state.data
assertEquals(expectedChange.`issued by`(bankOfCorda.ref(ref)), changeState.amount)
}
}

// Check notary node vault updates
vaultUpdatesBankClient.expectEvents {
expect { (consumed, produced) ->
assertThat(consumed).isEmpty()
assertThat(produced).hasSize(1)
val paymentState = produced.single().state.data
assertEquals(expectedPayment.`issued by`(bankOfCorda.ref(ref)), paymentState.amount)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOC_NAME
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.NodeParameters
import net.corda.testing.node.internal.FINANCE_CORDAPPS

val cordaDriverJunitJupiterTestConfig = CordaDriverJunitJupiterConfig(
parametersForNodes = listOf(
NodeParameters(
ALICE_NAME
),
NodeParameters(
BOC_NAME
)
),
driverParameters = DriverParameters(
cordappsForAllNodes = FINANCE_CORDAPPS,
isDebug = true,
startNodesInProcess = true,
networkParameters = testNetworkParameters(
minimumPlatformVersion = 4
)
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.finance.DOLLARS
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.RegisterExtension
import rx.exceptions.OnErrorNotImplementedException
import java.util.concurrent.TimeUnit

@Timeout(300_000, unit = TimeUnit.MILLISECONDS)
class TestsOfAfterEachTestInCordaDriverContextHookThrowsCorrectly : JunitJupiterIntegrationTestTemplate() {

companion object {

@JvmField
@RegisterExtension
val cordaDriverJunitJupiterStatic = cordaDriverJunitJupiterTestConfig.buildDriver()
}

override val cordaDriverJunitJupiter: CordaDriverJunitJupiter
get() = cordaDriverJunitJupiterStatic

@AfterEachTestInCordaDriverContext
fun testAfterEachTestInCordaDriverContextThrowsCorrectly() {
assertThrows<OnErrorNotImplementedException> {
CashFlowsForTesting(cordaDriverJunitJupiter).apply {
bankOfCordaIssues(2000.DOLLARS)
paySomeCash(forceException = true)
}
}
}

@Test
fun `empty test to test correct thowing behaviour of 'AfterEachTestInCordaDriverContext'`() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.finance.DOLLARS
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.extension.RegisterExtension
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals

@Timeout(300_000, unit = TimeUnit.MILLISECONDS)
class TestsOfAfterEachTestInCordaDriverContextHookWithSuccess : JunitJupiterIntegrationTestTemplate() {

companion object {

@JvmField
@RegisterExtension
val cordaDriverJunitJupiterStatic = cordaDriverJunitJupiterTestConfig.buildDriver()
}

override val cordaDriverJunitJupiter: CordaDriverJunitJupiter
get() = cordaDriverJunitJupiterStatic

@AfterEachTestInCordaDriverContext
fun testFunctionalityOfAfterEachTestInCordaDriverContext() {

assertDoesNotThrow {
cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow()
}

assertEquals(
cordaDriverJunitJupiterTestConfig.parametersForNodes.size,
cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow().size
)

assertEquals(
cordaDriverJunitJupiterTestConfig.parametersForNodes.map { it.providedName },
cordaDriverJunitJupiter.cordaX500Names,
"The Node handles `CordaX500Name` attributes should match the provided names of the `NodeParameter` instances of the `CordaDriverJunitJupiterTestConfig`."
)

CashFlowsForTesting(cordaDriverJunitJupiter).apply {
bankOfCordaIssues(2000.DOLLARS)
paySomeCash()
}
}

@Test
fun `empty test to test not throwing behaviour of 'AfterEachTestInCordaDriverContext'`() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.finance.DOLLARS
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.RegisterExtension
import rx.exceptions.OnErrorNotImplementedException
import java.util.concurrent.TimeUnit

@Timeout(300_000, unit = TimeUnit.MILLISECONDS)
class TestsOfBeforeEachTestInCordaDriverContextHookThrowsCorrectly : JunitJupiterIntegrationTestTemplate() {

companion object {

@JvmField
@RegisterExtension
val cordaDriverJunitJupiterStatic = cordaDriverJunitJupiterTestConfig.buildDriver()
}

override val cordaDriverJunitJupiter: CordaDriverJunitJupiter
get() = cordaDriverJunitJupiterStatic

@BeforeEachTestInCordaDriverContext
fun testBeforeEachTestInCordaDriverContextThrowsCorrectly() {
assertThrows<OnErrorNotImplementedException> {
CashFlowsForTesting(cordaDriverJunitJupiter).apply {
bankOfCordaIssues(2000.DOLLARS)
paySomeCash(forceException = true)
}
}
}

@Test
fun `empty test to test correct thowing behaviour of 'BeforeEachTestInCordaDriverContext'`() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.corda.testing.driver.junit.jupiter

import net.corda.finance.DOLLARS
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.extension.RegisterExtension
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals

@Timeout(300_000, unit = TimeUnit.MILLISECONDS)
class TestsOfBeforeEachTestInCordaDriverContextHookWithSuccess : JunitJupiterIntegrationTestTemplate() {

companion object {

@JvmField
@RegisterExtension
val cordaDriverJunitJupiterStatic = cordaDriverJunitJupiterTestConfig.buildDriver()
}

override val cordaDriverJunitJupiter: CordaDriverJunitJupiter
get() = cordaDriverJunitJupiterStatic

@BeforeEachTestInCordaDriverContext
fun testFunctionalityOfBeforeEachTestInCordaDriverContext() {

assertDoesNotThrow {
cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow()
}

assertEquals(
cordaDriverJunitJupiterTestConfig.parametersForNodes.size,
cordaDriverJunitJupiter.getCordaNodeHandlesOrThrow().size
)

assertEquals(
cordaDriverJunitJupiterTestConfig.parametersForNodes.map { it.providedName },
cordaDriverJunitJupiter.cordaX500Names,
"The Node handles `CordaX500Name` attributes should match the provided names of the `NodeParameter` instances of the `CordaDriverJunitJupiterTestConfig`."
)

CashFlowsForTesting(cordaDriverJunitJupiter).apply {
bankOfCordaIssues(2000.DOLLARS)
paySomeCash()
}
}

@Test
fun `empty test to test not throwing behaviour of 'BeforeEachTestInCordaDriverContext'`() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.corda.testing.driver.junit.jupiter

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import kotlin.test.assertNull

class TestsOfBeforeNodeInitInCordaDriverContextHook : JunitJupiterIntegrationTestTemplate() {

companion object {

@JvmField
@RegisterExtension
val cordaDriverJunitJupiterStatic = cordaDriverJunitJupiterTestConfig.buildDriver()
}

override val cordaDriverJunitJupiter: CordaDriverJunitJupiter
get() = cordaDriverJunitJupiterStatic

@BeforeNodeInitInCordaDriverContext
fun testBeforeNodeInitInCordaDriverContextBehaviour() {

assertNull(cordaDriverJunitJupiter.getCordaNodeHandlesOrNull(), "Expect the Corda node handles to be not initialized before the nodes started.")
assertNull(cordaDriverJunitJupiter.getDefaultCordaNotaryHandleOrNull(), "Expect the Corda default notary handle to be not initialized before the nodes started.")
}

@Test
fun `empty test to test behaviour of 'BeforeNodeInitInCordaDriverContext'`() {
}
}
Loading