Solana.TestValidator (Solana v0.2.0) View Source

A Solana Test Validator managed by an Elixir process. This allows you to run unit tests as if you had the solana-test-validator tool running in another process.

Requirements

Since Solana.TestValidator uses the solana-test-validator binary, you'll need to have the Solana tool suite installed.

How to Use

You can use the Solana.TestValidator directly or in a supervision tree.

To use it directly, add the following lines to the beginning of your test/test_helper.exs file:

alias Solana.TestValidator
{:ok, validator} = TestValidator.start_link(ledger: "/tmp/test-ledger")
ExUnit.after_suite(fn _ -> TestValidator.stop(validator) end)

This will start and stop the solana-test-validator before and after your tests run.

In a supervision tree

Alternatively, you can add it to your application's supervision tree during tests. Modify your mix.exs file to make the current environment available to your application:

def application do
  [mod: {MyApp, env: Mix.env()}]
end

Then, adjust your application's children depending on the environment:

defmodule MyApp do
  use Application

  def start(_type, env: env) do
    Supervisor.start_link(children(env), strategy: :one_for_one)
  end

  defp children(:test) do
    [
      {Solana.TestValidator, ledger: "/tmp/test_ledger"},
      # ... other children
    ]
  end

  defp children(_) do
    # ...other children
  end
end

Options

You can pass any of the long-form options you would pass to a solana-test-validator here.

For example, to add your own program to the validator, set the bpf_program option as the path to your program's build artifact. See Solana.TestValidator.start_link/1 for more details.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Gets the state of a Solana.TestValidator process.

Starts a Solana.TestValidator process linked to the current process.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Gets the state of a Solana.TestValidator process.

This is useful when you want to check the latest output of the solana-test-validator.

Starts a Solana.TestValidator process linked to the current process.

This process runs and monitors a solana-test-validator in the background.

Options

  • :bind_address - The default value is "0.0.0.0".

  • :bpf_program

  • :clone

  • :config - The default value is "/home/derek/.config/solana/cli/config.yml".

  • :dynamic_port_range - The default value is "1024-65535".

  • :faucet_port - The default value is 9900.

  • :faucet_sol - The default value is 1000000.

  • :gossip_host - The default value is "127.0.0.1".

  • :gossip_port

  • :url

  • :ledger - The default value is "test-ledger".

  • :limit_ledger_size - The default value is 10000.

  • :mint

  • :rpc_port - The default value is 8899.

  • :slots_per_epoch

  • :warp_slot

Stops a Solana.TestValidator process.

Should be called when you want to stop the solana-test-validator.