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.

0 Comments

Leave a Reply

More great articles

Syntax vs runtime vs logic errors in solidity

A lot of people are confused about debugging in general and don't know the difference between a syntax error and…

Read Story

Crud – Part III

In the last part of this tutorial we finished all the functionalities of our smart contract. Unfortunately, we have a…

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

Never miss a minute

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