Running anchor test for the bpf-upgrade-state example program while on localnet results in the following error

Error: AnchorError caused by account: program_data. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.


Error due to trying to use this address in the test

const programDataAddress = findProgramAddressSync(
    new anchor.web3.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111")


anchor test works fine if on devnet though

The test runs on localnet if I complete the following steps as a workaround:

  • run solana-test-validator
  • then anchor deploy
  • then anchor run test

Found these that seem related:

Could anyone explain why directly running anchor test for this example does not work on localnet?

1 Answer 1


This is expected behavior. If you just run anchor test against a local network, it will start a new test validator using the --bpf-program argument with solana-test-validator, which defaults to the non-upgradeable loader.

If you want to change this behavior, you literally just need to change this line: https://github.com/solana-labs/solana/blob/00ba78bd2d2c3a40d99bb697a5d8bfbac4f62e70/validator/src/bin/solana-test-validator.rs#L210



Please feel free to put in a PR for this! Since the non-upgradeable loader is mostly unusable, this change makes a lot of sense.


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.