Testing contracts that use ENS with ENSBuilder
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…’);
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.
For in-depth information as well as a quick tutorial go to EnsBuilder GitHub.