Starting a solo project and building a test suite

Starting a solo project and building a test suite

Today was my first full workday focused on Web3. It was awesome. I normally eat lunch at 11:30 am. I was in the zone and didn’t notice I was hungry until 1:00 pm.

Until last week, I spent most of my time going through a few introductory Solidity and Web3 javascript courses to get the basics down. On Wednesday, I finished working through Nader Dabit’s “The Complete Guide to Full Stack Ethereum Development.” It was a nice introduction to the modern tool suite for Web3 development and introduced me to a number of great tools like Hardhat, Ethers.js, Alchemy, and the Mocha/Chai testing frameworks. At this point, I felt confident enough to start building some of the project ideas I had developed since starting to learn Solidity.

First "Real" Project - Crypto Raiders Staking Vaults

On Thursday, I started working on an auto-compounder vault for the Crypto Raiders staking contracts. If you’re not familiar with the project, it’s hosted on Polygon and has its own bank interface to deposit Sushi LP and project tokens for staking incentives (I highlighted my Raider Analysis app in the last issue that helps analyze these). They are several strategies to convert the rewards into additional staked tokens to compound your gains. However, the process to do so is a bit manual currently and the ROI can be enhanced with frequent compounding due to high APRs. Therefore, I decided to build a contract and bot to do this automatically.

I finished the initial implementation of the Raider LP Vault contract (specifically for the LP staking contracts, not the locked Raider staking one) over the weekend. It allows users to deposit their SLP tokens, grow their deposit, and then withdraw their new balance of SLP tokens at any time. On the frontend, it will look similar to the Yearn.finance vaults, but it’s not as sophisticated since the strategies are fixed and governance is not decentralized.

Today's Goal - Build out the Smart Contract Test Suite

Because of the amount of real money this contract could hold, testing the contract is more important than getting the first pass done. Therefore, I spent most of the day today building out a test suite to put the main contract functions through its paces.

Unlike many sample projects I built that were mainly stand alone, this contract interacts with multiple other contracts on chain including the Raider Staking contracts, the SushiSwap Router, and all of the ERC-20 token contracts for the base and LP tokens involved. In order to not have to build out a bunch of scaffolding myself for the tests, I used an awesome feature of Hardhat to fork Polygon Mainnet from a fixed block and run it locally in my development environment.

My goal with the test suite is to work through the main user flows first and then tackle corner cases and security. Today, I wrote out 15 tests and troubleshot a ton of errors caused by me being new to ethers.js, not providing the right setup for each case, and learning the quirks of the UniswapV2Router API (which is used by SushiSwap). At the end of the day, I had debugged the contract enough to pass all the tests:

Tests completed for the RAIDER/MATIC LP pool case