Skip to content

Merge 1.2 into master #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
corda_release_group = 'net.corda'
corda_release_version = '4.3'
tokens_release_group = "com.r3.corda.lib.tokens"
tokens_release_version = "1.2-SNAPSHOT"
corda_gradle_plugins_version = '5.0.8'
tokens_release_version = "1.2.2-SNAPSHOT"
corda_gradle_plugins_version = '5.0.12'
kotlin_version = '1.2.71'
junit_version = '4.12'
dokka_version = '0.9.17'
Expand All @@ -25,6 +25,7 @@ buildscript {
mavenCentral()
mavenLocal()
maven { url "http://ci-artifactory.corda.r3cev.com/artifactory/corda-releases" }
maven { url "http://ci-artifactory.corda.r3cev.com/artifactory/corda-dependencies" }
maven { url "https://repo.gradle.org/gradle/libs-releases-local/" }
}

Expand Down Expand Up @@ -72,6 +73,7 @@ subprojects {
maven { url "http://ci-artifactory.corda.r3cev.com/artifactory/corda-lib-dev" }
maven { url "http://ci-artifactory.corda.r3cev.com/artifactory/corda-lib" }
maven { url "https://repo.gradle.org/gradle/libs-releases-local/" }
maven { url "http://ci-artifactory.corda.r3cev.com/artifactory/corda-dependencies" }
}

