7

enter image description here

My tests all run successfully, but at the end of my test execution, I get error Error: No such file or directory (os error 2).

On the anchor discord, I found a thread from February detailing the same issue I had discord link. I recently also added another program to my anchor project, similar to the user who posted on discord, but I only saw this error after upgrading to anchor anchor-cli 0.25.0 and solana solana-cli 1.10.32.

My Anchor.toml has the following. I get the error both in CI and locally, and both environments have ts-mocha and yarn installed.

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 --parallel"

Edit: Looks like it might be a race condition? Removing the parallel flag I now get the below. So I still get the error, but it happens before the success.

Error: No such file or directory (os error 2)
✨  Done in 432.44s.

Edit: Looks like the issue is with multi-programs, or at least the way I have them setup. Removing whirlpool from the directory structure removes the issue. enter image description here

Edit: Fixed!!! I needed this in my dummy whirlpool program

#[program]
pub mod whirlpool {
    use super::*;

    // _val to ensure tx are different so they don't get rejected.
    pub fn initialize(_ctx: Context<Initialize>, _val: u64) -> Result<()> {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}
1

5 Answers 5

5

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 there is no program.

#[program]
pub mod whirlpool {
    use super::*;

    // _val to ensure tx are different so they don't get rejected.
    pub fn initialize(_ctx: Context<Initialize>, _val: u64) -> Result<()> {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}
1
  • 3
    Thank you! You can also simplify this by not using any instructions #[program] pub mod my_program {}.
    – acheron
    Commented Nov 17, 2022 at 13:45
3

In my case, I faced a similar issue due to a mismatch in Solana versions. When I initialized my Anchor project, I was using Solana version 1.18.18. However, on my other device, I had the latest version 1.18.21 installed.

Installing the specific Solana version 1.18.18 that I used when initializing the project solved the issue.

I check the solana release page, and found:

  • 1.18.18 using client SolanaLabs
  • 1.18.21 using client Agave
2

If you update your Solana CLI to use the latest Agave client as described here https://solana.com/docs/intro/installation: sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)" ,

you need to update your Solana CLI version in your Anchor.toml file.

E.g. solana_version = "2.0.15"

Reference: https://solana.com/docs/intro/installation

1

I got the same error, Error: No such file or directory (os error 2). In my case yarn and node where missing, I forgot to install them.

  • npm install --global yarn
  • sudo apt install nodejs
0

From official Solana Install instructions (https://solana.com/docs/intro/installation):

If you are on Linux or WSL and encounter the following errors when running anchor test after creating a new Anchor project, it's may be due to missing Node.js or Yarn:

Permission denied (os error 13) No such file or directory (os error 2)

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.