Replace public testnets with Virtual TestNets synced with mainnet state. Get started!

Case Study

How Nexus Mutual Uses Virtual TestNets to Speed up Development Loops

Organization: Nexus Mutual

Website: nexusmutual.io

Industry: DeFi

How Nexus Mutual Uses Virtual TestNets to Speed up Development Loops

"Tenderly Virtual TestNets improved our dev loop a lot because we no longer have to wait a long time for tests to execute. Instead of doing a lot of manual work, using Virtual TestNets is much faster and easier."

Anatol Prisacaru

Senior Engineer at Nexus Mutual

As a leading insurance alternative for the DeFi space, Nexus Mutual offers a diverse set of products that cover risks for on-chain and real-world assets. Cover protection is available to DeFi users, VCs, and funds for protocol failures, ETH slashing, and other types of risks.

Any on-chain user can join Nexus Mutual to create, stake, and participate in staking pools that enable on-chain protection, sharing risks with other members. Stakers delegate their NXM to provide enough capacity for specific cover products while buyers purchase the products based on the available capacity.

Nexus Mutual services are open-source and available to Web3 teams to fork and work on their iterations. Their engineering organization is fully decentralized, with frontend, backend, and Solidity teams across the globe.

Introducing realistic testing on on-chain data

Initially, the Nexus Mutual developers used Truffle and Ganache for testing before transitioning to a Ganache-based OpenZeppelin framework until it was deprecated. The team then had to undergo another migration to Hardhat and Ethers v5. At that time, testing on real on-chain data was limited to local forks. They had to write extensive scripts to recreate mainnet conditions as closely as possible and were still constrained to local environments. 

The Nexus Mutual engineering team also tried setting up Kovan, but the public testnet was always behind. Oracles were either missing or their values weren’t up-to-date. Additionally, it was difficult to maintain public testing infrastructure. For these reasons, the team decided not to deploy to a different public testnet once Kovan got deprecated.

As one of the first Tenderly users, the Nexus Mutual team started using the simulation infrastructure as soon as Tenderly pioneered simulation technology. Tenderly’s simulation infrastructure enabled the team to run multiple chained simulations, previewing the execution of governance proposals on top of on-chain data. They would play out proposals with all related parameters to check whether everything worked as expected.

The Nexus Mutual team now uses Tenderly Virtual TestNets, a flexible development infrastructure that mirrors the on-chain conditions of a production network. The team can quickly fork a network using Virtual TestNets to get full on-chain data in their development and testing workflows.

Rather than using a public testnet, it’s much easier and more efficient to use Tenderly Virtual TestNets to fork the mainnet and get exactly the same environment, with the ability to share it with your team. – Anatol Prisacaru, Senior Engineer at Nexus Mutual

How Virtual TestNets shorten Nexus Mutual's development loops

To enable the execution of realistic and reproducible tests, the Nexus Mutual team set up a development and testing infrastructure that relies on an internally maintained Erigon node and zero-setup Virtual TestNets. The team uses Hardhat and Ethers v5 together with Erigon and Virtual TestNets as part of their tech stack. 

Currently, the Nexus Mutual uses their tech stack to run three different types of tests: 

  1. Unit tests to test contract logic in isolation
  2. Integration tests to test all their contract interactions 
  3. Fork tests that depend on up-to-date on-chain data

Often enough the fork tests are lengthy, leading to a long-running process that increases the duration of their development loops between applying a change and seeing its result.

Instead, the Nexus Mutual engineers use Virtual TestNets to quickly test whether a code change does exactly what it should. They spin up a Virtual TestNet to test the impact of their changes using snapshots. The team runs tests up to a point, executes evm_snapshot, and comments out the already executed steps. Then, at the beginning of each test suite, they revert the state to the snapshot to execute a specific step.

Running evm_snapshot on Virtual TestNets
Running evm_snapshot on Virtual TestNets
Tenderly Virtual TestNets improved our dev loop a lot because we no longer have to wait a long time for tests to execute. Instead of doing a lot of manual work, using Virtual TestNets is much faster and easier.  – Anatol Prisacaru, Senior Engineer at Nexus Mutual

By using Virtual TestNets, the Nexus Mutual team greatly speeds up their development loops. They can fork the Mainnet in milliseconds and test different scenarios under realistic conditions. Plus, they can dive into execution flows in the developer-friendly Dashboard, using granular, human-readable data to debug errors more efficiently.

If I have to debug something and write a script to check the values, it takes a lot of time. Instead, I can just go to Virtual TestNets in the Dashboard, open contract execution, check the state, and run a simulation after that. Tenderly saves a lot of time on debugging. – Anatol Prisacaru, Senior Engineer at Nexus Mutual

Running a diverse test suite on Virtual TestNets

In addition to running fork tests on Virtual TestNets with complete on-chain data, the Nexus Mutual team uses them for other testing purposes. 

Previewing governance proposals

The Nexus Mutual engineering team also uses Virtual TestNets to simulate the execution of active governance proposals. They run multiple simulations on Virtual TestNets to preview the votes of advisory board members and their effects. This way, the team can test whether everything executes as expected and identify possible defects in a safe environment that mimics the production state. 

Once they simulate the votes, they share the Virtual TestNet with everyone to examine the post-execution state. Each team member can take a look, run tests, and ensure all the values are correct, preventing unwanted or malicious effects.

Before you had to be very technical to write test scripts and check the values and state. With Virtual TestNets, anyone can go to the UI to fork a network and simulate transactions. It’s much easier. – Anatol Prisacaru, Senior Engineer at Nexus Mutual

Testing frontend integrations for new upgrades

Additionally, the team spins up a new Virtual TestNet to run frontend tests for upcoming product updates. The Solidity team deploys and forwards smart contracts to the frontend team on a Virtual TestNet once they’re ready. The frontend team then uses the Virtual TestNet RPC in MetaMask to run tests on on-chain data.

If the frontend team encounters issues while testing UI integrations, they can share failed transactions or even entire Virtual TestNet environments with the Solidity team. The Solidity team can then use the built-in virtual explorer and debugging tools to inspect transaction execution, troubleshoot issues with a granular stack trace, and deploy patches quickly.

Accelerating Web3 development with Virtual TestNets

Aside from bringing complete on-chain data to Web3 development workflows, Virtual TestNets significantly speed up development cycles for the Nexus Mutual team. Instead of manually setting up network forks using local nodes, they can quickly fork a network and run different tests in Virtual TestNet environments that mimic the production state. Then, they can dive into granular execution using the built-in tools, saving significant time on debugging.