3

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.

https://github.com/coral-xyz/anchor/blob/master/tests/bpf-upgradeable-state/programs/bpf-upgradeable-state/src/lib.rs

Error due to trying to use this address in the test

const programDataAddress = findProgramAddressSync(
    [program.programId.toBytes()],
    new anchor.web3.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111")
  )[0];

https://github.com/coral-xyz/anchor/blob/master/tests/bpf-upgradeable-state/tests/bpf-upgradable-state.ts#L15

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

4

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

to:

solana_sdk::bpf_loader_upgradeable::id()

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.

1

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.