4

Trying to learn anchor dev, following soldev.app. I have a problem, when I run anchor test, this is the error I get:

Unable to get the latest blockhash. The test validator does not look started. Check .anchor/test-ledger/test-ledger-log.txt for errors. Consider increasing [test.startup_wait] in Anchor.toml.

Ledger location: .anchor/test-ledger
Log: .anchor/test-ledger/validator.log
Initializing...
Error: failed to start validator: Failed to create ledger at .anchor/test-ledger: blockstore error

When I try to run solana-test-validator it works. In the Anchor.toml file cluster is set to localnet.

1
  • As the error says, Check .anchor/test-ledger/test-ledger-log.txt for errors. - please look inside the file to get a detailed error message!
    – mikemaccana
    Commented Jun 3 at 15:01

2 Answers 2

5

Run solana-test-validator in a separate terminal.

Then run anchor test --skip-local-validator whenever you wanna test your program.

You can create an alias if this gets tedious. e.g. alias anchortest="anchor test --skip-local-validator

2
  • 2
    The flag --skip-local-validator is so badly named because you pass it to anchor test to skip local validator, and yet anchor test requires solana-test-validator to run (in a separate terminal). Sounds like a prank! HAHA. Commented Feb 11, 2023 at 15:48
  • I'm joining to @Nawaz There must be a self validator in test environment. Commented Sep 8, 2023 at 13:58
0

In my case I had to add the following to my Anchor.toml file, above [scripts]:

[test]
startup_wait = 20000

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.