Testing dates in Solidity smart contracts – Part I

Julien Klepatch

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.


Leave a Reply

More great articles

Inspect storage with calls & return statements

In Solidity, you can return some values from functions, like in other programming languages. Its also possible to use these…

Read Story

Simple storage – Part II

In this video, we are going to finish our simple storage smart contract, which can set and get the value…

Read Story

DAO – Part I

In this new series of videos, we are going to build a DAO (Decentralized Autonomous Organization) smart contract. The DAO…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]