Giter Club home page Giter Club logo

corda-training-template's Introduction

Corda

Corda Training Template

This repo contains all of the instructions and class templates for the practical exercises of the Corda two day training course.

This repository is divided into two parts: Java templates, and Kotlin templates. You may complete the training in whichever language you prefer.

To all external trainers:

This repo will have a major upgrade on March 26th. The primary changes will be

  1. Corda version bump
  2. Cordapp structural changes: separate flows and contracts/states
  3. Spring server rewrite.

The upgraded code is done and you can see the preview at branch 4.4-update

Setup

Tools

  • JDK 1.8 latest version
  • IntelliJ latest version (2017.1 or newer)
  • git

After installing the required tools, clone or download a zip of this repository, and place it in your desired location.

IntelliJ setup

  • From the main menu, click open (not import!) then navigate to where you placed this repository.
  • Click File->Project Structure, and set the Project SDK to be the JDK you downloaded (by clicking new and nagivating to where the JDK was installed). Click Okay.
  • Next, click import on the Import Gradle Project popup, leaving all options as they are.
  • If you do not see the popup: Navigate back to Project Structure->Modules, clicking the + -> Import button, navigate to and select the repository folder, select Gradle from the next menu, and finally click Okay, again leaving all options as they are.

Instructions

Once you are all set up, you can start expanding on the class templates. This project follows a test-based development style - the unit tests for each class contain all the information you will need to complete this CorDapp.

All the tests are commented out by default - to complete this training, you will uncomment them one at a time, building up the CorDapp until it passes everything.

You will begin by opening IOUState and IOUStateTests in your language of choice and uncommenting the first test. Then, use the TODO and hints to modify IOUState to pass the test.

In order to issue IOU's using Corda - You will first fix IOUState, then IOUContract, and lastly IOUIssueFlow. Then you can move on to more challenging exercises specified in Transfer and Settle testing files.

Running the tests

  • Kotlin: Select Kotlin - Unit tests from the dropdown run configuration menu, and click the green play button.
  • Java: Select Java - Unit tests from the dropdown run configuration menu, and click the green play button.
  • Individual tests can be run by clicking the green arrow in the line number column next to each test.
  • When running flow tests you must add the following to your run / debug configuration in the VM options field. This enables us to use
  • Quasar - a library that provides high-performance, lightweight threads.
  • "-javaagent: /PATH_TO_FILE_FROM_ROOT_DIR/quasar.jar"

Template Files

Kotlin

State:

  • Template: kotlin-source/src/test/kotlin/net/corda/training/state/IOUState.kt
  • Tests: kotlin-source/src/main/kotlin/net/corda/training/state/IOUStateTests.kt

Contract:

  • Template: kotlin-source/src/main/kotlin/net/corda/training/contract/IOUContract.kt
  • Issue Tests: kotlin-source/src/test/kotlin/net/corda/training/contract/IOUIssueTests.kt
  • Transfer Tests: kotlin-source/src/test/kotlin/net/corda/training/contract/IOUTransferTests.kt
  • Settle Tests: kotlin-source/src/test/kotlin/net/corda/training/contract/IOUSettleTests.kt

Flow:

  • Issue flow template: kotlin-source/src/main/kotlin/net/corda/training/flow/IOUIssueFlow.kt
  • Issue flow tests: kotlin-source/src/test/kotlin/net/corda/training/flow/IOUIssueFlowTests.kt
  • Transfer flow template kotlin-source/src/main/kotlin/net/corda/training/flow/IOUTransferFlow.kt
  • Transfer flow tests: kotlin-source/src/test/kotlin/net/corda/training/flow/IOUTransferFlowTests.kt
  • Settle flow template kotlin-source/src/main/kotlin/net/corda/training/flow/IOUSettleFlow.kt
  • Settle flow tests: kotlin-source/src/test/kotlin/net/corda/training/flow/IOUSettleFlowTests.kt

The code in the following files was already added for you:

  • kotlin-source/src/main/kotlin/net/corda/training/plugin/IOUPlugin.kt
  • kotlin-source/src/test/kotlin/net/corda/training/Main.kt
  • kotling-source/src/main/kotlin/net/corda/training/plugin/IOUPlugin.kt
  • kotling-source/src/main/java/kotlin/corda/training/flow/SelfIssueCashFlow.kt

Java

State:

  • Template: java-source/src/main/java/net/corda/training/state/IOUState.java
  • Tests: java-source/src/test/java/net/corda/training/state/IOUStateTests.java

Contract:

  • Template: java-source/src/main/java/net/corda/training/contract/IOUContract.java
  • Issue Tests: java-source/src/test/java/net/corda/training/contract/IOUIssueTests.java
  • Transfer Tests: java-source/src/test/java/net/corda/training/contract/IOUIssueTests.java
  • Settle Tests: java-source/src/test/java/net/corda/training/contract/IOUIssueTests.java

