4

I'm new to Anchor and Solana program development. I've done some reading on debugging Solana programs running in local by using solana-test-validator and solana logs.

However, I noticed when I'm running unit tests with Anchor that it tries to fire up a new validator in my local and so anchor test cannot be run (on the same port) while I have a validator running.

Naturally, I shut down my validator when I'm running these tests but that also means I'm no longer running solana logs.

I noticed that Anchor outputs a directory:

.anchor/test-ledger

I'd like to better understand how this folder works.

Does it contain the output I would otherwise be getting by running solana logs?

What other important information does it contain that Solana program developers commonly use for debugging?

More generally, would anyone be able to provide an overview of the folder's contents? I have attached a screenshot of this test-ledger directory for reference.

Contents of .anchor/test-ledger directory

1 Answer 1

4

Before exiting, anchor test will write log files out to .anchor/program-logs. These log files will contain the transaction logs for every transaction executed during the previous test run, but only transactions from programs that are in the repo you're testing.

If you simply need to read the state of the blockchain, the easiest way is to start up the localnet again and probe it with tools like the Solana CLI, or even https://explorer.solana.com with a custom URL set to http://localhost:8899.

Edit:

To address your more general concern of the contents of the test-ledger folder, most all of it is not necessary to interact with during normal Solana program development.

All of the best tools for introspection of Solana blockchain state are tools that send RPC requests to clusters, including requests to local test validators on localhost. I've not heard of anything helpful for Solana devs reading the data in test-ledger directly, but I've also never heard of any Solana devs feeling like it was really necessary for them.

If you muck around deeply enough and manage to break things in utterly spectacular ways as I have before, you may need to read the log file softlinked to test-ledger/validator.log. But I think it's kind of a rare happenstance. Even so, nice to know that file is there.

Anchor comes with some ways of controlling your test validator, documented here. https://book.anchor-lang.com/anchor_references/anchor-toml_reference.html

Or if you prefer, you can run your own validator with solana-test-validator configuring it how you want through command-line flags, then run anchor test with --skip-local-validator.

For a deep dive into how solana-test-validator works, its source code is here: https://github.com/solana-labs/solana/blob/master/validator/src/bin/solana-test-validator.rs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.