1

I have a Solana smart contract (written with Anchor) that interacts with Pyth and Chainlink Solana oracles. In EVM world, we would either redeploy the necessary contracts locally in the test start-up and configure them ourselves or perform fork-testing (forking the state of the mainnet and running tests independently locally).

Problems with forking:

  • I've found this answer on how to "fork" Solana programs and accounts, but I am not sure if I can configure it so the anchor test runner starts up and loads the accounts for me.
  • I am not sure how to interact with the program from JS after it's in my local network. I don't have the IDL available.

Problems with setting things up manually:

  • I've found this answer on how to retrieve the on-chain programs and insert them inside the anchor test runner, but I am not sure how to interact with the program from JS after it's in my local network. I don't have the IDL available.

If anyone has had the experience of writing localnet tests for either of these oracles or any other external program, please share your experience.

1 Answer 1

2

I was able to solve the issue by making use of Anchor.toml [test.validator.clone] attribute (docs)

  1. First I clone the necessary program solana program dump --url devnet HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny chainlink.so
  2. Update the Anchor.toml file:
# Because I am copying many accounts in my tests, I need to wait quite a long time
[test]
startup_wait = 100000

# The cluster from which I am cloning the accounts
[test.validator]
url = "https://api.devnet.solana.com"

# The external programs I want to deploy
[[test.genesis]]
address = "<chainlink validator address>"
program = "chainlink.so"

# Addresses that I want to clone (e.g. price feed account from chainlink or pyth)
[[test.validator.clone]]
address = "<address of account I'm using in my tests>"

[[test.validator.clone]]
address = "<address of account I'm using in my tests>"

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.