Leo is a programming language designed for writing scalable, verifiable, and auditable programs for the private-by-default Aleo network: testing is a crucial component in achieving these aims. The Leo environment, however, presents some hurdles that make testing Leo code less straightforward than in more mainstream programming language environments.

Enter DokoJS, a lightweight testing framework that sands down the rough edges around writing unit tests against Leo code: it makes the testing workflow as simple as testing JavaScript. The rest of this post will walk through the process of testing a Leo program using DokoJS.

<aside> đź’ˇ

This post assumes familiarity with Leo syntax: you should ideally have perused the Leo language reference beforehand.

This post also assumes familiarity with JavaScript and common unit testing conventions and patterns.

</aside>

Challenges Around Testing Leo Code

Before diving in, it’s important to understand what problems DokoJS addresses. The thing is, Leo is not a general-purpose programming language. It is not Turing-complete, and its syntax must maintain semantic equivalence with the underlying zkSNARK output of the compiler. Indeed, it is a language designed specifically for writing decentralized applications that live and run on the Aleo network. Building testing capabilities directly into the Leo language and its compiler would run counter to these purposes, i.e., we cannot write tests for Leo code in Leo itself.

DokoJS addresses this limitation by generating and exposing interfaces that allow developers to programmatically interact with Leo code using JavaScript. At that point, developers are able to write tests against Leo code just like how they would write tests against JavaScript, with all of the streamlined developer experience niceties that come with such a mature testing ecosystem. With that said, let’s take a look at DokoJS in action!

Getting Started with DokoJS

Install Prerequisites

First off, make sure that Leo is already installed on your machine. If it isn’t, refer to these instructions for installing it and its dependencies. You’ll also need npm installed for the purposes of this walkthrough; you can refer here if you need to grab it. For testing purposes, you’ll also need a local testnet setup. For this, we recommend Amareleo, which is a light, fast, and easy to use Aleo development node: refer here for installation instructions.

Install DokoJS Itself

As for DokoJS itself, you can opt to either install it via npm by running npm install -g @doko-js/cli@latest, or building it from source. Note that building from source will also require pnpm, which you can install following this guide if you need to do so.

# Clone the git repository
git clone <https://github.com/venture23-aleo/doko-js>

cd doko-js

# Install the dependencies
pnpm install

# Build the project
npm run build

# Install the DokoJS CLI
npm run install:cli

Initializing a New Project

We can now initialize a new project called token by running dokojs init token.

Let’s highlight a few of the directories and files contained in the project we just initialized:

For this walkthrough, we’ll be testing a modified version of the Token program that can be found on the Leo playground. It will require us to get familiar with how to test both public and private transactions and operations. Navigate to the playground link, and then copy and paste the playground code into the token.leo file in the programs/ directory.

Configuring DokoJS