apply plugin: 'kotlin'
Expand Down
14 changes: 3 additions & 11 deletions freighter-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,13 @@ sourceSets {

evaluationDependsOn(":workflows")
task freighterTest(type: Test, dependsOn: [project(":workflows").jar]) {
maxParallelForks 2
maxParallelForks 1
systemProperty "java.util.concurrent.ForkJoinPool.common.parallelism", "128"
testClassesDirs = sourceSets.freighterTest.output.classesDirs
classpath = sourceSets.freighterTest.runtimeClasspath
useJUnitPlatform {
includeTags "DOCKER"
excludeTags "AZURE", "ORACLE"
if (Os.isFamily(Os.FAMILY_WINDOWS) || Os.isFamily(Os.FAMILY_MAC)) {
//windows + mac cannot run comcast tests and cannot run oracle tests due to credential store issues
excludeTags "FULL_LINUX_KERNEL", "ORACLE"
}

if (Os.isFamily(Os.FAMILY_UNIX) && "uname -a".execute().getText().contains("microsoft")) {
excludeTags "FULL_LINUX_KERNEL"
}
excludeTags "AZURE", "FULL_LINUX_KERNEL", "ORACLE"
}
}

Expand All @@ -45,7 +37,7 @@ configurations {

dependencies {
freighterTestCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
freighterTestCompile "freighter:freighter-testing-core-junit5:0.4.5-SNAPSHOT"
freighterTestCompile "freighter:freighter-testing-core-junit5:0.7.1-SNAPSHOT"

freighterTestCompile project(":contracts")
freighterTestCompile project(":workflows")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,19 @@ package freighter.testing
import com.r3.corda.lib.tokens.contracts.states.FungibleToken
import com.r3.corda.lib.tokens.contracts.types.IssuedTokenType
import com.r3.corda.lib.tokens.contracts.types.TokenType
import com.r3.corda.lib.tokens.workflows.OwnerMigration
import com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens
import freighter.deployments.DeploymentContext
import freighter.deployments.NodeBuilder
import freighter.deployments.SingleNodeDeployment
import freighter.deployments.UnitOfDeployment.Companion.CORDA_4_3
import freighter.machine.DeploymentMachineProvider
import freighter.machine.generateRandomString
import liquibase.database.DatabaseConnection
import liquibase.database.core.PostgresDatabase
import net.corda.core.contracts.Amount
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import net.corda.nodeapi.internal.persistence.DatabaseConfig
import org.hamcrest.MatcherAssert
import org.hamcrest.core.Is
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import utility.LoggingUtils
import utility.Retry
import utility.getArtifactAndDependencies
import utility.getOrThrow
import java.net.URLClassLoader
import java.sql.Connection
import java.sql.Driver
import java.time.Duration
import java.util.*
import java.util.concurrent.CompletableFuture

class TokenSDKDBCompatibility : DockerRemoteMachineBasedTest() {

Expand Down Expand Up @@ -90,7 +76,7 @@ class TokenSDKDBCompatibility : DockerRemoteMachineBasedTest() {
.withCordapp(tokenSelection)
.withCordapp(modernCiV1)
.withDatabase(machineProvider.requestDatabase(db))
).withVersion("4.3")
).withVersion(CORDA_4_3)
.deploy(deploymentContext)

val nodeMachine = deploymentResult.getOrThrow().nodeMachines.single()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package freighter.testing

import com.r3.corda.lib.tokens.contracts.states.FungibleToken
import com.r3.corda.lib.tokens.contracts.types.IssuedTokenType
import com.r3.corda.lib.tokens.contracts.types.TokenType
import com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens
import com.r3.corda.lib.tokens.workflows.flows.rpc.MoveFungibleTokens
import com.r3.corda.lib.tokens.workflows.utilities.heldTokenAmountCriteria
import com.stress.flows.CreateNewCIFlow
import freighter.deployments.DeploymentContext
import freighter.deployments.NodeBuilder
import freighter.deployments.SingleNodeDeployment
import freighter.deployments.UnitOfDeployment
import freighter.machine.DeploymentMachineProvider
import freighter.machine.generateRandomString
import net.corda.core.contracts.Amount
import net.corda.core.internal.sumByLong
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.containsInAnyOrder
import org.junit.jupiter.api.Test
import utility.getOrThrow
import java.time.Duration

class TokenSDKUpgrade46Compatibility : DockerRemoteMachineBasedTest() {

//remove the prod key and sign with freighter key
val tokensV1Contracts = NodeBuilder.DeployedCordapp.fromGradleArtifact(
group = "com.r3.corda.lib.tokens",
artifact = "tokens-contracts",
version = "1.1"
).signedWithFreighterKey()

val tokensV1Workflows = NodeBuilder.DeployedCordapp.fromGradleArtifact(
group = "com.r3.corda.lib.tokens",
artifact = "tokens-workflows",
version = "1.1"
)

val tokensV1Selection = NodeBuilder.DeployedCordapp.fromGradleArtifact(
group = "com.r3.corda.lib.tokens",
artifact = "tokens-selection",
version = "1.1"
)

//we must sign with the same freighter key to allow contract upgrade from 1.1
val tokenCurrentContracts =
NodeBuilder.DeployedCordapp.fromClassPath("tokens-contracts").signedWithFreighterKey()

val tokenCurrentWorkflows =
NodeBuilder.DeployedCordapp.fromClassPath("tokens-workflows")

val modernCiV1 = NodeBuilder.DeployedCordapp.fromGradleArtifact(
group = "com.r3.corda.lib.ci",
artifact = "ci-workflows",
version = "1.0"
)

val freighterHelperCordapp = NodeBuilder.DeployedCordapp.fromClassPath("freighter-cordapp-flows")

@Test
fun `tokens can be upgraded on a node running postgres 9_6`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.PG_9_6)
}

@Test
fun `tokens can be upgraded on a node running postgres H2`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.H2)
}

@Test
fun `tokens can be upgraded on a node running postgres 10_10`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.PG_10_10)
}

@Test
fun `tokens can be upgraded on a node running postgres 11_5`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.PG_11_5)
}

@Test
fun `tokens can be upgraded on a node running ms_sql`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.MS_SQL)
}

@Test
@OracleTest
fun `tokens can be upgraded on a node running oracle 12 r2`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.ORACLE_12_R2)
}

