A template with cookie cutter CLI, Program and Integration tests for Solana blockchain

Overview

About

solana-cli-program template is a sample app demonstrating the creation of a minimal CLI application written in Rust to interact with Solana and programs. It provides multiple pieces of functionality:

  • ping: Creates a transaction sending 0 SOL from the signer's account to the signer's account. Returns the signature of the transaction.
  • mint: Mint a key/value pair to an owning account.
  • transfer: Transfer a key, and it's value, from one owning account to another.
  • burn: Burn (delete) a key, and it's value, from an owning account.
  • balance: Returns an account's balance.
  • help: Tips for using the app. This is an off-chain operation.

solana-cli-program template is a derived work inspired by @mvines solana-cli-template

Structure

A functional macro level view

framework

Quick start

  1. Install Rust from https://rustup.rs/
  2. Clone this repo
  3. If running the integration tests or Mint, Transfer, Burn instructions:
cd program
cargo build-bpf
cd ..
  1. cargo run help

Sample keys

The repo includes sample keys for 'owners'. There are two owner accounts predefined User1 and User2, each with two keypairs defined:

  1. An owners 'wallet' account. This is funded by the Solana configurations default account and is used to fund program accounts.
  2. An owners program 'account' which is used by the sample program for mint, transfer and burn operations
  • There is a third account called Service which is used for program instructions that exact a fee for the instruction execution. These are executed as part of the integration tests only

Running locally step-by-step

  1. If not running Mint, Transfer and/or Burn:
  • Start a local node: run solana-test-validator.
  • Optionally generate a keypair: solana-keygen new -o test.json.
  • Optionally add 100 SOL to the corresponding account solana airdrop --url http://127.0.0.1:8899 --keypair test.json 100.
  1. For running Mint, Transfer and/or Burn:
  • Start a local node and load the sample program solana-test-validator --bpf-program SampGgdt3wioaoMZhC6LTSbg4pnuvQnSfJpDYeuXQBv ~/solana-cli-program-template/program/target/bpfel-unknown-unknown/release/solana_cli_template_program_bpf.so --ledger ~/solana-cli-program-template/.ledger --reset
  1. Build app: cargo run.

  2. Ping:

$ cargo run -- ping --url http://127.0.0.1:8899 --keypair test.json
Signature: 2Y863JX96RTqbeGfcvQowVt1V91Dgs2LZfVgQ3mGJPmYu24sUTYmfkArHAAgj4uFqP75bm9GXU9DYjiMFxahQJUC
  1. Mint (no fee):
cargo run -- mint --url http://127.0.0.1:8899 -t User1 -k AKey --value Minted key value pair
User1 to account key/value store {"AKey": "Minted key value pair"}
  1. Transfer (no fee):
cargo run -- transfer --url http://127.0.0.1:8899 -f User1 -t User2 -k AKey
User1 from account key/value store {}
User2 to account key/value store {"AKey": "Minted key value pair"}
  1. Burn (no fee):
cargo run -- burn --url http://127.0.0.1:8899 -f User2 -k AKey
User2 from account key/value store {}
  1. Balance:
$ cargo run -- balance --url http://127.0.0.1:8899 --keypair test.json
3dSRGE3wYCcGWFrxAsQs5PaBqtJzzxdTzY2ypXNFUji9 has a balance of ◎99.999995000 // balance less than 100 because of ping operation above
$ cargo run -- balance --url http://127.0.0.1:8899 --keypair keys/accounts/user1_account.json
A94wMjV54C8f8wn7zL8TxNCdNiGoq7XSN7vWGrtd4vwU has a balance of ◎0.008017920 // after first running 'mint'
  1. Run help for the complete list of options:
$ cargo run -- --help
cli-program-template 0.1.0


USAGE:
    cli-program-template [FLAGS] [OPTIONS] 
   
    

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Show additional information

OPTIONS:
    -C, --config 
    
             Configuration file to use [default: /Users/user/.config/solana/cli/config.yml]
        --url 
     
                  JSON RPC URL for the cluster [default: value from configuration file]
        --keypair 
      
           Filepath or URL to a keypair [default: client keypair]

SUBCOMMANDS:
  balance     Get balance
  burn        Burn (delete) a key/value pair from an account
  help        Prints this message or the help of the given subcommand(s)
  mint        Mint a new key/value pair to an account
  ping        Send a ping transaction
  transfer    Transfer a key/value pair from one account to another

      
     
    
   
