When I am testing my class with truffle test ./test/testinheritance.js I am getting an error. "Error: VM Exception while processing transaction: revert".
It seems to be error related to the condition that a function setHeir must be called by owner.
I am not sure how to set/get/check owner in test script so that I can test the contract.
Please help me to test this contract via script.
The test script is
The test script is
var DormantAssetFactory = artifacts.require("./DormantAssetFactory.sol");
var DormantAsset = artifacts.require("./DormantAsset.sol");
var dormantAssetAddress = null;
contract('DormantAssetFactory', function (accounts) {
it("Let's call Heir function contract", async function () {
var dormant_asset_factory = await DormantAssetFactory.deployed();
(await dormant_asset_factory.newDormantAsset());
//now get the Address of first contrac /This is not correct way but to show error
dormantAssetAddress =
(await dormant_asset_factory.getDormantAssetAt(0));
var contractInstance = DormantAsset.at(dormantAssetAddress); //get contract at address
//Call function of parent of current contract
// console.log(contractInstance);
var result =
(await contractInstance.setHeir(accounts[1]));
//Just temp conditions
assert.equal(1, 1, "Yes we called setHeir");
});
});
Factory class is DormantAsstFactory
pragma solidity ^0.4.18;
import './DormantAsset.sol';
contract DormantAssetFactory {
// index of created DormantAsset contracts
address[] public dormantAssets;
uint256 public _heartbeatTimeout =1000000;
function getContractCount() public constant returns(uint contractCount)
{
return dormantAssets.length;
}
// deploy a new contract
function newDormantAsset() public returns(address _newDormantAssetContract)
{
DormantAsset c = new DormantAsset(_heartbeatTimeout);
dormantAssets.push(c);
return c;
}
}
This contract created inside factory and it is inherited from this contract https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/ownership/Heritable.sol
Contract Class is
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/ownership/Heritable.sol';
contract DormantAsset is Heritable {
event Sent(address indexed payee, uint256 amount, uint256 balance);
event Received(address indexed payer, uint256 amount, uint256 balance);
function DormantAsset(uint256 _heartbeatTimeout) Heritable(_heartbeatTimeout) public {}
function () public payable {
Received(msg.sender, msg.value, this.balance);
}
function sendTo(address payee, uint256 amount) public onlyOwner {
require(payee != 0 && payee != address(this));
require(amount > 0);
payee.transfer(amount);
Sent(payee, amount, this.balance);
}