#pallet #substrate #demonstrate #storage #maps #map #pallets

no-std simple-map

A pallet that demonstrates Substrate's storage maps

1 unstable release

0.0.1 Nov 2, 2021

#20 in #pallets

GPL-3.0-or-later

10KB
209 lines

Pallets

UPDATE: This repository has been archived. Pallets that are used in production are moved to universal-dot-node.

This is a playground for new pallets that are developed for Substrate.

The pallets used in production have been moved to the node.

Pallets are developed separately from Runtime and injected into the Runtime.

Custom Pallet cargo versions shall remain consistent with Runtime package versions.

Development

To build each pallet, run:

cargo build

Optionally, you can install clippy which is a rust tool that check for Rust to improve common mistakes. To install clippy: https://github.com/rust-lang/rust-clippy

To run clippy locally, run:

cargo clippy

Add Pallet to Runtime

To add a specific pallet to a Runtime, navigate to the Universal-dot-node. In the /Runtime/Cargo.toml add each pallet dependency. For example, to add the Profile pallet, the following configuration should be added:

[dependencies.pallet-profile]
default-features = false
git = 'https://github.com/UniversalDot/pallets.git'
version = '0.0.67'

Testing

Mock Runtime

Pallet test depend on substrate Runtime. To be able to run these pallet test, first we must construct a mock Runtime environment. Mocks for runtime are constructed for each pallet separately and are located in their respective /src/ folder.
More information regarding constructing Mock Runtime at the following link.

Writing tests

Tests are functions, annotated with the #[test] macro. To test specific functionality, we use assert macros to match our expectations with the expected result. There are already several predefine assert macros such as:

  • assert_eq!
  • assert_ok!
  • assert_noop!

For more information on how to create tests, refer to the following link.

Run tests

To run test each pallet, simply run at pallet root:

cargo test

To run benchmark tests for each pallet, simply run at pallet root:

cargo test --features runtime-benchmarks

Logo


lib.rs:

A pallet to demonstrate usage of a simple storage map

Storage maps map a key type to a value type. The hasher used to hash the key can be customized. This pallet uses the blake2_128_concat hasher. This is a good default hasher.

Dependencies

~8–17MB
~240K SLoC