2016-10-31 11:30:57 +00:00
.. highlight :: kotlin
.. raw :: html
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/codesets.js"></script>
2018-10-15 09:40:10 +00:00
Running the example CorDapp
===========================
2016-10-31 11:30:57 +00:00
2017-07-21 11:33:31 +00:00
.. contents ::
2017-02-08 10:34:54 +00:00
2018-02-02 17:26:54 +00:00
The example CorDapp allows nodes to agree IOUs with each other, as long as they obey the following contract rules:
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
* The IOU's value is strictly positive
* A node is not trying to issue an IOU to itself
2016-11-29 13:45:58 +00:00
2018-02-02 17:26:54 +00:00
We will deploy and run the CorDapp on four test nodes:
2016-12-12 18:48:35 +00:00
2018-11-19 12:19:05 +00:00
* **Notary** , which runs a notary service
2017-09-22 15:51:32 +00:00
* **PartyA**
* **PartyB**
* **PartyC**
2016-12-12 18:48:35 +00:00
2017-09-22 15:51:32 +00:00
Because data is only propagated on a need-to-know basis, any IOUs agreed between PartyA and PartyB become "shared
facts" between PartyA and PartyB only. PartyC won't be aware of these IOUs.
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Downloading the example CorDapp
-------------------------------
2018-02-02 17:26:54 +00:00
Start by downloading the example CorDapp from GitHub:
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
* Set up your machine by following the :doc: `quickstart guide <getting-set-up>`
2016-11-17 18:31:17 +00:00
2018-11-19 12:19:05 +00:00
* Clone the samples repository from using the following command: `` git clone https://github.com/corda/samples ``
2016-11-17 18:31:17 +00:00
2018-11-19 12:19:05 +00:00
* Change directories to the `` cordapp-example `` folder: `` cd samples/cordapp-example ``
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Opening the example CorDapp in IntelliJ
---------------------------------------
2018-02-02 17:26:54 +00:00
Let's open the example CorDapp in IntelliJ IDEA:
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
* Open IntelliJ
2016-11-17 18:31:17 +00:00
2018-11-19 12:19:05 +00:00
* A splash screen will appear. Click `` open `` , navigate to and select the `` cordapp-example `` folder, and click `` OK ``
2016-11-17 18:31:17 +00:00
2018-06-05 09:57:29 +00:00
* Once the project is open, click `` File `` , then `` Project Structure `` . Under `` Project SDK: `` , set the project SDK by
2018-07-24 16:33:55 +00:00
clicking `` New... `` , clicking `` JDK `` , and navigating to `` C:\Program Files\Java\jdk1.8.0_XXX `` on Windows or `` Library/Java/JavaVirtualMachines/jdk1.8.XXX `` on MacOSX (where `` XXX `` is the
latest minor version number). Click `` Apply `` followed by `` OK ``
2016-11-17 18:31:17 +00:00
2018-06-05 09:57:29 +00:00
* Again under `` File `` then `` Project Structure `` , select `` Modules `` . Click `` + `` , then `` Import Module `` , then select
the `` cordapp-example `` folder and click `` Open `` . Choose to `` Import module from external model `` , select
`` Gradle `` , click `` Next `` then `` Finish `` (leaving the defaults) and `` OK ``
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
* Gradle will now download all the project dependencies and perform some indexing. This usually takes a minute or so
2017-09-22 15:51:32 +00:00
2017-07-21 11:33:31 +00:00
Project structure
2018-02-02 17:26:54 +00:00
~~~~~~~~~~~~~~~~~
The example CorDapp has the following structure:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
.. sourcecode :: none
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
.
2019-02-13 07:37:27 +00:00
├── LICENCE
├── README.md
├── TRADEMARK
├── build.gradle
2019-02-01 15:15:51 +00:00
├── clients
2019-02-13 07:37:27 +00:00
│ ├── build.gradle
2019-02-01 15:15:51 +00:00
│ └── src
│ └── main
2019-02-13 07:37:27 +00:00
│ ├── kotlin
│ │ └── com
│ │ └── example
│ │ └── server
│ │ ├── MainController.kt
│ │ ├── NodeRPCConnection.kt
│ │ └── Server.kt
│ └── resources
│ ├── application.properties
│ └── public
│ ├── index.html
│ └── js
2019-02-01 15:15:51 +00:00
│ └── angular-module.js
2017-07-21 11:33:31 +00:00
├── config
│ ├── dev
│ │ └── log4j2.xml
│ └── test
│ └── log4j2.xml
2019-02-13 07:37:27 +00:00
├── contracts-java
│ ├── build.gradle
│ └── src
│ └── main
│ └── java
│ └── com
│ └── example
│ ├── contract
│ │ └── IOUContract.java
│ ├── schema
│ │ ├── IOUSchema.java
│ │ └── IOUSchemaV1.java
│ └── state
│ └── IOUState.java
├── contracts-kotlin
│ ├── build.gradle
│ └── src
│ └── main
│ └── kotlin
│ └── com
│ └── example
│ ├── contract
│ │ └── IOUContract.kt
│ ├── schema
│ │ └── IOUSchema.kt
│ └── state
│ └── IOUState.kt
├── cordapp-example.iml
2017-07-21 11:33:31 +00:00
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
2019-02-13 07:37:27 +00:00
├── gradle.properties
├── gradlew
├── gradlew.bat
├── lib
│ ├── README.txt
│ └── quasar.jar
├── settings.gradle
├── workflows-java
2017-07-21 11:33:31 +00:00
│ ├── build.gradle
│ └── src
2018-11-19 12:19:05 +00:00
│ ├── integrationTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── DriverBasedTests.java
2017-07-21 11:33:31 +00:00
│ ├── main
2019-02-13 07:37:27 +00:00
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── flow
│ │ └── ExampleFlow.java
2017-07-21 11:33:31 +00:00
│ └── test
2018-11-19 12:19:05 +00:00
│ └── java
2017-07-21 11:33:31 +00:00
│ └── com
│ └── example
2018-11-19 12:19:05 +00:00
│ ├── NodeDriver.java
2017-07-21 11:33:31 +00:00
│ ├── contract
2018-11-19 12:19:05 +00:00
│ │ └── IOUContractTests.java
2017-07-21 11:33:31 +00:00
│ └── flow
2018-11-19 12:19:05 +00:00
│ └── IOUFlowTests.java
2019-02-13 07:37:27 +00:00
└── workflows-kotlin
├── build.gradle
└── src
├── integrationTest
│ └── kotlin
│ └── com
│ └── example
│ └── DriverBasedTests.kt
├── main
│ └── kotlin
│ └── com
│ └── example
│ └── flow
│ └── ExampleFlow.kt
└── test
└── kotlin
└── com
└── example
├── NodeDriver.kt
├── contract
│ └── IOUContractTests.kt
└── flow
└── IOUFlowTests.kt
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
The key files and directories are as follows:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
* The **root directory** contains some gradle files, a README and a LICENSE
2018-12-14 16:34:19 +00:00
* **config** contains log4j2 configs
2017-07-21 11:33:31 +00:00
* **gradle** contains the gradle wrapper, which allows the use of Gradle without installing it yourself and worrying
about which version is required
2017-09-22 15:51:32 +00:00
* **lib** contains the Quasar jar which rewrites our CorDapp's flows to be checkpointable
2019-02-01 15:15:51 +00:00
* **clients** contains the source code for spring boot integration
2019-02-13 07:37:27 +00:00
* **contracts-java** and **workflows-java** contain the source code for the example CorDapp written in Java
* **contracts-kotlin** and **workflows-kotlin** contain the same source code, but written in Kotlin. CorDapps can be developed in either Java and Kotlin
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Running the example CorDapp
---------------------------
There are two ways to run the example CorDapp:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
* Via the terminal
* Via IntelliJ
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
Both approaches will create a set of test nodes, install the CorDapp on these nodes, and then run the nodes. You can
read more about how we generate nodes :doc: `here <generating-a-node>` .
2017-09-22 15:51:32 +00:00
2018-02-02 17:26:54 +00:00
Running the example CorDapp from the terminal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-09-22 15:51:32 +00:00
Building the example CorDapp
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Open a terminal window in the `` cordapp-example `` directory
2016-11-17 18:31:17 +00:00
2018-08-01 16:55:00 +00:00
* Run the `` deployNodes `` Gradle task to build four nodes with our CorDapp already installed on them:
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
* Unix/Mac OSX: `` ./gradlew deployNodes ``
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
* Windows: `` gradlew.bat deployNodes ``
2016-12-12 18:48:35 +00:00
2017-07-21 11:33:31 +00:00
.. note :: CorDapps can be written in any language targeting the JVM. In our case, we've provided the example source in
2019-02-13 07:37:27 +00:00
both Kotlin and Java. Since both sets of source files are functionally identical, we will refer to the Kotlin version
throughout the documentation.
2016-11-17 18:31:17 +00:00
2019-02-13 07:37:27 +00:00
* After the build finishes, you will see the following output in the `` workflows-kotlin/build/nodes `` folder:
2018-08-01 16:55:00 +00:00
* A folder for each generated node
* A `` runnodes `` shell script for running all the nodes simultaneously on osX
* A `` runnodes.bat `` batch file for running all the nodes simultaneously on Windows
* Each node in the `` nodes `` folder will have the following structure:
.. sourcecode :: none
. nodeName
├── additional-node-infos //
├── certificates
├── corda.jar // The Corda node runtime
├── cordapps // The node's CorDapps
2019-03-25 18:23:17 +00:00
│ ├── corda-finance-contracts-|corda_version|.jar
│ ├── corda-finance-workflows-|corda_version|.jar
2018-08-01 16:55:00 +00:00
│ └── cordapp-example-0.1.jar
├── drivers
├── logs
├── network-parameters
├── node.conf // The node's configuration file
├── nodeInfo-<HASH> // The hash will be different each time you generate a node
└── persistence.mv.db // The node's database
.. note :: `` deployNodes `` is a utility task to create an entirely new set of nodes for testing your CorDapp. In production,
you would instead create a single node as described in :doc: `generating-a-node` and build your CorDapp JARs as described
in :doc: `cordapp-build-systems` .
2017-09-22 15:51:32 +00:00
Running the example CorDapp
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2019-02-13 07:37:27 +00:00
Start the nodes by running the following command from the root of the `` cordapp-example `` folder:
2019-04-04 13:31:38 +00:00
* Unix/Mac OSX: `` workflows-kotlin/build/nodes/runnodes ``
2019-02-13 07:37:27 +00:00
* Windows: `` call workflows-kotlin\build\nodes\runnodes.bat ``
2016-11-17 18:31:17 +00:00
2019-02-19 10:32:41 +00:00
Each Spring Boot server needs to be started in its own terminal/command prompt, replace X with A, B and C:
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
* Unix/Mac OSX: `` ./gradlew runPartyXServer ``
* Windows: `` gradlew.bat runPartyXServer ``
2019-02-19 10:32:41 +00:00
Look for the Started ServerKt in X seconds message, don't rely on the % indicator.
2018-02-08 16:50:28 +00:00
.. warning :: On Unix/Mac OSX, do not click/change focus until all seven additional terminal windows have opened, or some
2019-04-04 13:31:38 +00:00
nodes may fail to start. You can run `` workflows-kotlin/build/nodes/runnodes --headless `` to prevent each server from opening in a new terminal window. To interact with the nodes will need to use ssh, see :doc: `shell` .
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
For each node, the `` runnodes `` script creates a node tab/window:
2016-11-17 18:31:17 +00:00
.. sourcecode :: none
2018-03-02 17:48:45 +00:00
______ __
/ ____/ _________/ /___ _
/ / __ / ___/ __ / __ `/ Top tip: never say "oops", instead
/ /___ /_/ / / / /_/ / /_/ / always say "Ah, Interesting!"
\____/ /_/ \__,_/\__,_/
2016-11-17 18:31:17 +00:00
2019-03-25 12:20:26 +00:00
--- Corda Open Source corda-|corda_version| (4157c25) -----------------------------------------------
2016-11-17 18:31:17 +00:00
2019-02-13 07:37:27 +00:00
Logs can be found in : /Users/joeldudley/Desktop/cordapp-example/workflows-kotlin/build/nodes/PartyA/logs
2018-03-02 17:48:45 +00:00
Database connection url is : jdbc:h2:tcp://localhost:59472/node
2018-12-13 14:56:53 +00:00
Incoming connection address : localhost:10005
Listening on port : 10005
2019-03-25 12:20:26 +00:00
Loaded CorDapps : corda-finance-corda-|corda_version|, cordapp-example-0.1, corda-core-corda-|corda_version|
2018-03-02 17:48:45 +00:00
Node for "PartyA" started up and registered in 38.59 sec
2016-11-17 18:31:17 +00:00
2018-03-02 17:48:45 +00:00
Welcome to the Corda interactive shell.
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.
2017-07-21 11:33:31 +00:00
2019-02-01 15:15:51 +00:00
Fri Mar 02 17:34:02 GMT 2018>>>
2017-07-21 11:33:31 +00:00
2018-02-02 17:26:54 +00:00
It usually takes around 60 seconds for the nodes to finish starting up. To ensure that all the nodes are running, you
can query the 'status' end-point located at `` http://localhost:[port]/api/status `` (e.g.
2019-02-01 15:15:51 +00:00
`` http://localhost:50005/api/status `` for `` PartyA `` ).
2017-07-21 11:33:31 +00:00
2018-02-02 17:26:54 +00:00
Running the example CorDapp from IntelliJ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-09-22 15:51:32 +00:00
* Select the `` Run Example CorDapp - Kotlin `` run configuration from the drop-down menu at the top right-hand side of
the IDE
2016-10-31 11:30:57 +00:00
2017-09-22 15:51:32 +00:00
* Click the green arrow to start the nodes:
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
.. image :: resources/run-config-drop-down.png
:width: 400
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
* To stop the nodes, press the red square button at the top right-hand side of the IDE, next to the run configurations
2017-07-21 11:33:31 +00:00
2017-02-08 10:34:54 +00:00
Interacting with the example CorDapp
------------------------------------
2016-11-17 18:31:17 +00:00
2016-12-12 18:48:35 +00:00
Via HTTP
2017-01-06 11:05:37 +00:00
~~~~~~~~
2019-02-01 15:15:51 +00:00
The Spring Boot servers run locally on the following ports:
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
* PartyA: `` localhost:50005 ``
* PartyB: `` localhost:50006 ``
* PartyC: `` localhost:50007 ``
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
These ports are defined in `` clients/build.gradle `` .
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
Each Spring Boot server exposes the following endpoints:
2016-11-17 18:31:17 +00:00
2016-11-29 13:45:58 +00:00
* `` /api/example/me ``
* `` /api/example/peers ``
2017-02-08 10:34:54 +00:00
* `` /api/example/ious ``
2017-09-25 16:01:14 +00:00
* `` /api/example/create-iou `` with parameters `` iouValue `` and `` partyName `` which is CN name of a node
2016-11-17 18:31:17 +00:00
2019-02-01 16:14:16 +00:00
There is also a web front-end served from the home web page e.g. `` localhost:50005 `` .
2016-11-17 18:31:17 +00:00
2019-02-01 15:51:44 +00:00
.. warning :: The content is only available for demonstration purposes and does not implement
2018-02-02 17:26:54 +00:00
anti-XSS, anti-XSRF or other security techniques. Do not use this code in production.
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
Creating an IOU via the endpoint
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2018-08-13 15:21:16 +00:00
An IOU can be created by sending a PUT request to the `` /api/example/create-iou `` endpoint directly, or by using the
2019-02-01 15:51:44 +00:00
the web form served from the home directory.
2018-02-02 17:26:54 +00:00
2017-09-22 15:51:32 +00:00
To create an IOU between PartyA and PartyB, run the following command from the command line:
2016-11-17 18:31:17 +00:00
.. sourcecode :: bash
2019-02-01 15:15:51 +00:00
curl -X PUT 'http://localhost:50005/api/example/create-iou?iouValue=1&partyName=O=PartyB,L=New%20York,C=US'
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
Note that both PartyA's port number (`` 50005 `` ) and PartyB are referenced in the PUT request path. This command
2017-09-22 15:51:32 +00:00
instructs PartyA to agree an IOU with PartyB. Once the process is complete, both nodes will have a signed, notarised
copy of the IOU. PartyC will not.
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
Submitting an IOU via the web front-end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2019-02-01 15:51:44 +00:00
To create an IOU between PartyA and PartyB, navigate to the home directory for the node, click the "create IOU" button at the top-left
2017-09-22 15:51:32 +00:00
of the page, and enter the IOU details into the web-form. The IOU must have a positive value. For example:
2016-11-17 18:31:17 +00:00
.. sourcecode :: none
2018-03-06 14:22:38 +00:00
Counterparty: Select from list
2017-07-21 11:33:31 +00:00
Value (Int): 5
2017-02-08 10:34:54 +00:00
2017-07-21 11:33:31 +00:00
And click submit. Upon clicking submit, the modal dialogue will close, and the nodes will agree the IOU.
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
Checking the output
^^^^^^^^^^^^^^^^^^^
2018-03-02 11:20:29 +00:00
Assuming all went well, you can view the newly-created IOU by accessing the vault of PartyA or PartyB:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
*Via the HTTP API:*
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
* PartyA's vault: Navigate to http://localhost:50005/api/example/ious
* PartyB's vault: Navigate to http://localhost:50006/api/example/ious
2016-11-17 18:31:17 +00:00
2019-02-01 15:51:44 +00:00
*Via home page:*
2016-11-17 18:31:17 +00:00
2019-02-01 15:51:44 +00:00
* PartyA: Navigate to http://localhost:50005 and hit the "refresh" button
* PartyB: Navigate to http://localhost:50006 and hit the "refresh" button
2016-11-17 18:31:17 +00:00
2019-02-01 15:15:51 +00:00
The vault and web front-end of PartyC (at `` localhost:50007 `` ) will not display any IOUs. This is because PartyC was
2017-09-22 15:51:32 +00:00
not involved in this transaction.
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Via the interactive shell (terminal only)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-09-22 15:51:32 +00:00
Nodes started via the terminal will display an interactive shell:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
.. sourcecode :: none
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Welcome to the Corda interactive shell.
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
Fri Jul 07 16:36:29 BST 2017>>>
2016-11-17 18:31:17 +00:00
2017-09-22 15:51:32 +00:00
Type `` flow list `` in the shell to see a list of the flows that your node can run. In our case, this will return the
following list:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
.. sourcecode :: none
2016-11-17 18:31:17 +00:00
2019-02-01 15:51:44 +00:00
com.example.flow.ExampleFlow$Initiator
net.corda.core.flows.ContractUpgradeFlow$Authorise
net.corda.core.flows.ContractUpgradeFlow$Deauthorise
net.corda.core.flows.ContractUpgradeFlow$Initiate
net.corda.finance.flows.CashExitFlow
net.corda.finance.flows.CashIssueAndPaymentFlow
net.corda.finance.flows.CashIssueFlow
net.corda.finance.flows.CashPaymentFlow
net.corda.finance.internal.CashConfigDataFlow
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
Creating an IOU via the interactive shell
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2017-09-22 15:51:32 +00:00
We can create a new IOU using the `` ExampleFlow$Initiator `` flow. For example, from the interactive shell of PartyA,
you can agree an IOU of 50 with PartyB by running
`` flow start ExampleFlow$Initiator iouValue: 50, otherParty: "O=PartyB,L=New York,C=US" `` .
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
This will print out the following progress steps:
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
.. sourcecode :: none
2016-11-17 18:31:17 +00:00
2017-07-21 11:33:31 +00:00
✅ Generating transaction based on new IOU.
✅ Verifying contract constraints.
✅ Signing transaction with our private key.
✅ Gathering the counterparty's signature.
2018-03-06 14:22:38 +00:00
✅ Collecting signatures from counterparties.
2017-07-21 11:33:31 +00:00
✅ Verifying collected signatures.
✅ Obtaining notary signature and recording transaction.
✅ Requesting signature by notary service
Requesting signature by Notary service
Validating response from Notary service
✅ Broadcasting transaction to participants
✅ Done
2016-11-17 18:31:17 +00:00
2018-02-02 17:26:54 +00:00
Checking the output
^^^^^^^^^^^^^^^^^^^
2017-07-21 11:33:31 +00:00
We can also issue RPC operations to the node via the interactive shell. Type `` run `` to see the full list of available
operations.
2016-10-31 11:30:57 +00:00
2018-02-02 17:26:54 +00:00
You can see the newly-created IOU by running `` run vaultQuery contractStateType: com.example.state.IOUState `` .
As before, the interactive shell of PartyC will not display any IOUs.
2017-07-21 11:33:31 +00:00
Via the h2 web console
~~~~~~~~~~~~~~~~~~~~~~
You can connect directly to your node's database to see its stored states, transactions and attachments. To do so,
please follow the instructions in :doc: `node-database` .
2016-10-31 11:30:57 +00:00
2018-02-02 17:26:54 +00:00
Running nodes across machines
2017-07-21 11:33:31 +00:00
-----------------------------
2018-07-04 09:22:39 +00:00
The nodes can be configured to communicate as a network even when distributed across several machines:
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
* Deploy the nodes as usual:
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
* Unix/Mac OSX: `` ./gradlew deployNodes ``
* Windows: `` gradlew.bat deployNodes ``
2019-02-13 07:37:27 +00:00
* Navigate to the build folder (`` workflows-kotlin/build/nodes `` )
2018-07-04 09:22:39 +00:00
* For each node, open its `` node.conf `` file and change `` localhost `` in its `` p2pAddress `` to the IP address of the machine
2019-02-01 15:57:31 +00:00
where the node will be run (e.g. `` p2pAddress="10.18.0.166:10007" `` )
2018-07-04 09:22:39 +00:00
* These changes require new node-info files to be distributed amongst the nodes. Use the network bootstrapper tool
(see :doc: `network-bootstrapper` ) to update the files and have them distributed locally:
2019-02-13 07:37:27 +00:00
`` java -jar network-bootstrapper.jar workflows-kotlin/build/nodes ``
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
* Move the node folders to their individual machines (e.g. using a USB key). It is important that none of the
nodes - including the notary - end up on more than one machine. Each computer should also have a copy of `` runnodes ``
and `` runnodes.bat `` .
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
For example, you may end up with the following layout:
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
* Machine 1: `` Notary `` , `` PartyA `` , `` runnodes `` , `` runnodes.bat ``
* Machine 2: `` PartyB `` , `` PartyC `` , `` runnodes `` , `` runnodes.bat ``
2018-03-01 21:24:10 +00:00
2018-07-04 09:22:39 +00:00
* After starting each node, the nodes will be able to see one another and agree IOUs among themselves
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
.. warning :: The bootstrapper must be run **after** the `` node.conf `` files have been modified, but **before** the nodes
are distributed across machines. Otherwise, the nodes will not be able to communicate.
2016-12-12 18:48:35 +00:00
2018-07-04 09:22:39 +00:00
.. note :: If you are using H2 and wish to use the same `` h2port `` value for two or more nodes, you must only assign them that
2018-08-01 16:55:00 +00:00
value after the nodes have been moved to their individual machines. The initial bootstrapping process requires access to
the nodes' databases and if two nodes share the same H2 port, the process will fail.
2018-04-30 10:05:57 +00:00
2018-07-10 14:17:59 +00:00
Testing your CorDapp
--------------------
2016-10-31 15:52:10 +00:00
2018-02-02 17:26:54 +00:00
Corda provides several frameworks for writing unit and integration tests for CorDapps.
2016-10-31 15:52:10 +00:00
2018-02-02 17:26:54 +00:00
Contract tests
2018-07-10 14:17:59 +00:00
~~~~~~~~~~~~~~
2018-02-02 17:26:54 +00:00
You can run the CorDapp's contract tests by running the `` Run Contract Tests - Kotlin `` run configuration.
2016-10-31 15:52:10 +00:00
2018-02-02 17:26:54 +00:00
Flow tests
2018-07-10 14:17:59 +00:00
~~~~~~~~~~
2018-02-02 17:26:54 +00:00
You can run the CorDapp's flow tests by running the `` Run Flow Tests - Kotlin `` run configuration.
2017-07-21 11:33:31 +00:00
2018-02-02 17:26:54 +00:00
Integration tests
2018-07-10 14:17:59 +00:00
~~~~~~~~~~~~~~~~~
2018-02-02 17:26:54 +00:00
You can run the CorDapp's integration tests by running the `` Run Integration Tests - Kotlin `` run configuration.
2016-10-31 15:52:10 +00:00
2019-03-13 16:23:31 +00:00
.. _tutorial_cordapp_running_tests_intellij:
2019-03-12 10:26:17 +00:00
Running tests in IntelliJ
~~~~~~~~~~~~~~~~~~~~~~~~~
We recommend editing your IntelliJ preferences so that you use the Gradle runner - this means that the quasar utils
plugin will make sure that some flags (like `` -javaagent `` - see :ref: `below <tutorial_cordapp_alternative_test_runners>` ) are
set for you.
To switch to using the Gradle runner:
* Navigate to `` Build, Execution, Deployment -> Build Tools -> Gradle -> Runner `` (or search for `runner` )
* Windows: this is in "Settings"
* MacOS: this is in "Preferences"
* Set "Delegate IDE build/run actions to gradle" to true
* Set "Run test using:" to "Gradle Test Runner"
.. _tutorial_cordapp_alternative_test_runners:
If you would prefer to use the built in IntelliJ JUnit test runner, you can add some code to your `` build.gradle `` file and
it will copy your quasar JAR file to the lib directory. You will also need to specify `` -javaagent:lib/quasar.jar ``
and set the run directory to the project root directory for each test.
Add the following to your `` build.gradle `` file - ideally to a `` build.gradle `` that already contains the quasar-utils plugin line:
.. sourcecode :: groovy
apply plugin: 'net.corda.plugins.quasar-utils'
task installQuasar(type: Copy) {
destinationDir rootProject.file("lib")
from(configurations.quasar) {
rename 'quasar-core(.*).jar', 'quasar.jar'
}
}
and then you can run `` gradlew installQuasar `` .
2018-07-10 14:17:59 +00:00
Debugging your CorDapp
----------------------
2017-09-22 15:51:32 +00:00
2018-07-10 14:17:59 +00:00
See :doc: `debugging-a-cordapp` .