Faced a very not clear problem for me. There are two simple contracts:
contract Test1 {
int128 public val;
function getVal() view public returns(int128) {
return val;
}
function setVal( int128 _val ) public {
val = _val;
}
}
contract Test2 {
address public the1;
function setTest1( address _adr ) public {
the1 = _adr;
}
function setVal( int128 _val ) public {
Test1( the1 ).setVal( _val );
}
function getVal() view public returns(int128) {
return Test1( the1 ).getVal();
}
}
The value of field Test1.val you can change as calling function setVal in Test1 contract and calling same function in Test2 (Of course after setting the address of the first contract in the second Test2.setTest1)).
In the Remix and tests (ganache) – everything works as expected. But on a Private Network (implemented via Geth) I have trouble: when I call Test2.setVal – the value is changed; when I call Test2.getVal – does not work. I make calls via web3j
test2.setVal( BigInteger.valueOf(30)).send();
result = test2.getVal().send(); // (1)
In the point (1) there is an exception:
ContractCallException: Emtpy value (0x) returned from contract.
I have no idea what wrong with this. The mechanism of calling function from another contract is quite simple. But I can’t understand what I’m doing wrong.
And I tried to call contract’s functions throw geth-console. In this case there is no error, but simply Test2.getVal () returns 0.
I will be grateful for any ideas!
UPDATE. This is test (I used @Ferit's test)
const TEST_1 = artifacts.require('Test1.sol');
const TEST_2 = artifacts.require('Test2.sol');
contract('Ferit Test1', function (accounts) {
let test1;
let test2;
beforeEach('setup contract for each test case', async () => {
test1 = await TEST_1.at("…");
test2 = await TEST_2.at("…");
})
it('test1', async () => {
await test1.setVal(333);
let result = await test1.getVal();
console.log( "-> test1.getVal=" + result );
assert(result.toNumber(), 333 );
})
it('test2', async () => {
await test2.setVal(444);
let result = await test2.getVal(); // (!!!) return 0
console.log( "-> test2.getVal=" + result );
assert(result.toNumber(), 444);
})
})
TransactionReceipt
returned fromsetVal().send()
? Are you using the generated contract proxy? – Adam KipnissetVal().send()
returned a validTransactionReceipt
.TransactionReceipt r = test2.setVal( BigInteger.valueOf(30)).send();
System.out.println( r.getBlockHash() );
result = test1.getVal().send();
System.out.println( "1) " + result );
result = test2.getVal().send(); // ERROR!
System.out.println( "2) " + result );
Do you mean a proxy-java-class? Yes, I useweb3j
to generate it. For compilation I usetruffle
. – vasiliy