I'm running the 7nodes example of quorum from truffle and the example functionalities work as expected. However, when I create a public contract to access the state of another public contract, I'm getting a 0
return value even when that is not the case. Strangely, the contract is able to set the state of the callee contract. I have added the details below. Can someone please tell what I'm doing wrong over here?
geth version: 1.7.2-stable
truffle version: v4.1.7
solc-js version: v0.4.23
Public Contract 1:
pragma solidity ^0.4.17;
contract PublicStorage {
uint public storedData;
function PublicStorage(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() constant public returns (uint retVal) {
return storedData;
}
}
Public Contract 2:
pragma solidity ^0.4.17;
import './PublicStorage.sol';
contract PubStorageReader {
uint public storedData;
PublicStorage publicStorage;
function PubStorageReader(uint initVal, address publStorageAddr) public {
storedData = initVal;
publicStorage = PublicStorage(publStorageAddr);
}
function setPublic(uint x) public {
publicStorage.set(x);
}
function getPublic() constant public returns (uint publicRetVal) {
return publicStorage.get();
}
}
Deploy script:
deployer.deploy(PublicStorage, 102)
.then(function() {
return deployer.deploy(PubStorageReader, 202, PublicStorage.address);
});
Invocation:
> PublicStorage.deployed().then(function(instance) { return instance.get(); })
{ [String: '102'] s: 1, e: 2, c: [ 102 ] }
> PubStorageReader.deployed().then(function(instance) { return instance.getPublic(); })
{ [String: '0'] s: 1, e: 0, c: [ 0 ] }
> PubStorageReader.deployed().then(function(instance) { return instance.setPublic(2); })
{ ... }
> PublicStorage.deployed().then(function(instance) { return instance.get(); })
{ [String: '2'] s: 1, e: 0, c: [ 2 ] }
Now running the same code on testrpc reads the state as expected. What is the mistake in this?