Now that we have more people working in the Developer Platform team, it is time to revisit our approach to testing contracts, and improve on them.
Currently there are two ways Rust contract developers can test their contracts, and there is one way AssemblyScript developers can test theirs.
- Rust devs can use unit-tests like these to test small things. They are easy to use, but they are limited and cannot test full spectrum on interactions between contract and the blockchain, e.g. they don’t allow cross-contract calls or issuing transactions;
- Rust devs can also use near-sdk-sim test like these to test complex interactions between all kinds of contracts, plus it allows contracts to test creation of transactions. Unfortunately, behind the scenes near-sdk-sim emulates part of the NEAR node, which is costly to maintain and does not match execution of the node 100%;
- AS devs use tests similar to near-sdk-sim in their functionality. The test are written in AssemblyScript and they leverage similar emulation environment behind the scenes;
There are multiple reasons to change how we current approach testing:
- It would be good to not maintain many testing frameworks especially if their functionalities overlap;
- We are planning on allowing people to develop in other languages on NEAR (2 more languages are currently underway) and we want them to be able to reuse existing frameworks without creating a language-specific framework each time;
- It would be good for the tests to be able to run on the live nodes, like local node, Testnet, or Mainnet. This will allow developers ensure that the test behavior can be replicated in production;
- Maintaining an emulator of NEAR node is costly. Plus, it will inevitably diverge from the actual node causing bad DevX;
- It would be good if testing frameworks were completely decoupled from SDKs to allow easier iterations on both.
Several ideas were voiced:
- We discussed getting rid of the emulator and replacing it with the NEAR node, similar to how Ganache is used by Truffle. We call NEAR version of Ganache – Sandbox;
- There was an idea to allow users to run tests on code snippets from within our documentation webpage. Tests do not need to be hosted entirely in the browser webpage (i.e. they can run on the backend), but it would be cool if people could run them on Mainnet/Testnet for extra realism;
- We might want to replace AssemblyScript tests with TypeScript tests;
The following people are involved with this project:
- @tachyon – core development of the testing framework;
- @josh.quintal – product vision;
- @boatnear – development of the Sandbox;
Additionally the following people are partially involved in the project: