Skip to content

Commit

Permalink
Add serialization env to OwnerMigration (#212)
Browse files Browse the repository at this point in the history
* Make redeem flow handlers open (#199)

* Make redeem flow handlers open to allow adding custom processing logic for redeemed tokens on the issuer`s side.

Make ObserverAwareFinalityFlowHandler return a SignedTransaction if one was received.

* Undo removing a flow

Co-authored-by: Stefano Franz <[email protected]>

* Put Workflows Jar on a diet - exclude all corda runtime files (#206)

* keep

* put workflows jar on a bit of a diet

* Add serialization env to OwnerMigration

* fix migration for 4.6

Co-authored-by: Andrius Dagys <[email protected]>
Co-authored-by: Stefano Franz <[email protected]>
Co-authored-by: Stefano Franz <[email protected]>
  • Loading branch information
4 people committed Sep 25, 2020
1 parent 379d568 commit decdcbe
Show file tree
Hide file tree
Showing 25 changed files with 335 additions and 174 deletions.
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"
corda_gradle_plugins_version = '5.0.8'
tokens_release_version = "1.2.1-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
5 changes: 2 additions & 3 deletions contracts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'kotlin-jpa'
apply plugin: 'net.corda.plugins.cordapp'

if (!(corda_release_version in ['4.1'])) {
apply from: "${rootProject.projectDir}/deterministic.gradle"
apply from: "${rootProject.projectDir}/deterministic.gradle"
}

sourceSets {
Expand All @@ -23,7 +23,7 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

// Corda dependencies.
cordaCompile ("$corda_release_group:corda-core:$corda_release_version"){
cordaCompile("$corda_release_group:corda-core:$corda_release_version") {
changing = true
}

Expand All @@ -34,7 +34,6 @@ dependencies {
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "junit:junit:$junit_version"
testCompile "$corda_release_group:corda-node-driver:$corda_release_version"
testCompile project(":modules:money")
testCompile project(":modules:contracts-for-testing")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.r3.corda.lib.tokens.contracts

import com.r3.corda.lib.tokens.contracts.types.TokenType
import net.corda.core.contracts.Amount

class CommonTokens {

companion object {
val USD = TokenType("USD", 2)
val GBP = TokenType("GBP", 2)
}

}

fun Number.ofType(tt: TokenType): Amount<TokenType> {
return Amount(this.toLong(), tt)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import com.r3.corda.lib.tokens.contracts.utilities.getAttachmentIdForGenericPara
import com.r3.corda.lib.tokens.contracts.utilities.heldBy
import com.r3.corda.lib.tokens.contracts.utilities.issuedBy
import com.r3.corda.lib.tokens.contracts.utilities.of
import com.r3.corda.lib.tokens.money.GBP
import com.r3.corda.lib.tokens.money.USD
import com.r3.corda.lib.tokens.testing.states.DodgeToken
import com.r3.corda.lib.tokens.testing.states.DodgeTokenContract
import com.r3.corda.lib.tokens.testing.states.RUB
import com.r3.corda.lib.tokens.testing.states.RubleToken
import com.r3.corda.lib.tokens.contracts.CommonTokens.Companion.USD
import com.r3.corda.lib.tokens.contracts.CommonTokens.Companion.GBP
import org.junit.Test

// TODO: Some of these tests are testing AbstractToken and should be moved into the super-class.
Expand Down Expand Up @@ -58,7 +58,7 @@ class FungibleTokenTests : ContractTestCommon() {
}
// Includes a group with no assigned command.
tweak {
output(FungibleTokenContract.contractId, 10.USD issuedBy ISSUER.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy ISSUER.party heldBy ALICE.party)
command(ISSUER.publicKey, IssueTokenCommand(issuedToken, listOf(0)))
this `fails with` "There is a token group with no assigned command!"
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class FungibleTokenTests : ContractTestCommon() {
// Includes the same token issued by a different issuer.
// You wouldn't usually do this but it is possible.
tweak {
output(FungibleTokenContract.contractId, 1.GBP issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 1.ofType(GBP) issuedBy BOB.party heldBy ALICE.party)
command(ISSUER.publicKey, IssueTokenCommand(issuedToken, listOf(0)))
command(BOB.publicKey, IssueTokenCommand(GBP issuedBy BOB.party, listOf(1)))
verifies()
Expand Down Expand Up @@ -131,7 +131,7 @@ class FungibleTokenTests : ContractTestCommon() {

// Move coupled with an issue.
tweak {
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
//the issue token is added after the move tokens, so it will have index(1)
command(BOB.publicKey, IssueTokenCommand(USD issuedBy BOB.party, outputs = listOf(1)))

Expand All @@ -140,63 +140,63 @@ class FungibleTokenTests : ContractTestCommon() {

// Input missing.
tweak {
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy BOB.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, outputs = listOf(1)))

this `fails with` "When moving tokens, there must be input states present."
}

// Output missing.
tweak {
input(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
input(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1)))

this `fails with` "When moving tokens, there must be output states present."
}

// Inputs sum to zero.
tweak {
input(FungibleTokenContract.contractId, 0.USD issuedBy BOB.party heldBy ALICE.party)
input(FungibleTokenContract.contractId, 0.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy BOB.party)
input(FungibleTokenContract.contractId, 0.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
input(FungibleTokenContract.contractId, 0.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1, 2), outputs = listOf(1)))
// Command for the move.
this `fails with` "In move groups there must be an amount of input tokens > ZERO."
}

// Outputs sum to zero.
tweak {
input(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 0.USD issuedBy BOB.party heldBy BOB.party)
output(FungibleTokenContract.contractId, 0.USD issuedBy BOB.party heldBy BOB.party)
input(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 0.ofType(USD) issuedBy BOB.party heldBy BOB.party)
output(FungibleTokenContract.contractId, 0.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1), outputs = listOf(1, 2)))
// Command for the move.
this `fails with` "In move groups there must be an amount of output tokens > ZERO."
}

// Unbalanced move.
tweak {
input(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 11.USD issuedBy BOB.party heldBy BOB.party)
input(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 11.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1), outputs = listOf(1)))
// Command for the move.
this `fails with` "In move groups the amount of input tokens MUST EQUAL the amount of output tokens. " +
"In other words, you cannot create or destroy value when moving tokens."
}

tweak {
input(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy BOB.party)
output(FungibleTokenContract.contractId, 0.USD issuedBy BOB.party heldBy BOB.party)
input(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy BOB.party)
output(FungibleTokenContract.contractId, 0.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1), outputs = listOf(1, 2)))
// Command for the move.
this `fails with` "You cannot create output token amounts with a ZERO amount."
}

// Two moves (two different groups).
tweak {
input(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy BOB.party)
input(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(USD) issuedBy BOB.party heldBy BOB.party)
command(ALICE.publicKey, MoveTokenCommand(USD issuedBy BOB.party, inputs = listOf(1), outputs = listOf(1)))
// Command for the move.
verifies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.r3.corda.lib.tokens.contracts.utilities.heldBy
import com.r3.corda.lib.tokens.contracts.utilities.issuedBy
import com.r3.corda.lib.tokens.contracts.utilities.of
import com.r3.corda.lib.tokens.contracts.utilities.withNewHolder
import com.r3.corda.lib.tokens.money.USD
import com.r3.corda.lib.tokens.testing.states.PTK
import com.r3.corda.lib.tokens.testing.states.RUB
import org.junit.Test
Expand Down Expand Up @@ -58,7 +57,7 @@ class NonFungibleTokenTests : ContractTestCommon() {
}
// Includes a group with no assigned command.
tweak {
output(FungibleTokenContract.contractId, 10.USD issuedBy ISSUER.party heldBy ALICE.party)
output(FungibleTokenContract.contractId, 10.ofType(CommonTokens.USD) issuedBy ISSUER.party heldBy ALICE.party)
command(ISSUER.publicKey, IssueTokenCommand(issuedToken, outputs = listOf(0)))
this `fails with` "There is a token group with no assigned command!"
}
Expand All @@ -71,7 +70,7 @@ class NonFungibleTokenTests : ContractTestCommon() {

// Includes another token type and a matching command.
tweak {
val otherToken = USD issuedBy ISSUER.party
val otherToken = CommonTokens.USD issuedBy ISSUER.party
output(FungibleTokenContract.contractId, 10 of otherToken heldBy ALICE.party)
command(ISSUER.publicKey, IssueTokenCommand(issuedToken, outputs = listOf(0)))
command(ISSUER.publicKey, IssueTokenCommand(otherToken, outputs = listOf(1)))
Expand Down Expand Up @@ -118,8 +117,8 @@ class NonFungibleTokenTests : ContractTestCommon() {

// Move coupled with an issue.
tweak {
output(FungibleTokenContract.contractId, 10.USD issuedBy BOB.party heldBy ALICE.party)
command(BOB.publicKey, IssueTokenCommand(USD issuedBy BOB.party, outputs = listOf(1)))
output(FungibleTokenContract.contractId, 10.ofType(CommonTokens.USD) issuedBy BOB.party heldBy ALICE.party)
command(BOB.publicKey, IssueTokenCommand(CommonTokens.USD issuedBy BOB.party, outputs = listOf(1)))
// Command for the move.
command(ALICE.publicKey, MoveTokenCommand(issuedToken, inputs = listOf(0), outputs = listOf(0)))
verifies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.r3.corda.lib.tokens.contracts.states.FungibleToken
import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken
import com.r3.corda.lib.tokens.contracts.types.TokenPointer
import com.r3.corda.lib.tokens.contracts.utilities.*
import com.r3.corda.lib.tokens.money.GBP
import net.corda.core.crypto.Crypto
import net.corda.core.crypto.SignableData
import net.corda.core.crypto.SignatureMetadata
Expand Down Expand Up @@ -57,8 +56,8 @@ class TokenPointerTests : ContractTestCommon() {
fun `tokenTypeJarHash must be not null if tokenType is not a pointer`() {
val pointer: TokenPointer<TestEvolvableTokenType> = TestEvolvableTokenType(listOf(ALICE.party)).toPointer()
val pointerToken: NonFungibleToken = pointer issuedBy ISSUER.party heldBy ALICE.party
val staticToken: NonFungibleToken = GBP issuedBy ISSUER.party heldBy ALICE.party
val staticToken: NonFungibleToken = CommonTokens.GBP issuedBy ISSUER.party heldBy ALICE.party
assertEquals(pointerToken.tokenTypeJarHash, null)
assertEquals(staticToken.tokenTypeJarHash, GBP.getAttachmentIdForGenericParam())
assertEquals(staticToken.tokenTypeJarHash, CommonTokens.GBP.getAttachmentIdForGenericParam())
}
}
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
Loading

0 comments on commit decdcbe

Please sign in to comment.