Skip to main content
6 votes
Accepted

How to run anchor tests partially?

You likely have something like this in your Anchor.toml file: [scripts] test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" Change the wildcard (*) character to specify ...
Ademola's user avatar
  • 3,833
6 votes
Accepted

How to use the Anchor's `features = ["cpi"]`?

The cpi feature simply toggles whether the cpi module is generated or not. Probably the most significant generated item is the cpi::<your instruction>() function that takes a CpiContext and: ...
sohrab's user avatar
  • 1,781
5 votes
Accepted

How do i get current slot number onchain?

Through the clock sysvar use solana_sdk::clock::Clock; let slot = Clock::get()?.slot;
Arowana's user avatar
  • 2,243
5 votes
Accepted

Anchor: How can I check specific Anchor Error Codes are caught in my test script if they are expected?

This is the general way of testing against errors in Anchor TS it('Expects Error', async () => { try { const tx = await program.methods.testErr().rpc(); assert.ok(false); ...
Muhammed Adil's user avatar
5 votes
Accepted

anchor test: Error: Your configured rpc port: 8899 is already in use

This happens only when you have a test validator running because anchor test runs its own validator as well. When it tries it sees that your validator is already listening on port 8899 and crashes. ...
Buzzec's user avatar
  • 534
5 votes
Accepted

Anchor test fails on Fedora

I finally fixed it by downgrading to openssl1.1 using sudo yum install openssl1.1 And anchor test finally works!
Kirima's user avatar
  • 155
5 votes

How to fix solana-test-validator Illegal instruction (core dumped) error even after building from source?

If you already tried all this and still getting Illegal instruction error, you probably need to change some compilation variables. In my case, the problem was the old CPU (older than 2013) and fixed ...
nicoeft's user avatar
  • 141
5 votes
Accepted

Anchor test can't start validator, but solana-test-validator works fine

Run solana-test-validator in a separate terminal. Then run anchor test --skip-local-validator whenever you wanna test your program. You can create an alias if this gets tedious. e.g. alias anchortest=&...
vicyyn's user avatar
  • 4,095
5 votes
Accepted

Creating Address Lookup Table in localnet fails with "invalid instruction data" error

EDIT: The error you're getting is being thrown by this check. The instruction to create a lookup table requires the client to pass in a recent slot as an argument, and checks that that slot is valid(...
Ademola's user avatar
  • 3,833
4 votes
Accepted

How to read the contents of Anchor's test-ledger directory

Before exiting, anchor test will write log files out to .anchor/program-logs. These log files will contain the transaction logs for every transaction executed during the previous test run, but only ...
HelmetFace's user avatar
  • 1,747
4 votes

"Error: No such file or directory (os error 2)" Error from Anchor Test

For multi-program projects, if one of them is a dummy program, you need something like this. The reason is anchor is likely looking for the idl file for this program and it doesn't get generated if ...
Mocha's user avatar
  • 103
4 votes
Accepted

How to convert number to buffer in Anchor TS test

The seeds shoud be: const [gamePDA] = await PublicKey.findProgramAddress( [ Buffer.from("game"), user.publicKey.toBuffer(), new anchor.BN(fPlayer.gameCount).toArrayLike(Buffer, ...
James's user avatar
  • 309
4 votes
Accepted

AnchorError caused by account: program_data. Error Code: AccountNotInitialized

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 ...
Jon C's user avatar
  • 15.6k
4 votes

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete

Can you do }).rpc({ skipPreflight:true }) This will not simulate the tx and you could get better errors
Pratik.js's user avatar
  • 1,632
4 votes

problem with running tests for every program in local env

Program AQDdxLFXQk6eBsVEW1HiHKKH77QMzSK2vMCbjMPhERHx failed: Invoked an instruction with data that is too large (12884933564 > 10240) This means you are compiling with the wrong cli version. Try 1....
Jonas H.'s user avatar
  • 5,767
4 votes

is there a limit to the number of functions that can consume anchor Context?

The error has nothing to do with the context. You can use the same context in as many ixs as you like. The error here states that the program can't deserialize the instruction which means that the ...
0xShuk's user avatar
  • 1,939
4 votes

is there a limit to the number of functions that can consume anchor Context?

Your error is not because of a limit on the number of functions but due to this: #[instruction(bump: u8)]. Passing the instruction’s arguments with the #[instruction(..)] attribute makes anchor look ...
Serban's user avatar
  • 1,296
4 votes
Accepted

What does anchor error `2003` mean

These are the types of constraints defined using this syntax #[account(constraint = <expr>)]. From the anchor documentation: Constraint that checks whether the given expression evaluates to true....
Serban's user avatar
  • 1,296
3 votes
Accepted

How to create an associated Token Account in anchor, I'm getting the following error: "insufficient account keys for instruction"

This is a shot in the dark, but are you using an old version of the Solana tools by any chance? There may be a mismatch between the validator and the instruction you're creating. Be sure to have at ...
Jon C's user avatar
  • 15.6k
3 votes
Accepted

How can I set a panic in anchor?

First, you need to create an error, the message will be sent when the error is thrown #[error_code] pub enum ErrorCode { #[msg("This is an ERROR!")] MyCustomError, } then in your ...
vicyyn's user avatar
  • 4,095
3 votes
Accepted

what is the relation between Signers & Wallets in testing

What is the difference between provider.wallet.Pubkey , provider.Pubkey and anchor.web3.Keypair.generate().publicKey ... A crypto wallet is a device or application that stores a collection of keys ...
vicyyn's user avatar
  • 4,095
3 votes

Error: Your configured rpc port: 8899 is already in use

If you're running anchor test and you have a local validator already running, you can use the following command to skip the validator startup: anchor test --skip-local-validator Otherwise you can kill ...
Jacob Creech's user avatar
  • 3,854
3 votes

How to use the VSCode debugger when testing a Solana Anchor program

Not that I know of. I do most of my debugging with the msg! macro and then inspect the program logs. See also this helpful Gist: https://gist.github.com/briangershon/89dfe197941c0abbd26db991ce350ce5
Sebastian Dine's user avatar
3 votes
Accepted

Error when creating PDA: Transaction simulation failed: Error processing Instruction 0: Program failed to complete

The problem is in this line: vault.bump = *ctx.bumps.get("house-vault").unwrap(); You have to use the name of the account, not the seed to get the bump. So the correct code in your case ...
0xShuk's user avatar
  • 1,939
3 votes

Globally installed anchor version is not correct

I uninstalled my old anchor binary. There were a couple of steps I tried first: npm uninstall anchor-cli This would work if I install via npm. I did not. cargo uninstall anchor This would work if I ...
Jacob Creech's user avatar
  • 3,854
3 votes

Add a counter to track NFTs minted

You are trying to initialize MintingAccount every time the mint function is called, this might be a cause for the error.
frawd's user avatar
  • 391
3 votes
Accepted

Insufficient lamports but my balance already is 7 SOL

If you are testing using anchor test, try checking the Anchor.toml file and replace localnet to the cluster you're trying to test on [programs.localnet] my_program = "...
john's user avatar
  • 7,445
3 votes

Don't understand why I am getting errors: custom attribute panicked - and - unexpected closing delimiter: `)`

Does this code originate from somewhere else? There's a few things wrong with it. Firstly the #[access_control] macro usually wraps a function i.e: fn check() { ...... } and then : #[access_control(...
Ademola's user avatar
  • 3,833
3 votes

How do I pass in `Option<MyEnum>` as an argument when testing

I cannot replicate the issue. I was able to pass null when I did not have an argument to pass. Happy to take a look at your full code if you have a GH. Here's what I tested (and anchor test ran fine): ...
AMilz's user avatar
  • 1,536
3 votes
Accepted

Account data is not persisting for a really simple instruction

Add mut to pub lock: Account<'info, Lock>, to mark the account as writable: #[account( mut, //<--- add this seeds = [ lock.locker.as_ref(), owner.key()...
john's user avatar
  • 7,445

Only top scored, non community-wiki answers of a minimum length are eligible