Using truffle and truffle test I have the below test code:

  function testBuyItem() public {
    uint8 expected = 2;
    bytes32 expectedName = "Item";

    Assert.equal(uint(8), uint(7), "Should fail");

    contract.buy.value(1 ether)(expected);
    var (typeId, name, condition) = contract.getUserItem(1);

    Assert.equal(expectedName, name, "Should be Item");

It doesn't fail, even if I have a failing test ABOVE the contract.buy.value(1 ether)(expected) line. If I comment out the contract.buy... line it fails as expected. The code for buy has a payable modifier than checks the value of msg.value with require.

  • Sometimes truffle can fail to recompile contracts, try deleting build/ directory and recompile everything.
    – Ismael
    Jan 21, 2018 at 7:37


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.