0
#[test]
fn test_create_user_pda() {
    let wallet = solana_sdk::signer::keypair::Keypair::new();

I want to use this wallet as a payer, how do I make an airdrop in a test?

Attempt to debit an account but found no record of a prior credit

2 Answers 2

0

You cant fund a wallet and use it to sign the same tx its being funded in.

0

For those who need this functionality, the only solution that actually worked for me was to spawning a new process executing solana airdrop command inside a test:

Command::new("solana")
        .arg("airdrop")
        .arg("--commitment")
        .arg("finalized")
        .arg("1")
        .arg(format!("{}", wallet_pubkey.to_string()))
        .spawn()
        .unwrap()
        .wait()
        .unwrap();

--commitment finalized will take more time than normally, but it's essential - otherwise we move on before the account is created.

For whatever reason, calling airdrop via RPC client with the same commitment config didn't actually wait for the transaction to finalize.

1
  • Calling airdrop with the RPC client returns a signature -- you then need to call confirm_transaction with that signature.
    – Jon C
    Commented Oct 30 at 22:40

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.