0

I am probably missing something very obvious but I cannot get the simplest assert statement to work! What am I doing wrong?

My goal is to simply confirm that I am within a start date and end date range using "now".

I cannot even get assert (1==1); to return true!

Please assist!

pragma solidity ^0.4.18;

contract TestAssert {

// Unix timestamp converter used = https://www.unixtimestamp.com/
   uint256 public constant startDate = 1517907600; // 02/06/2018 09:00:00 
   uint256 public constant endDate = 1522659600; // 04/02/2018 09:00:00

//This is the Constructor
  function TestAssert() {

  }

  function assertOneEqualsOne () returns (bool) {
    assert(1 == 1);
  }

  function assertStartDate () constant returns(bool){
    assert(now >= startDate); 
  }

  function assertEndDate () constant returns(bool){
    assert(now <= endDate);
  }

  function returnNow() returns (uint256) {
    return now;
  }

  function () payable {
     // this is the fallback function.
  }

}
0

You need to add a return to your functions.

   function assertOneEqualsOne () external pure returns (bool) {
           assert(1 == 1);
           return true;
   }

If the assert fails it will signal a REVERT and throw an exception in your client code.

  • Thank you VERY much! I knew it was something I was overlooking! I assumed the assert function would return it for me. Lesson learned!!! – wardsback Feb 18 '18 at 14:25

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.