Test network reference
Web3j Corda provides a DSL that allows you to automatically generate and configure a set of nodes for testing
(in a way, is quite similar to a CordForm Gradle task).
Here is an example of a Corda network that creates three nodes and start them on Docker containers:
val myNetwork = network {
directory = File("<path-to-corDapp>")
nodes {
notary {
name = "O=Notary, L=London, C=GB"
validating = true
}
party {
name = "O=PartyA, L=London, C=GB"
}
party {
name = "O=PartyB, L=New York, C=US"
}
}
}
Running this task will create six Docker containers:
- A
Notarynode that offers a validating notary service. PartyAandPartyBnodes that:- Are not offering any services.
- Have an RPC user,
user1by default, that will be used by Braid to log into the node via RPC.
- For each party node, a Braid server exposing their CorDapps using Open API.
- A Network Map to orchestrate the communication between the nodes.
Additionally, all party nodes will include:
- If
directoryis a Gradle project, any CorDapps defined in the project’s source folders and its dependencies. - If
directoryis not a Gradle project, all JAR files containing CorDapps found indirectoryand its sub-directories.
This means that running the network from the generated sample CorDapp from web3j-corda new, for example,
would automatically build and add the sample CorDapp to each node.
Configuration
The configuration values available in the DSL are as follows:
network
Defines a dockerized Corda network.
Optional configuration
-
version: org.web3j.corda.util.OpenApiVersionOpen API version exposed by the nodes (defaults to
3.0.1). -
directory: java.io.FileBase directory where CorDapps are located (defaults to
user.dirsystem property). -
tag: StringNetwork Map Docker image tag (defaults to
v0.5.0)
Read-only configuration
-
image: StringNetwork map Docker image name,
cordite/network-map. -
notaries: Array<CordaNotaryNode>The notary nodes in this network, indexed by position (e.g.
notaries[0]). -
parties: Array<CordaPartyNode>The party nodes in this network, indexed by position (e.g.
parties[0]). -
api: org.web3j.corda.networkmap.NetworkMapApiThe API to interact with the Network Map in this network.
-
service: org.web3j.corda.protocol.CordaServiceThe Corda service to access the Network Map.
notary, party
Inside a network you can declare nodes using the notary and party blocks.
Both have in common the following configuration values:
Required configuration
-
name: StringThe legal identity name of the Corda node. (see myLegalName), e.g.
name = "O=PartyA, L=London, C=GB"
Optional configuration
In addition, each node can specify the following properties:
-
p2pPort: IntCorda P2P port for this node, random by default. (see p2pAddress), e.g.
10006 -
rpcSettings { <config> }Specifies RPC settings for the node. (see rpcSettings), e.g. (ports are randomized by default)
rpcSettings {
port = 10006
adminPort = 10026
}
-
rpcUsers { <config> }Set the RPC users for this node. (see rpcUsers), e.g. (showing default values)
rpcUsers {
user = "user1"
password = "test"
permissions = "ALL"
}
-
autoStart: BooleanSet if this node should start automatically (
trueby default). -
timeOut: java.util.time.DurationTimeout for this Corda node to start (defaults to 5 min).
-
image: StringDocker image name, e.g.
corda-zulu-4.1 -
tag: StringDocker image tag, e.g.
latest
Read-only configuration
-
rpcSettings.address: StringExternal host and port for the RPC server binding, e.g.
example.com:10002 -
rpcSettings.adminAddress: StringExternal host and port for the RPC admin binding, e.g.
example.com:10002 -
p2pAddress: StringAddress/port the node uses for inbound communication from other nodes. (see p2pAddress) e.g.
example.com:10002 -
canonicalName: StringCanonical name to be used as Docker container and host name, e.g.
notary-london-gb.
notary
Defines a Corda notary node.
Optional configuration
-
validating: BooleanDefines this notary as validation (defaults to
false).
party
Defines a Corda party node.
Optional configuration
-
webPort: IntBraid server port for this node, random by default.
Read-only configuration
-
webAddress: StringAddress/port to communicate with Braid server, e.g.
example.com:10002 -
corda: org.web3j.corda.protocol.CordaCorda instance to interact with this node through the Braid server.
Customizing Docker images and tags
All of network, notary and party elements allow you to specify which Docker container image name and tag you want
to use in your network. This table specifies the default values used:
| Marker | Image name | Image tag |
|---|---|---|
network |
cordite/network-map |
v0.5.0 |
notary, party |
corda/corda-zulu-4.1 |
latest |