function testDate(uint date1,uint date2)
returns (bool)
  require(date1 == date2,'not same date') 
  return date1 == date2;

let res = await TestSol.testDate.call(‘1630972800’,‘1631145600’);

enter image description here

why the res always true?

  • Can you show the whole test? As said by Lauri the contract is fine, so the problem should be in the test.
    – Ismael
    Sep 20 at 5:50

There are a few issues with your code.

  1. You should always use BigNumber when using integers. JavaScript can't handle big numbers. Even if you know the numbers will never be too big, in my opinion it's simply good habit to always use BigNumber.

  2. You are passing strings to your function. ‘1630972800’ is a string, not a number. My guess is that it gets interpret as something completely different (maybe 0) and both numbers are the same in the EVM.

The function works just fine if you try it in Remix, except you're missing one ;.

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.