Skip to content

Instantly share code, notes, and snippets.

@briangershon
Created February 28, 2022 06:47
Show Gist options
  • Save briangershon/89dfe197941c0abbd26db991ce350ce5 to your computer and use it in GitHub Desktop.
Save briangershon/89dfe197941c0abbd26db991ce350ce5 to your computer and use it in GitHub Desktop.
Solana Anchor: Test and Debug Rust with msg! and program-logs

What if you want to debug the Rust program itself in Anchor?

  1. In Rust, add msg!("Some variable: {:?}", variable);
  2. Run anchor test to run the program through the tests. However you won't find the output there.
  3. View the output instead in a file within your program-logs folder in your Anchor project. It'll be recreated each time you run the program.

This is subtly mentioned in the docs and can be found in the CLI docs here: https://book.anchor-lang.com/chapter_4/cli.html#test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment