Testing contracts that use ENS with ENSBuilder

Marek Kirejczyk
Sep 28, 2018 · 2 min read

When it comes to testing contracts and functionality that uses Ethereum Naming System (ENS), it is a bit tricky. It is difficult to test in isolation from ENS, and it is hard to stub ENS.

We stumble upon that challenge when working on Universal Login SDK.

To solve that problem we created a simple library called ENSBuilder, which allows one to quickly set up and configure a standalone instance of ENS, on a local environment, in tests or on a test chain.

With ENSBuilder setup is as easy as a single method call:

const ensAddress = await builder.bootstrapWith(‘example’, ‘eth’);

And you already have a copy of ENS, up and running, as well as two domains registered: ‘ens’ and ‘example.ens’.

You can now register an address:

await builder.registerAddress(‘marek’, ‘example.eth’, ‘0x…’);

Ethers.js

The builder uses ethers.js as a contract abstraction. Web3js is also supported but will require you to pass a private key. We plan to add better web3js support if we see requests from people to do it. We would also happily accept PRs :)

Why Ethers.js you may ask?
We find ethers.js to be a stable, light, feature complete and production ready alternative to web3js. Therefore we are using it both for tests as well as application code.

Getting Started

For in-depth information as well as a quick tutorial go to EnsBuilder GitHub.

If you enjoyed this post, please hit the 👏 button and if you would like to get notified when new story shows up, click follow button below.

You can also follow us on Facebook and Twitter.

Ethworks

On the blockchain, software engineering and running a company.

Ethworks

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

Marek Kirejczyk

Written by

Ethereum blockchain Engineer. Ethworks, Universal Login.

Ethworks

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