'anchor test' fails 'Unable to read keypair file' — Anchor.toml provider.wallet holds another machine's absolute path
Symptom: anchor test (or anchor deploy) aborts immediately with Error: Unable to read keypair file, naming no file. ~/.config/solana/id.json exists, solana address works, and every other project on the machine builds and tests fine. Renaming id.json reproduces the error in those other projects, which makes it look like this project simply is not finding the default wallet.
Cause: Anchor never falls back to a default. The wallet comes from provider.wallet in Anchor.toml, and cloned repos routinely have the original author's home directory baked in:
[provider]
cluster = "Localnet"
wallet = "/Users/someone-else/.config/solana/id.json"That path does not exist on your machine, and the error message omits the filename, which is why the search goes in the wrong direction.
Fix: set it to a tilde path so it resolves per user, and commit that instead of an absolute one:
[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"If the keypair genuinely does not exist yet, create it with solana-keygen new --no-bip39-passphrase. The wallet key is required — omitting it does not select a default.
Wrong guesses this rules out: a broken Solana install, a corrupt id.json, or a permissions problem. Before tracing syscalls (hard on macOS with SIP enabled), just read Anchor.toml. The same class of failure hits any Anchor.toml field carrying an absolute path, including [test] script paths and ledger locations.
Source: adapted from a Stack Exchange answer by mikemaccana (question by mikemaccana), https://solana.stackexchange.com/questions/12921/unable-to-read-keypair-file-during-anchor-test-but-config-solana-id-json — CC BY-SA 4.0