Error: Returned error: VM Exception while processing transaction: invalid opcode at Object.run

by neha agarwal   Last Updated July 11, 2019 13:28 PM

ApprovalContract.sol

pragma solidity ^0.5.1;

    contract ApprovalContract{
    address public sender;
    address payable public reciever;
    address public constant approver=0xe05cE3f89b5Ab28d6d2Ac8A503473Cd5A23e616a;

    function deposit (address payable _receiver)external payable{

        require (msg.value > 0);
        sender=msg.sender;
        reciever=_receiver;
    }

    function viewApprover () external pure returns(address) {
        return approver;
    }

    function approve () external payable {

        require (msg.sender==approver);
        reciever.transfer(address(this).balance);
    }
    }

2_deploy_contract.js

const ApprovalContract = artifacts.require("ApprovalContract");

module.exports = function(deployer) {
  deployer.deploy(ApprovalContract);
}

For testing, ApprovalContract.js

const ApprovalContract = artifacts.require('../../lyndacontract/ApprovalContract.sol');

contract('ApprovalContract',function(accounts)){

it('initiates contract',async function(){
  const contract = await ApprovalContract.deployed();
  const approver = await contract.approver.call(); 
  assert.equal(approver,0xe05cE3f89b5Ab28d6d2Ac8A503473Cd5A23e616,"approvers don't match");
})
}

truffle compile,truffle migrate run successfully. When I do truffle test,this error comes-

Error: Error: Error: Returned error: VM Exception while processing transaction: invalid opcode
    at Object.run (/home/neha/.nvm/versions/node/v8.16.0/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
Truffle v5.0.26 (core: 5.0.26)
Node v8.16.0


Related Questions


Updated July 27, 2018 18:28 PM

Updated June 27, 2019 15:28 PM

Updated December 04, 2018 17:28 PM

Updated October 11, 2018 10:28 AM