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

Advanced Drizzle Tutorial: Create your own Dapp components with React and Context API

In the last episode I gave you an introduction to Drizzle and we built a simple Dapp using Drizzle, Truffle…

Read Story

DAO – Part IV

In this video, we are going to allow investors of the DAO to: create investment proposals vote on each investment…

Read Story

Testing integers in smart contract with Truffle and bn.js (Big Number)

In Solidity smart contract, you might have to deal with huge numbers, especially when doing financial transfers. Don't forget that…

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