Testing the network

To test that our network is working as expected, we'll run two tests using a contract that comes prepackaged with the Quorum code, simplestorage.sol:

pragma solidity ^0.4.15;

contract simplestorage {
uint public storedData;

function simplestorage(uint initVal) {
storedData = initVal;
}

function set(uint x) {
storedData = x;
}

function get() constant returns (uint retVal) {
return storedData;
}
}

This is a very simple contract that will allow members of the network to read and write a variable on the condition that they have authorization to do so. We'll first deploy the contract publicly, check that all nodes are able to interact with it, and then redeploy the contract in such a way that only two of the nodes are able to interact with it.

It should be noted that the contract is compiled with an older version of the compiler, in this case 0.4.15. This is because there have been issues with using later releases of the Solidity compiler with Quorum (see https://github.com/jpmorganchase/quorum/issues/371.)

To deploy the contract, we can make use of the runscript.sh script, together with the following:

  • public-contract.js
  • private-contract.js

These preprepared files contain references to both the ABI and bytecode required to deploy the contracts using Web3. If we look at the two files, we can see that the ABI and bytecode are identical  we're deploying exactly the same contract. The only difference is how the contract is deployed.

For public-contract.js, we use the following:

var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760}, function(e, contract) { ... }

And for private-contract.js, we use this code:

var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}, function(e, contract) { ... }

In each case, the simple variable is the reference to the newly deployed contract. The initial value passed to the constructor is 42, and the contract is deployed by the first account on node 1. The specific difference is that the private contract is deployed with the privateFor parameter, with a public key being passed as the value. The transaction being used to deploy the contract is therefore private, and intended only for the owner of the specified public key.

We can check which node this public key equates to by checking the keys held by the Constellation Transaction Manager on each node. Upon inspection, we see that this equates to node 7, meaning once the contract is deployed, only nodes 1 (the deployer) and 7 will be able to access and view the data belonging to the contract as shown here:

$ cat examples/7nodes/keys/tm7.pub
ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc=
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset