0

If calling a function in a contract would result in a failed require the whole test passes, even if the asserts are incorrect. This is extremely confusing. Look at the simple example below, which actually passes when it should obviously fail.

function testSomeFuncThatRequires() public {
    Assert.equal(uint(1), uint(2), "What the hell");
    require(1 > 2);
  }

If you remove the require(1 > 2), then the test fails as expected. I am using truffle test to run my tests.

What am I doing wrong? Do most people just test their contracts with JavaScript? Seems like the problem is avoidable with JS.

  • 1
    How are you setting the rest of your file up? I tried the above and it did throw as expected with the addition of require(1>2). – Karen S Jan 24 '18 at 17:13
  • Dang... maybe I am using an old version of something? I don’t know what it would be though since I just installed everything for Ethereum for the first time last week. I just did truffle init and went from there. I’ll add a copy of my whole test file ASAP. – shieldstroy Jan 24 '18 at 17:45

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.