Skip to content

Commit

Permalink
put workflows jar on a bit of a diet
Browse files Browse the repository at this point in the history
  • Loading branch information
roastario committed Jun 6, 2020
1 parent 364d8a0 commit d371c0c
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 97 deletions.
1 change: 0 additions & 1 deletion contracts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

6 changes: 2 additions & 4 deletions workflows/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.cordapp'


evaluationDependsOn(":modules:money")
evaluationDependsOn(":modules:selection")

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

cordapp {
Expand Down Expand Up @@ -49,7 +47,7 @@ configurations {
}

compileKotlin{
dependsOn (moneyProject.jar, selectionProject.jar)
dependsOn (selectionProject.jar)
}

dependencies {
Expand All @@ -76,7 +74,7 @@ dependencies {
// CorDapp dependencies.
cordapp project(":contracts")

compile(files(moneyProject.jar.archivePath, selectionProject.jar.archivePath))
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
@@ -0,0 +1,27 @@
package com.r3.corda.lib.tokens.money

import com.r3.corda.lib.tokens.contracts.types.TokenType
import java.util.*

/**
* A representation of digital money. This implementation somewhat mirrors that of [Currency].
*
* Note that the primary constructor only exists for simple and convenient access from Java code.
*
* @param currencyCode The currency code that represents the TokenType which the developer wishes to instantiate.
*/
class DigitalCurrency {
companion object {
private val registry = mapOf(
Pair("XRP", TokenType("Ripple", 6)),
Pair("BTC", TokenType("Bitcoin", 8)),
Pair("ETH", TokenType("Ethereum", 18)),
Pair("DOGE", TokenType("Dogecoin", 8))
)

@JvmStatic
fun getInstance(currencyCode: String): TokenType {
return registry[currencyCode] ?: throw IllegalArgumentException("$currencyCode doesn't exist.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.r3.corda.lib.tokens.money

import com.r3.corda.lib.tokens.contracts.types.TokenType
import java.util.*

/**
* This class is used to return a [TokenType] with the required currency code and fraction digits for fiat currencies.
*
* Note that the primary constructor only exists for simple and convenient access from Java code.
*
* @param currencyCode The currency code that represents the TokenType which the developer wishes to instantiate.
*/
class FiatCurrency {
companion object {
// Uses the java money registry.
@JvmStatic
fun getInstance(currencyCode: String): TokenType {
val currency = Currency.getInstance(currencyCode)
return TokenType(currency.currencyCode, currency.defaultFractionDigits)
}
}
}
Loading

0 comments on commit d371c0c

Please sign in to comment.