Learn to write unit and simulation tests for smart contracts.
In the Resources section below choose AssemblyScript or Rust
If you have the time to look around the corner, here's a little more for you.
If you want a few more ideas for this challenge, consider the following:
Find a contract that has no unit tests (there are many) and write them
Remove some (or all) of the existing unit tests from a contract and rewrite them.
Check out this little puzzle, it may be fun for you
Start from a blank document (or just boilerplate) and try to test-drive (TDD) a contract.
If you're feeling fearless, here's about as far as you might take this road in a day
While simulation tests are an evolving work in progress, we do have a few examples which can help you. The key to understanding simulation tests on NEAR is that you're testing the Wasm binary. This means the same simulation test configuration will work for Rust and AssemblyScript.
In fact, the exact same simulation tests can be used against a compiled Rust or compiled AssemblyScript contract. Maybe this is obvious once you consider that simulation tests are using the same on-chain virtual machine so everything you do in a simulation test should be 1:1 repeatable on-chain.
Heads up, simulation tests must be written in Rust. The examples below will make that clear.
What is a new idea — what Satoshi figured out — is how to independently agree upon a history of events without central coordination. He found a way to implement a decentralised timestamping scheme that:
- a) doesn’t require a time-stamping company or server,
- b) doesn’t require a newspaper or any other physical medium as proof, and
- c) can keep the ticks more-or-less constant, even when operating in an environment of ever-faster CPU clock times.
– Gigi in Bitcoin is Time
REMEMBER: For today’s activity
If you intend to focus on AssemblyScript, [ OPEN the list of AssemblyScript contracts ]
For a minimum of 3 contracts marked as CORE Activity
Unit testing is provided by as-pect and the syntax resembles RSpec. The library is well documented but sometimes the tests for the testing library might be the best source of examples to help you learn quickly.
Almost all of the examples available on near.dev include unit tests.
If you intend to focus on Rust, [ OPEN the list of Rust contracts ]
For a minimum of 3 contracts marked as CORE Activity
Unit testing is included as part of the Rust language.
You can read more about unit tests in Rust by Example or "the book".
All of NEAR's Core Contracts include unit tests if you want to see some good examples. You will notice the whitelist
contract, for example, includes a test_utils
import that sets up the MockedBlockchain context for unit tests in a separate file