2

Im getting the following error when trying to run my js test file using truffle:

Error: VM Exception while executing eth_call: invalid opcode

The js test file is the following:

var DebitService = artifacts.require("./DebitService.sol");

contract('DebitService', function (accounts) {
    it("Should execute newDebitObject method from Debit Service.", function () {
        return DebitService.deployed().then(function (instance) {
            return instance.newDebitObject.call("0x4d9139268c5a22aa17aa04219ffee71d110b2ec8", 1, "TestTokenFromDebitService", 10);
        }).then(function (success) {
            assert.equal(success.valueOf(), true, "Error executing newDebitObject method from Debit Service. Error: ");
        });
    });
});

And the contract function being called abd the modifier are the following:

modifier onlyOwner
    {
        require(msg.sender == owner);
        _;
    }

function newDebitObject(address _contentCreator, uint _amountInWei, string _name, uint _debitFrequency) onlyOwner returns (bool success)    
{
        if (debitObjectID[_contentCreator] != 0) return false;
        return true;
}

When I remove the only owner clause from the function, it seems to run the test correctly. However it gives the mentioned error when I try to use the onlyOwner clause on the function. Am I doing something wrong ? Can someone help me with this issue ?

Thanks.

  • Are you using TestRPC? Does the same error happen with Geth? – Linmao Song Nov 17 '17 at 10:54
0

Ok, I think I know the issue here. The Contract is deployed by your deployment script, possibly in Node or Javascript, but you call this contract from another contract, whos address is different, hence in the assert, it fails because it is not the owner. I have the same issue using zeppelin ownerable myself, and narrowed it down to this problem. A possible option is to initialise owner in your constructor with the creator, and deploy this contract from the caller contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.