fbpx

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

HelloWorld smart contract

The obligatory hello world tutorial! Here we go! In this video, I am going to show you how to create…

Read Story

Test driven development for Solidity

Do you write tests for your Solidity smart contracts? Congrats if you do, and if don't it's time to start!…

Read Story

Crud – Part IV

If a user does not exist, no error is produced. We should change that. In this video you will learn…

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