Skip to content
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

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

Merged
merged 3 commits into from
Jun 8, 2020
Merged
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
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())
}
}
1 change: 0 additions & 1 deletion modules/contracts-for-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ dependencies {

// CorDapp dependencies.
cordapp project(":contracts")
cordapp project(":modules:money")
}
57 changes: 0 additions & 57 deletions modules/money/build.gradle

This file was deleted.

2 changes: 0 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
include 'contracts'
include 'workflows'
include 'modules:money'
include 'modules:contracts-for-testing'
include 'modules:selection'
findProject(':modules:money')?.name = 'money'
include 'freighter-tests'

17 changes: 15 additions & 2 deletions workflows/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ apply plugin: 'kotlin-jpa'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.cordapp'


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file ... WTF?!
Why?

If there isn't an easier way of doing this then Gradle Must DIE!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an edge case in our fatjarring.

We want to compile in the selection project, but the selection project cordaCompile Corda components, which when you don't use the jar approach results in the entire Corda runtime being included in the fatJar due to transitive dependencies.

The next step is to just move all the logic into workflows.. which I'm seriously considering.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably would make sense to do so, given that money and selection aren't separate cordapps anymore and unlikely to be used outside of the token sdk.

evaluationDependsOn(":modules:selection")

def selectionProject = project(":modules:selection")

cordapp {
targetPlatformVersion 5
minimumPlatformVersion 5
Expand Down Expand Up @@ -41,6 +46,10 @@ configurations {
integrationTestRuntime.extendsFrom testRuntime
}

compileKotlin{
dependsOn (selectionProject.jar)
}

dependencies {
// Kotlin.
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Expand All @@ -50,6 +59,10 @@ dependencies {
changing = true
}

cordaCompile("$corda_release_group:corda-node-api:$corda_release_version") {
changing = true
}

// Logging.
testCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"

Expand All @@ -60,8 +73,8 @@ dependencies {

// CorDapp dependencies.
cordapp project(":contracts")
compile project(":modules:money")
compile project(":modules:selection")

compile(files(selectionProject.jar.archivePath))

//CI for confidential tokens
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class TokenDriverTest {
portAllocation = incrementalPortAllocation(),
startNodesInProcess = false,
cordappsForAllNodes = listOf(
TestCordapp.findCordapp("com.r3.corda.lib.tokens.money"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.selection"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.contracts"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.workflows"),
Expand All @@ -156,7 +155,6 @@ class TokenDriverTest {
portAllocation = incrementalPortAllocation(),
startNodesInProcess = false,
cordappsForAllNodes = listOf(
TestCordapp.findCordapp("com.r3.corda.lib.tokens.money"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.contracts"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.workflows"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.testing"),
Expand Down Expand Up @@ -265,7 +263,6 @@ class TokenDriverTest {
inMemoryDB = false,
startNodesInProcess = false,
cordappsForAllNodes = listOf(
TestCordapp.findCordapp("com.r3.corda.lib.tokens.money"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.contracts"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.workflows"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.testing"),
Expand Down Expand Up @@ -323,7 +320,6 @@ class TokenDriverTest {
inMemoryDB = false,
startNodesInProcess = false,
cordappsForAllNodes = listOf(
TestCordapp.findCordapp("com.r3.corda.lib.tokens.money"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.contracts"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.workflows"),
TestCordapp.findCordapp("com.r3.corda.lib.tokens.testing"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ import net.corda.core.crypto.toStringShort
import net.corda.core.internal.readFully
import net.corda.core.serialization.SerializationContext
import net.corda.core.serialization.deserialize
import net.corda.core.serialization.internal.SerializationEnvironment
import net.corda.core.serialization.internal._allEnabledSerializationEnvs
import net.corda.core.serialization.internal._inheritableContextSerializationEnv
import net.corda.core.serialization.internal.effectiveSerializationEnv
import net.corda.core.transactions.SignedTransaction
import net.corda.core.utilities.contextLogger
import net.corda.serialization.internal.AMQP_P2P_CONTEXT
import net.corda.serialization.internal.AMQP_STORAGE_CONTEXT
import net.corda.serialization.internal.CordaSerializationMagic
import net.corda.serialization.internal.SerializationFactoryImpl
Expand Down