I havae two contract Record
and Register
.
Register.sol
looks like:
pragma solidity ^0.4.24;
contract Register {
string private name;
constructor(string entityname) public {
name = entityname;
}
function getName() public view returns (string username) {
return name;
}
}
And in Record.sol
:
pragma solidity ^0.4.24;
import "./Register.sol";
contract Record {
constructor(address ownerAddr, address providerAddr) public {
Register(ownerAddr).getName();
Register(providerAddr).getName();
}
}
FYI, Record
just want to call getName()
method of Register contract in its constructor. In the test file I want to create new Record
using the following code but got this error VM Exception while processing transaction: revert.
beforeEach('create new Register and Record contract', async () => {
providerA = await Register.new("Dr Strange", {from: accounts[0]});
providerB = await Register.new("Maybe", {from: accounts[1]});
record = await Record.new(providerA.address, providerB.addresss);
})
What should I do?
Truffle v4.1.14 (core: 4.1.14)
Solidity v0.4.24 (solc-js)
Ganache v1.2.2
============================ UPDATE ==============================
I think its the problem of the contract iteself, not the test script. Because using Remix, Register
contract can be deployed, but Record
cannot even be deployed.
returns (string username)
toreturns (string)
.returns (string)
. Problem exists.console.log(providerA.address, providerB.addresss)
. Make sure that they are notundefined
. That would explain therevert
exception. On web3.js v1 you should use_address
, notaddress
(though Truffle uses web3.js v0 as far as I'm aware of).0x048964912779d7896841ecb0ab2ac2ca8a022d39 0x568d7256e3aa7789bc039f314eeebba7ff3005a9
and they exist in Ganache as CREATED CONTRACT ADDRESS.getName
function.