Comments
  • Initial review

    Initial review

    @mvines From a testing perspective, I have completed implementation of a sunny day integration test through the program instructions. These are not options in the CLI, yet....

    If you want to take a look and provide any feedback before I continue at this point please feel free. Do not spare the lash :)... still in learning curve and it will help.

    opened by FrankC01 2
  • zeroize issue in Cargo.lock

    zeroize issue in Cargo.lock

    https://discord.com/channels/428295358100013066/517163444747894795/866817559377477662

    bottlecap97 — Today at 7:03 PM update, broken builds. it appears zerorize latest update, has broken the builds of many solana-labs apps and examples, including solana-cli-program-template, because this zeroize library is referenced often by dependencies in the chain. it was recently upgrade to 1.4.0 a day ago, and linked dependencies will not build & compile as is now. im not sure what a fix would be at this time. simply doing the recommendations inside the cargo.toml solana apps portion does not appear to work - and im not sure how it affects linked dependency chains. should this be officially logged somewhere?

    the only workaround I know of is to use a hard coded referenced version and checksum in the cargo lock of the builds in question. im sure there is a better temp work around or answer to just build.

    [[package]] name = "zeroize" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" Tyera — Today at 7:12 PM Yeah, that's correct. I think locking zeroize to the earlier version is the quickest fix atm. We do have a fix for this issue coming in v1.7.7: https://github.com/solana-labs/solana/pull/18766

    wontfix 
    opened by FrankC01 0
  • Add `ProgramTest` utility for program transaction testing

    Add `ProgramTest` utility for program transaction testing

    The template has integration testing that uses solana-test-validator and exercises RPC to drive the transactions to the program.

    The solana toolbox has a ProgramTest lightweight runtime engine (no ledger, RPC, etc.) that supports driving transactions directly to the program. This change is to add program/test to do rapid program edit/test before advancing to the full blown validator testing.

    change 
    opened by FrankC01 0
  • Restructure source so the program memory layout is known between CLI and Program

    Restructure source so the program memory layout is known between CLI and Program

    Currently that knowledge is replicated in both src/util/account_state.rs and program/src/account_state.rs

    This change will require moving just the constants that define the memory mapping to a common file accessible to builds for CLI and Program.

    change 
    opened by FrankC01 0
  • Document the touch-points to adopt template into consumers context

    Document the touch-points to adopt template into consumers context

    While the template as is serves the purpose of reducing the time to a reasonably comprehensive framework, it may be confusing and time consuming to identify all the change 'cause and effect' when fitting to needs of the consumer.

    documentation 
    opened by FrankC01 0
Owner
null
Snapshot testing for a herd of CLI tests

trycmd Snapshot testing for a herd of CLI tests trycmd aims to simplify the process for running a large collection of end-to-end CLI test cases, takin

null 57 Jan 3, 2023
🔔 CLI utility to send notifications to Slack via integration webhooks

Slack notifier Just a simple CLI tool to send notifications to Slack. Please note that this project is just a playground to start learning Rust, it is

Green.Mod 2 May 21, 2022
Assure that your tests are there, and well written.

cargo-is-tested [ ???? ] El libro contiene instrucciones e información detallada en Español. cargo-is-tested is a way to check which of your items are

Alex ✨ Cosmic Princess ✨ 15 Jan 8, 2023
An adaptation of the Solana token-swap program implementing Curve's StableSwap invariant.

StableSwap Program An adaptation of the Solana token-swap program implementing Curve's StableSwap invariant. Click here to try it out live on the Sola

smaster0517 3 Mar 30, 2022
A simple, opinionated way to run containers for tests in your Rust project.

rustainers rustainers is a simple, opinionated way to run containers for tests. TLDR More information about this crate can be found in the crate docum

wefox 4 Nov 23, 2023
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

?? This program is designed to translate text into the correct layout when typing is incorrect. ?? Example ghbdtn -> привет Just (by default) pressing

Gest Se 5 Jan 26, 2023
A simple program for C program IO testing. Written in Rust

A simple program for C program IO testing. Written in Rust, using concurrency to speed up valgrind testing. Make sure to update settings at your first run of the program!

null 1 Feb 22, 2022
Solstice Flare - CLI Tool for interacting with Solana

?? WIP: This tool is in active development, and can experience breaking changes. For safety, it currently operates on Devnet by default Flare Flare is

Anthias Labs 4 Feb 26, 2024
A cat(1) clone with syntax highlighting and Git integration.

A cat(1) clone with syntax highlighting and Git integration. Key Features • How To Use • Installation • Customization • Project goals, alternatives [中

David Peter 38.9k Jan 8, 2023
A Rust CLI template on Gitpod

This is a Rust CLI template configured for ephemeral development environments on Gitpod.

Oliver Gibbs 2 Jan 14, 2022
A template for starting a dioxus project to be used with dioxus-cli

A template for starting a dioxus project to be used with dioxus-cli

Dioxus 6 Nov 25, 2022
BoilerFiles is a CLI for downloading your boilerplate files from a public GitHub template repo.

BoilerFiles Available on crates.io. BoilerFiles is a CLI for downloading your boilerplate files from a public GitHub template repo. Features Are you t

Jan Müller 4 Oct 1, 2022
A high-performance WebSocket integration library for streaming public market data. Used as a key dependency of the `barter-rs` project.

Barter-Data A high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges - batteries includ

Barter 23 Feb 3, 2023
Experimental integration of `fedimint-client` with the Leptos web frontend framework

CAUTION: highly experimental, the Database implementation is likely horribly broken Fedimint Client built with Leptos This repo contains a proof-of-co

null 3 Aug 27, 2023
Leptos integration with Golden Layout.

Leptos Golden Layout Leptos integration with Golden Layout. This has many features missing but covers the basics for integrating leptos with golden la

Ari Seyhun 3 Oct 23, 2023
Configurable HTML/Vue/Svelte/Jinja/Twig formatter, with dprint integration.

markup_fmt markup_fmt is a configurable HTML/Vue/Svelte/Jinja/Twig formatter. Notes for Vue and Svelte Users This formatter provides some options such

Pig Fang 17 Nov 15, 2023
Wrapper over MMTk to simplify integration with runtimes: thread management system, object header, root scanning

vmkit A library which provides bunch of building blocks to make a VM in Rust. Feautures MMTK integration out of the box Thread management provided by

null 3 Aug 31, 2024
A lightweight and super fast cli todo program written in rust under 200 sloc

todo A lightweight and super fast cli todo program written in rust under 200 sloc installation AUR package: todo-bin use cargo build --release to comp

sioodmy 243 Dec 24, 2022