Dates are a bit weird in Solidity. Solidity does have some keywords for working with dates, like now
, or 1 day
, but it does not have a native date type. Instead, dates are represented as integers, using timestamps in seconds.
In our Truffle tests, we need to be able to pass dates to Solidity smart contracts in order to test them. However, when you create a date in Javascript, you get a Javascript object, not a timestamp, and there are no functions to convert a Javascript date object to a timestamp in seconds. How can we work around that?
In this video, you are going to learn how to pass Javascript dates to Solidity smart contracts in your Truffle tests.
SolidityTestingTruffle
Leave a Reply