Image for post
Image for post

Smart contract testing with ENS and Waffle

Marek Kirejczyk
Aug 5 · 2 min read

With hundreds of applications using ENS, an Ethereum-based decentralised naming system, we can all agree that it has become a widely recognised standard in the blockchain space.

Yet, when it comes to testing smart contracts, it’s difficult to test code that interacts with ENS. And for this exact reason, we’ve introduced an ENS module in Waffle.

The two most common scenarios involve:

  • testing smart contracts interaction with ENS,
  • integration or end-to-end testing of smart contracts together with a higher-level API/GUI.

We’ve already experienced this need on several occasions. In such situations, it’s useful to have ENS deployed in your test/development node. It’s somewhat complex to deploy a copy of ENS on your own, so we’ve added such an option to Waffle a while ago.

How does it work? It’s very simple.

ENS attached to MockProvider

The most straightforward way to start using ENS is to use the built-in MockProvider singleton.

Creating domains

To create a top-level domain, usecreateTopLevelDomainfunction:

To create a subdomain, use createSubDomain function:

If you want to create a multi-level domain with a single call, use recursive option for createSubDomain:

Setting address

To set an address for a given domain, use setAddress function:

Option {recursive: true} is also available for setAddress.

And if you want to set address with reverse mapping, you can use:

Again, reverse option is available.

Deploying ENS copy

If for some reason you need a stand-alone copy of ENS or you want to hook it up to another provider or deploy to another node/network, you can use deployENS function that will deploy a ready-to-work ENS copy (with top-level registrar and a resolver):


It’s a great pleasure to see ENS becoming a first-class citizen on Ethereum, and now that it’s so easy to test with it, we hope the adoption will accelerate even further.


We are Ethworks. A truly remarkable team for your blockchain project.

Find us on Twitter, GitHub and Dribbble.

Ethworks

On the blockchain, software engineering and running a company.

Sign up for 💡 Waffle News 💡

By Ethworks

Best practices in testing smart contracts with Waffle: our sweeter and simpler library built for Ethereum developers Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Marek Kirejczyk

Written by

Ethereum blockchain Engineer. Ethworks, Universal Login.

Ethworks

Ethworks

Software is eating the world. Blockchain is eating money. Ethworks is cooking.

Marek Kirejczyk

Written by

Ethereum blockchain Engineer. Ethworks, Universal Login.

Ethworks

Ethworks

Software is eating the world. Blockchain is eating money. Ethworks is cooking.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store