5

I'm curious what the recommended way is to provision an instance of solana-test-validator with a 'known state', consisting of a few accounts and mints.

We use this 'known state' in our local development setups and on CI, and having this in place really helps us develop quickly, we are mainly looking for a more elegant way to achieve this goal.

Currently, we are using a manual solution that's been implemented in a shell script. We basically start the validator, push it to the background, then execute a bunch of commands to bring this instance in our desired state.

I'm curious if there are more elegant ways to do this. Ideally, more declarative than imperative. What do other people use for this?

1

1 Answer 1

4

You can load program and account fixtures into the validator using these command line arguments.

--bpf-program

Use this to load a .so file as the validator starts up.

solana-test-validator --bpf-program \
  PUBKEY_OR_PATH_TO_KEYPAIR \
  path/to/program.so

--account

Use this to load account data from a JSON file.

solana-test-validator --account \
  path/to/account.json

You can produce this JSON file from a live account using:

solana account \
  PUBKEY \
  --output json

--clone

Though inadvisable if you aim to have reproducible tests, you can also clone an account, by address, from a live cluster.

solana-test-validator --clone \
  ACCOUNT_PUBKEY

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.