Flow:

  • Issue template: java-source/src/main/java/net/corda/training/flow/IOUIssueFlow.java
  • Issue tests: java-source/src/test/java/net/corda/training/flow/IOUIssueFlowTests.java
  • Transfer template: java-source/src/main/java/net/corda/training/flow/IOUTransferFlow.java
  • Transfer tests: java-source/src/test/java/net/corda/training/flow/IOUTransferFlowTests.java
  • Settle template: java-source/src/main/java/net/corda/training/flow/IOUSettleFlow.java
  • Settle tests: java-source/src/test/java/net/corda/training/flow/IOUSettleFlowTests.java

The code in the following files was already added for you:

  • java-source/src/main/java/net/corda/training/plugin/IOUPlugin.java
  • java-source/src/test/java/net/corda/training/NodeDriver.java
  • java-source/src/main/java/net/corda/training/plugin/IOUPlugin.java
  • java-source/src/main/java/net/corda/training/flow/SelfIssueCashFlow.java

Running the CorDapp

Once your application passes all tests in IOUStateTests, IOUIssueTests, and IOUIssueFlowTests, you can run the application and interact with it via a web browser. To run the finished application, you have two choices for each language: from the terminal, and from IntelliJ.

Kotlin

  • Terminal: Navigate to the root project folder and run ./gradlew kotlin-source:deployNodes, followed by ./kotlin-source/build/node/runnodes
  • IntelliJ: With the project open, select Kotlin - Node driver from the dropdown run configuration menu, and click the green play button.

Java

  • Terminal: Navigate to the root project folder and run ./gradlew java-source:deployNodes, followed by ./java-source/build/node/runnodes
  • IntelliJ: With the project open, select Java - NodeDriver from the dropdown run configuration menu, and click the green play button.

Interacting with the CorDapp

Once all the three nodes have started up (look for Webserver started up in XXX sec in the terminal or IntelliJ ), you can interact with the app via a web browser.

  • From a Node Driver configuration, look for Starting webserver on address localhost:100XX for the addresses.

  • From the terminal: Node A: localhost:10009, Node B: localhost:10012, Node C: localhost:10015.

To access the front-end gui for each node, navigate to localhost:XXXX/web/iou/

Troubleshooting:

When running the flow tests, if you get a Quasar instrumention error then add:

-ea -javaagent:lib/quasar.jar

to the VM args property in the default run configuration for JUnit in IntelliJ.

Solutions are available here.

corda-training-template's People

Contributors

abhipatel avatar adagys avatar agoldvarg avatar amoothart avatar anoop-v-mathew avatar clintonio avatar davidleeuk avatar exfalso avatar gatsinski avatar ischasny avatar jamiels avatar mikehearn avatar peterli-r3 avatar rick-r3 avatar rogersanick avatar shamsasari avatar sphar-io avatar tubibuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

corda-training-template's Issues

DummyState shall be imported from net.corda.testing.contracts package

// tx.input(IOUContract.IOU_CONTRACT_ID, new DummyState());

The test case expects to create a DummyState, but it's not imported into the test file. It can be imported to the file to let beginners focus on solving and understanding corda instead of solving dependency/import issues.

Solution "import net.corda.testing.contracts.DummyState;" shall be added to IOUIssueTests.java

Reg build issue

I am trying to set up corda-training-template on my PC. It is a Ubuntu 18.04 system with 16GB RAM.

JDK is set to JAVA 1.8.0.242

If the downloaded code is used as it is for build, then following error is coming

ERROR: Unable to load class 'com.intellij.util.ThrowableConsumer'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

In case following change is done:

distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip,

then after the download of corda-webserver-4.0 jar, Build hangs and I need to restart the PC.

Can you please confirm what could I be missing?

Unable to run test case#1 with JDK11.0.1

Hi Team,
I am now trying to run first IOUState Test from IntelliJ IDEA.
I've configured jdk11.0.1 for this in project structure.
When i am trying to execute first assignment . Its not able to identify the JDK version on my system.
Could you please look at it.

Could not determine Java version using executable C:\Program Files\Java\jdk-11.0.1\bin\java.exe.

The problem is... Its unable to implement the interface "ContractState" .
So, when i am trying to run the test again after declaring amount variable "val amount : Amount" ..
Its unable to identify the Amount and currency keywords and throwing below error,

e: E:\BlockChain\Corda\corda-training-template\kotlin-source\src\main\kotlin\net\corda\training\state\IOUState.kt: (12, 34): Unresolved reference: Amount
e: E:\BlockChain\Corda\corda-training-template\kotlin-source\src\main\kotlin\net\corda\training\state\IOUState.kt: (12, 41): Unresolved reference: currency
:kotlin-source:compileKotlin FAILED

FAILURE: Build failed with an exception.

PS:Meanwhile , I am trying to configure JDK8 and will provide my observations.

