A basic overview to help you write out your checks and balances.
Learn how to write tests and improve the correctness of a
Testing a custom transfer function.
Testing each function is an imporant part of developing pallets for production. This guide
steps you through best practices for writing test cases for a basic
1. Outline the
A transfer function has two key elements: subtracting a balance from an account and adding that balance to another account. Here, we'll start by outlining this function:
The first thing to verify, is whether the sender has enough balance.
In a separate
tests.rs file, write out this first test case:
To implement some error check, replace
try_mutate to use
This will check whether bal is greater or equal to amount and throw an error message if not:
cargo test from your pallet's directory.
#[transactional] to generate a wrapper around both checks:
Make sure that sending and receiving accounts aren't dust accounts. Use