1

This error came back in 2023 after the previous post here from 2022 August.

anchor run test1 now gave me Error: failed to get recent blockhash: TypeError: fetch failed !!?? That is because it does not run a local network then deploy my programs... So that is new in Anchor 0.29.0

My Anchor.toml

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

test1 = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/zero-copy.ts"

anchor test -h gave me --run <RUN> Run the test suites under the specified path

When I ran anchor test --run ./tests/zero-copy.ts, Anchor still ran all tests!!??

Workaround: change the Anchor.toml test path:

test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/zero-copy.ts"

But this is a workaround, not the best solution...

How can I add multiple tests in [script] then run one of the tests?

1 Answer 1

2

anchor run test1 now gave me Error: failed to get recent blockhash: TypeError: fetch failed !!?? That is because it does not run a local network then deploy my programs... So that is new in Anchor 0.29.0

The command anchor test does three things:

  1. Builds the program.
  2. Deploys the program, spinning the localnet validator if needed.
  3. Runs the test script.

Running anchor run <script> only does step 3 and so requires you to have run the anchor build and anchor deploy commands beforehand. If you're testing on localnet it also requires that you spin up a test validator between the build and deploy steps and keep it active while you run your script.

The solution to this is running anchor localnet to perform the build, start-validator, and deploy steps before you run your script.

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.