npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atixlabs/mina-testing-utils

v0.0.1-a3

Published

Handful MINA testing utilx to be used alongside with zkapp-cli generated projects

Downloads

8

Readme

Mina Testing Utils

This repository contains a set of utilities for testing Mina zkapps:

  • Custom jest matchers
  • An interactive debugger to interact with locally deployed contracts
  • A contract (gates) sizer

Requirements

Installing

In order to use this tool, you should install it as a dev dependency on your existing project, for example, one created using zkcli-app:

npm --save-dev install @atixlabs/mina-testing-utils 

Using Jest matchers

Import it in your tests as follows:

// Import to extend the matchers
import '@atixlabs/mina-testing-utils';

describe('my test', () => {

  it('some test', async () => {

		// Matchers are automatically recognized by jest
    expect(Field(19)).toEqual(19);
    expect(app.someBooleanState).toBeFalse()
  })

You can refer to contract.test.ts for a running example.

Using the interactive debugger

After installing the package, you can run the interactive debugger as follows:

import { Field, SmartContract, state, State, method } from 'o1js';

/**
 * Basic Example
 * See https://docs.minaprotocol.com/zkapps for more info.
 *
 * The Add contract initializes the state variable 'num' to be a Field(1) value by default when deployed.
 * When the 'update' method is called, the Add contract adds Field(2) to its 'num' contract state.
 *
 * This file is safe to delete and replace with your own contract.
 */
export class Add extends SmartContract {
  @state(Field) num = State<Field>();

  init() {
    super.init();
    this.num.set(Field(1));
  }

  @method update() {
    const currentState = this.num.getAndAssertEquals();
    const newState = currentState.add(2);
    this.num.set(newState);
  }
}
❯ npx mina-testing-utils repl


 ███╗   ███╗ ██╗ ███╗   ██╗  █████╗      ████████╗ ███████╗ ███████╗ ████████╗ ██╗ ███╗   ██╗  ██████╗      ██╗   ██╗ ████████╗ ██╗ ██╗      ███████╗
 ████╗ ████║ ██║ ████╗  ██║ ██╔══██╗     ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝ ██║ ████╗  ██║ ██╔════╝      ██║   ██║ ╚══██╔══╝ ██║ ██║      ██╔════╝
 ██╔████╔██║ ██║ ██╔██╗ ██║ ███████║        ██║    █████╗   ███████╗    ██║    ██║ ██╔██╗ ██║ ██║  ███╗     ██║   ██║    ██║    ██║ ██║      ███████╗
 ██║╚██╔╝██║ ██║ ██║╚██╗██║ ██╔══██║        ██║    ██╔══╝   ╚════██║    ██║    ██║ ██║╚██╗██║ ██║   ██║     ██║   ██║    ██║    ██║ ██║      ╚════██║
 ██║ ╚═╝ ██║ ██║ ██║ ╚████║ ██║  ██║        ██║    ███████╗ ███████║    ██║    ██║ ██║ ╚████║ ╚██████╔╝     ╚██████╔╝    ██║    ██║ ███████╗ ███████║
 ╚═╝     ╚═╝ ╚═╝ ╚═╝  ╚═══╝ ╚═╝  ╚═╝        ╚═╝    ╚══════╝ ╚══════╝    ╚═╝    ╚═╝ ╚═╝  ╚═══╝  ╚═════╝       ╚═════╝     ╚═╝    ╚═╝ ╚══════╝ ╚══════╝



  

Please load the Mina REPL context by executing .loadMina before running any commands.


  
mina-testing-utils> .loadMina
✔ Snarky loaded successfully! You can access it through the mina object.

mina-testing-utils> let { Add } = await import("/Projects/yourProject/build/src/Add.js")

mina-testing-utils> let { priv: zkAppPrivateKey, pub: zkAppAddress } = mina.genKeyPair();

mina-testing-utils> let zkApp = new Add(zkAppAddress);

mina-testing-utils> let { privateKey: deployerKey, publicKey: deployerAccount } = mina.testAccounts[0];

mina-testing-utils> let txn = await mina.o1js.Mina.transaction(deployerAccount, () => {
  mina.o1js.AccountUpdate.fundNewAccount(deployerAccount);
  zkApp.deploy();
});

mina-testing-utils> await txn.prove();
mina-testing-utils> await txn.sign([deployerKey, zkAppPrivateKey]).send();

mina-testing-utils> console.log("Stored number in state is: ", zkApp.num.get().toString())
Stored number in state is:  1

See it in action:

asciicast

Using the contract sizer

This tool also allows you to keep track of the amount of gates the contracts you create are creating thus giving an idea of the complexity it will involve using them. To try it, run:

npx mina-testing-utils circuits-sizer build/src/test-contract.js

Bear in mind you need to compile them first (if zkapp-cli is being used, it should be npm run build).

See it in action:

asciicast

Development

Requirements

  • nodejs +18

Setup

npm install

Testing

npm test

Trying on a zkapp-cli local app

Note: npm link seems to be messing around with o1js import resulting in multiple errors therefore follow this steps in order to use a local version of this lib:

# generate your zkapp as you would do normally, see https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
zk example

# build the library
npm run build
# generate a tar file in any folder as pleased
npm run dev-pack -- --pack-destination /tmp/ 

# install the library in your zkapp
cd example && npm install --save-dev /tmp/mina-testing-utils-0.0.1.tgz