I’m currently working on a “Light Replica” project under Developers Grant Program.
The goal of this project is to give you a possibility to write tests/deployment scripts in JavaScript/TypeScript and run them against canisters in development. If you have used truffle/hardhat than it is exactly the kind of experience (especially hardhat) I want to bring to IC development.
I’m implementing “mock replica” in TypeScript along with WASM dropins so it will be possible to run in node.js and any brower that supports WASM (so actually all of major browsers).
Project Description
Ethereum and other EVM chains benefit from frameworks such as truffle or hardhat. They enable easy and fast creation, testing and deployment of solutions to EVM based chains. Their strength lies in usage of JS scripts to do everything: setup local node, make tests, make deployments and more.
“Light Replica” is a project to startup creation of similar tool for the Internet Computer ecosystem. It will be composed from two elements:
Light Node - it is a local node designed for development (fast startup and cleanup), it will replicate behavior of the real node with additional logging and functions to help testing. It will be able to run and interact with any IC compatible wasm file.
Light Runner/Cli - a set of libraries written in JS (available in npm) that can be used in node.js environment to create and build projects, write tests, create deployments and arbitrary scripts that have access to project “context” right from the js code.
Both tools are aimed at developers. To help them efficiently develop, test and deploy canisters to the IC.
I would like your input on what JS testing library should be supported (I was thinking Jest or Mocha). Also the API of the framework is up to discussion.
Starting with jest sounds like a good approach to me. vitetest would probably be neat. never used it yet but, they seem to have quite some momemtum and I heard it’s super fast. Enough momemtum that if I would have to start a new suite of test, I would probably first try vitetest over jest.
Super interesting and valuable project, please keep posted
Install container in a replica, the canister id will be automatically assigned (Principal object is used from @dfinity/principal). Currently it works only with wasm files (no compilation support yet)
The candid file can be specified by hand or it will be obtained from canister (works on all Motoko canisters and Rust canister that explicitly supports this method). It will be automatically transformed in to IDL data (I’m using objects from @dfinity/candid). You will get actor like object, which can be used to call deployed canister
Currently you can call only query methods, all debug and traps will be displayed on the console. I’ve checked and the call and result looks identical as in regular “agent” (I’ve tried to match it, so it is familiar to use)
What is next:
Refactor of the code, so it can be uploaded to npmjs
Adding support for update calls
More tests, and examples on how to write tests using published npmjs package
And what is on the roadmap:
Ability to redirect canister output to custom endpoint
BLS signatures and express server (so that you can use actual @dfinity packages)