Postman collection does not match configuration and code

The port numbers I get when running runnodes on macOS are different from those stored in the Postman collection. When running the script, I seem to get the ParticipantA webserver on 10009, ParticipantB on 10012 and ParticipantC on 10015. On the other hand, in Postman I see that it expects Node A to be on 10007, Node B on 10010 and Node C on 10013.

Also, the ParticipantC name is different in the Postman collection (O=ParticipantC,L=New York,C=US) versus the node configuration (O=ParticipantC,L=Paris,C=FR).

IOUSettleTests.kt

It looks like there is a bug with the solution as I am trying to run the first test of IOUSettleTests.kt it gives me error.

I got it working by changing the string message in IOUSettleTests.kt

in line 61 this.failsWith("Contact Verification Failed");

by this.failsWith("Contract verification failed")

Noticed it was different in the Corda-training-solution repo.

java.lang.AssertionError: Expected exception containing 'Contact Verification Failed' but raised exception was 'net.corda.core.contracts.TransactionVerificationException$ContractRejection: Contract verification failed: Required net.corda.training.contract.IOUContract.Commands command, contract: net.corda.training.contract.IOUContract, transaction: 44A4FD321412407AB9F7C2F6B1AAD494284F0CF140A7FEC8F58AF7FB09FAF65D'

Unable to resolve net.corda:corda-core:4.0-SNAPSHOT

If you clone the repo and follow the instructions, there are some error like this after opening in Intelli J:

Warning:<i><b>root project 'corda-supply-chain-poc': Unable to resolve additional project configuration.</b>
Details: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':kotlin-source:compile'.
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve net.corda:corda-core:4.0-SNAPSHOT.
Required by:
    project :kotlin-source
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve net.corda:corda-core:4.0-SNAPSHOT.
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases/net/corda/corda-core/4.0-SNAPSHOT/corda-core-4.0-SNAPSHOT.pom'.
Caused by: org.gradle.internal.resource.transport.http.HttpErrorStatusCodeException: Could not GET 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases/net/corda/corda-core/4.0-SNAPSHOT/corda-core-4.0-SNAPSHOT.pom'. Received status code 409 from server: Conflict</i>

Looking into the maven repository, 4.0-SNAPSHOT is not longer there

At the time of writing this, the most recent was: 4.0-RC02

I'm also sending a PR fixing this

Part of IOUApi should be left unimplemented in sync with training materials

In Module 10 of https://github.com/corda/corda-training-materials ,
the trainee or the reader is requested to implement getIOUs() and issueIOU() for practice,
however they are already implemented or the whole solutions are just commented out in corda-training-template.

For the training materials to be effective, we need modifications either to the code or to the document, such that the trainee can implement by his/her own.

Invalid check of IOUState on full settlement flow

val signedTransactionFlow = object : SignTransactionFlow(flowSession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
val outputStates = stx.tx.outputs.map { it.data::class.java.name }.toList()
"There must be an IOU transaction." using (outputStates.contains(IOUState::class.java.name))

In the case of full settlement, the transaction must not contain an IOUState in output, therefore the code above produces an error.

The check should be removed as in corda-training-solutions, or modified such that the check is made only when in a partial settlement.

BTW I don't have much expertise on Corda so not sure but, I doubt that that check is really required here, because we have already similar checks in IOUContract.

On macOS, runnodes requires special OS permissions

On macOS 10.14.4, executing the runnodes triggers a permission prompt to allow the executing program (Terminal or another terminal emulator such as iTerm2) to "control your computer" and then to "control Terminal".

Cannot Issue an IOU on Corda-Training-Template Java-Src

The IOUIssueFlow takes a parameter of IOUState state. As described in creating-an-instance-of-a-class, we can provide the state object to the flow via the crash shell as (also tried without the dollar sign):

flow start IOUIssueFlow$InitiatorFlow state: { amount: $10, lender: "O=ParticipantB, L=New York, C=GB", borrower: "O=ParticipantC, L=Paris, C=FR" }

This statement works with the Kotlin version of the corda-training-template but throws the following error in the Java version:

No matching constructor found:
- [net.corda.training.state.IOUState]: Could not parse as a command: Cannot construct instance of `net.corda.training.state.IOUState` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: UNKNOWN; line: -1, column: -1]

Although I am not using the default constructor, the default constructor should still be called by this():

@ConstructorForDeserialization
    public IOUState(Amount<Currency> amount, Party lender, Party borrower, UniqueIdentifier linearId){
        this.amount = amount;
        this.lender = lender;
        this.borrower = borrower;
        this.linearId = linearId;
    }

    public IOUState(Amount<Currency> amount, Party lender, Party borrower) {
        this(amount, lender, borrower, new UniqueIdentifier());
    }

What is the proper syntax to issue an IOU state in the corda-training-template?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.