coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

`anchor test` fails for solana dev course example #2978

Open ouoabcde opened 1 month ago

ouoabcde commented 1 month ago

I'm encountering error when trying to run anchor test. Error is like below.

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

This is .anchor/test-ledger/test-ledger-log.txt file content.

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: io error: Error checking to unpack genesis archive: Archive error: extra entry found: "._genesis.bin" Regular

And here's .anchor/test-ledger/validator.log for the reference.

[2024-05-22T05:35:05.440160000Z INFO  solana_test_validator] solana-validator 1.18.14 (src:d8e08244; feat:4215500110, client:SolanaLabs)
[2024-05-22T05:35:05.440265000Z INFO  solana_test_validator] Starting validator with: ArgsOs {
        inner: [
            "solana-test-validator",
            "--ledger",
            ".anchor/test-ledger",
            "--mint",
            "91zBeWL8kHBaMtaVrHwWsck1UacDKvje82QQ3HE2k8mJ",
            "--bpf-program",
            "3Z7TVHxxEkJMUWZd7Hu4U5AXyRHTVpJQUhgkBEFq4p3Y",
            "/Users/chunjunghyun/junghyun/learnings/solana/soldev-labs/anchor-counter/target/deploy/anchor_counter.so",
        ],
    }
[2024-05-22T05:35:05.440568000Z WARN  solana_perf] CUDA is disabled
[2024-05-22T05:35:05.449354000Z INFO  solana_faucet::faucet] Faucet started. Listening on: 0.0.0.0:9900
[2024-05-22T05:35:05.449390000Z INFO  solana_faucet::faucet] Faucet account address: BdPz3T4QrYCWs6JYkmTyDCzDeGSoc2ZfwGC7hgkzYVKS
[2024-05-22T05:35:05.451028000Z INFO  solana_validator::admin_rpc_service] started admin rpc service!
[2024-05-22T05:35:05.457503000Z INFO  solana_test_validator] Feature for 41tVp5qR1XwWRt5WifvtSQyuxtqQWJgEK8w91AtBqSwP deactivated
[2024-05-22T05:35:05.461398000Z INFO  solana_ledger::blockstore] Maximum open file descriptors: 1000000
[2024-05-22T05:35:05.461580000Z INFO  solana_ledger::blockstore] Opening blockstore at ".anchor/test-ledger/rocksdb"
[2024-05-22T05:35:05.462099000Z WARN  solana_ledger::blockstore_db] Unable to detect Rocks columns: Error { message: "IO error: No such file or directory: While opening a file for sequentially reading: .anchor/test-ledger/rocksdb/CURRENT: No such file or directory" }
[2024-05-22T05:35:05.744568000Z INFO  solana_ledger::blockstore] Opening blockstore done; blockstore open took 282ms
[2024-05-22T05:35:05.752480000Z INFO  solana_metrics::metrics] metrics disabled: environment variable not found
[2024-05-22T05:35:05.752589000Z INFO  solana_metrics::metrics] datapoint: shred_insert_is_full total_time_ms=1i slot=0i last_index=31i num_repaired=0i num_recovered=0i
[2024-05-22T05:35:05.867125000Z INFO  solana_accounts_db::hardened_unpack] Extracting ".anchor/test-ledger/genesis.tar.bz2"...

My anchor version is 0.30.0, solana-cli version is 1.18.14

acheroncrypto commented 1 month ago

[2024-05-22T05:35:05.462099000Z WARN solana_ledger::blockstore_db] Unable to detect Rocks columns: Error { message: "IO error: No such file or directory: While opening a file for sequentially reading: .anchor/test-ledger/rocksdb/CURRENT: No such file or directory" }

You might want to add extra startup time in Anchor.toml:

[test]
startup_wait = 10000

If that doesn't work, you can start the test validator with solana-test-validator, and run the tests with anchor test --skip-local-validator.

ouoabcde commented 1 month ago

startup_wait setting didn't work, but anchor test --skip-local-validator works. Thank you :)

dividenconquer commented 1 month ago

By default, MacOS includes BSD tar, but solana-test-validator requires GNU tar. To install GNU tar, use Homebrew:

brew install gnu-tar

Then, add the following line to your ~/.zshrc file:

export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"

This will ensure that the GNU tar executable is in your system's PATH, allowing solana-test-validator to function correctly.

ouoabcde commented 1 month ago

By default, MacOS includes BSD tar, but solana-test-validator requires GNU tar. To install GNU tar, use Homebrew:

brew install gnu-tar

Then, add the following line to your ~/.zshrc file:

export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"

This will ensure that the GNU tar executable is in your system's PATH, allowing solana-test-validator to function correctly.

Hello @dividenconquer, I've tried your suggestion, but it's occurring same error.

binyebarwe commented 2 weeks ago

export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"

thanks this works well!