0

I'm getting the following error during the testing in Truffle:

 Error: Returned error: VM Exception while processing transaction: revert

It simply says "revert" without the contingency message, which tells me that it's not coming from any of the "require" functions I've defined. I've also tried running the test with everything else commented out, except for the "pay()" function, including all the other test, but still didn't work.

testing

it("can pay the payout from the pending credit to the proper beneficiary", async () => {
    // ARRANGE
    let beneficiary = accounts[2];
    let flightAddress = accounts[4];
    let initialBalance;
    let postBalance;
    let eventEmitted = false;
    // ACT
    try {
      initialBalance = await web3.eth.getBalance(beneficiary);
    } catch (e) {
      throw new Error(e);
    }
    await config.flightSuretyData.buy(beneficiary, 100, flightAddress);
    await config.flightSuretyData.creditInsurees(beneficiary);
    await config.flightSuretyData.pay({ from: beneficiary }); // right here!
    await config.flightSuretyData.contract.events.InsurancePayoutPaid(
      function () {
        eventEmitted = true;
      }
    );
    try {
      postBalance = await web3.eth.getBalance(beneficiary);
    } catch (e) {
      throw new Error(e);
    }
    assert.equal(
      postBalance - initialBalance,
      result,
      "The insurance payout failed"
    );
    assert.isTrue(eventEmitted, "The event InsurancePayoutPaid is not emitted");
  });

contract

    function pay() external payable requireIsOperational {
        require(msg.sender != address(0), "Not a valid address");
        require(
            insurance[msg.sender].isValue == true,
            "The caller is not insured"
        );
        require(
            pendingCredit[msg.sender] != 0,
            "The pending credit amount is 0"
        );
        uint256 payout = pendingCredit[msg.sender];
        pendingCredit[msg.sender] = 0;
        msg.sender.transfer(payout);
        // address(uint160(msg.sender)).transfer(payout);
        emit InsurancePayoutPaid(msg.sender, payout);
    }

I thought maybe it had to do with the gas limit so I tried :

await config.flightSuretyData.pay({ from: beneficiary, gasPrice: 0 });

or

await config.flightSuretyData.pay({ from: beneficiary, gas: 0 });

But none worked.

I've tried :

web3.utils.fromWei(postBalance) - web3.utils.fromWei(initialBalance) for the assertion

or

"web3.utils.fromWei(100)" for the argument for the buy() function, but that wasn't it either.

Finally, I've deleted the build, truffle migrate --reset and then tried testing again, but still the same result.

  • 1
    What is requireIsOperational? – goodvibration May 21 at 23:10
  • 1
    Also, you probably want to add require(address(this).balance >= payout, "insufficient amount of ether in the contract"); before msg.sender.transfer(payout);. – goodvibration May 21 at 23:12

Your Answer

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

Browse other questions tagged or ask your own question.