private fun runTokensOnNodeRunningDatabase(db: DeploymentMachineProvider.DatabaseType) {
val randomString = generateRandomString()
val deploymentContext = DeploymentContext(machineProvider, nms, artifactoryUsername, artifactoryPassword)
val deploymentResult = SingleNodeDeployment(
NodeBuilder().withX500("O=PartyB, C=GB, L=LONDON, CN=$randomString")
.withCordapp(tokensV1Contracts)
.withCordapp(tokensV1Workflows)
.withCordapp(tokensV1Selection)
.withCordapp(modernCiV1)
.withCordapp(freighterHelperCordapp)
.withDatabase(machineProvider.requestDatabase(db))
).withVersion(UnitOfDeployment.CORDA_4_6_SNAPSHOT)
.deploy(deploymentContext)

val nodeMachine = deploymentResult.getOrThrow().nodeMachines.single()
val ourIdentity = nodeMachine.rpc { nodeInfo().legalIdentities.first() }


val tokenType = TokenType("StefCoin", 2)
val issuedTokenType = IssuedTokenType(ourIdentity, tokenType)
val amount = Amount(100_000_000, issuedTokenType)
val tokenToIssue1 = FungibleToken(amount, ourIdentity)
val tokenToIssue2 = FungibleToken(amount, ourIdentity)

val issueTx = nodeMachine.rpc {
startFlow(
::IssueTokens,
listOf(tokenToIssue1, tokenToIssue2), emptyList()
).returnValue.getOrThrow(Duration.ofMinutes(1))
}


nodeMachine.stopNode()
nodeMachine.upgradeCordapp(tokensV1Contracts, tokenCurrentContracts)
nodeMachine.upgradeCordapp(tokensV1Workflows, tokenCurrentWorkflows)
//selection should be fat-jarred into tokens-workflows
nodeMachine.deleteCordapp(tokensV1Selection)
nodeMachine.startNode()

nodeMachine.rpc {
val keyCriteria = heldTokenAmountCriteria(tokenType, ourIdentity)
val actual = vaultQueryByCriteria(keyCriteria, FungibleToken::class.java).states.map { it.state.data }
MatcherAssert.assertThat(actual, containsInAnyOrder(tokenToIssue1, tokenToIssue2))
}

val createdCi = nodeMachine.rpc {
startFlow(::CreateNewCIFlow).returnValue.getOrThrow().also {
println("Successfully created CI: $it")
}
}

val moveToCi = nodeMachine.rpc {
startFlow(
::MoveFungibleTokens,
Amount(50_000_000, tokenType),
createdCi
).returnValue.getOrThrow(Duration.ofMinutes(1))
}

nodeMachine.rpc {
val keyCriteria = heldTokenAmountCriteria(tokenType, createdCi)
val actual = vaultQueryByCriteria(keyCriteria, FungibleToken::class.java).states.map { it.state.data }
MatcherAssert.assertThat(actual.map { it.amount }.sumByLong { it.quantity }, `is`(50_000_000L))
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import com.stress.flows.CreateNewCIFlow
import freighter.deployments.DeploymentContext
import freighter.deployments.NodeBuilder
import freighter.deployments.SingleNodeDeployment
import freighter.deployments.UnitOfDeployment
import freighter.machine.DeploymentMachineProvider
import freighter.machine.generateRandomString
import net.corda.core.contracts.Amount
import net.corda.core.internal.sumByLong
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.BeforeEach
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.containsInAnyOrder
import org.junit.jupiter.api.Test
import utility.getOrThrow
import java.time.Duration
import java.util.concurrent.CompletableFuture

class TokenSDKUpgradeDBCompatibility : DockerRemoteMachineBasedTest() {

Expand Down Expand Up @@ -65,6 +65,11 @@ class TokenSDKUpgradeDBCompatibility : DockerRemoteMachineBasedTest() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.PG_9_6)
}

@Test
fun `tokens can be upgraded on a node running postgres H2`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.H2)
}

@Test
fun `tokens can be upgraded on a node running postgres 10_10`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.PG_10_10)
Expand Down Expand Up @@ -100,7 +105,7 @@ class TokenSDKUpgradeDBCompatibility : DockerRemoteMachineBasedTest() {
.withCordapp(modernCiV1)
.withCordapp(freighterHelperCordapp)
.withDatabase(machineProvider.requestDatabase(db))
).withVersion("4.3")
).withVersion(UnitOfDeployment.CORDA_4_3)
.deploy(deploymentContext)

val nodeMachine = deploymentResult.getOrThrow().nodeMachines.single()
Expand Down
Loading