DEV Community

Cover image for devnet-fixtures: funded wallets, mints and token balances from a YAML file
Abdeldjalil Chougui
Abdeldjalil Chougui

Posted on Originally published at abdeldjalilchougui.biz

devnet-fixtures: funded wallets, mints and token balances from a YAML file

An end-to-end test for a Solana app needs a starting state before it can check anything. There must be a wallet with some SOL to pay fees, a second wallet to receive, a mint with known decimals, token accounts, and balances the test can assert on. Most projects build that state with a setup script: a few airdrops, a mint creation, some mintTo calls, then a list of addresses copied into environment variables.

Those scripts tend to break in the same places. Devnet airdrops are rate limited and fail at random. Running the script twice creates a second mint or doubles the balances. And the addresses change on every run, so the test config has to be regenerated each time.

devnet-fixtures is a small CLI for CI pipelines and local end-to-end tests that replaces the script with a description. You write the wallets, mints and token balances you need in YAML. It creates them on a cluster, then prints their addresses as .env lines or JSON.

Two warnings from the README come first. The project is not audited, and it is for devnet, testnet and localnet only: it refuses mainnet, both by URL and by checking the RPC's genesis hash. It also writes throwaway keypairs to disk, so never fund them with real assets, and keep keysDir out of git.

What it does

The spec is one YAML file:

cluster: ${FIXTURES_CLUSTER:-localnet}   # localnet | devnet | testnet | URL
keysDir: .fixtures                        # keypairs saved here (0600), gitignored
# funder: ./funder.json                   # used when airdrops fail (devnet rate limits)
airdrop: { retries: 5, delayMs: 1000, maxSolPerRequest: 2 }
accounts:
  - { name: alice, sol: 2 }
  - { name: bob, sol: 1 }
  - { name: carol }
mints:
  - name: usdc
    decimals: 6
    authority: alice
    mintTo:
      - { owner: alice, amount: 1000 }
      - { owner: bob, amount: 12.5 }
    atas: [carol]
  - name: points
    decimals: 0
    token2022: true
    authority: bob
    mintTo: [{ owner: carol, amount: 42 }]
Enter fullscreen mode Exit fullscreen mode

Running it against a local validator prints the result:

$ devnet-fixtures examples/fixtures.yaml --rpc http://127.0.0.1:8899 --prefix e2e
E2E_RPC_URL=http://127.0.0.1:8899
E2E_ALICE_PUBKEY=FnJm4NKB…
E2E_ALICE_KEYPAIR=/…/.fixtures/alice.json
E2E_USDC_MINT=93g3h43j…
E2E_USDC_DECIMALS=6
E2E_USDC_TOKEN_PROGRAM=TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
E2E_USDC_ATA_BOB=AFjfVXrH…
E2E_POINTS_MINT=2egvfGXW…
...
Enter fullscreen mode Exit fullscreen mode

It never prints secret keys. The output contains public keys and keypair file paths only. A test that needs to sign as alice loads the file at E2E_ALICE_KEYPAIR.

It is idempotent. Keypairs are reused from keysDir. Mints are remembered per cluster genesis hash in keysDir/state.json, and reused while they still exist. SOL balances and token balances are topped up to the target, never added on top. A second run against the same cluster makes no transactions, except to top up SOL that was spent on fees.

Airdrops are handled with care. Each request is split into chunks of maxSolPerRequest and retried with exponential backoff (delayMs × 2^n). If airdrops still fail and a funder keypair is configured, the tool sends a System transfer from the funder instead. Token operations, meaning mint creation, ATAs and minting, are retried in the same way.

Amounts are exact. Values in mintTo are UI amounts, such as 12.5, and they are converted exactly to base units with no float drift.

SPL Token and Token-2022. A mint is created with the classic token program by default, or with Token-2022 when the spec says token2022: true. The output tells the tests which program owns each mint.

How to use it

You need Node.js 20 or later. Clone and build:

git clone https://github.com/AbdeldjalilChougui/devnet-fixtures
cd devnet-fixtures
pnpm install && pnpm build
Enter fullscreen mode Exit fullscreen mode

Then run it from the checkout:

node dist/cli.js examples/fixtures.yaml --rpc http://127.0.0.1:8899   # with solana-test-validator running
node dist/cli.js spec.yaml --format json --out fixtures.json
node dist/cli.js spec.yaml --github-env                               # also append to $GITHUB_ENV
Enter fullscreen mode Exit fullscreen mode

The first command needs solana-test-validator running locally. The second writes JSON to a file instead of .env lines on standard output. The third also appends the variables to $GITHUB_ENV, so later steps of a GitHub Actions job see them without any glue code.

In GitHub Actions, the job has three steps. This is the README's sketch, adapted to a tool that was cloned and built into devnet-fixtures/ in an earlier step:

- run: solana-test-validator --reset --quiet &
- run: node devnet-fixtures/dist/cli.js test/fixtures.yaml --rpc http://127.0.0.1:8899 --github-env
- run: pnpm test:e2e      # reads E2E_* env vars
Enter fullscreen mode Exit fullscreen mode

The cluster field accepts localnet, devnet, testnet or a URL, and it supports ${VAR:-default} expansion. That lets the same spec run against a local validator on a laptop and against devnet in CI, with one environment variable to switch.

Things to know

  • Not audited, and never for mainnet. The tool refuses a mainnet URL, and it also refuses when the RPC answers with the mainnet genesis hash, so pointing a custom URL at mainnet does not get around the check.
  • The keypairs are throwaway. They are saved in keysDir with 0600 permissions. Treat them as test material: never send real assets to them, and add the directory to .gitignore.
  • One mint authority per mint, no freeze authority. Token-2022 extensions are not configurable.
  • A harmless warning. @solana/spl-token prints "bigint: Failed to load bindings" when its optional native build is disabled. The README says this can be ignored.
  • What was tested. The 14 unit tests never touch the network. They cover spec parsing and validation, ${VAR:-default} expansion and refusing mainnet by URL. They run the main logic against an in-memory FakeChain to check chunked airdrops, backoff timings, the funder fallback, failure without a funder, idempotent re-runs, refusing a mainnet genesis hash, 0600 keypair files, and env output that contains no secrets. The RPC layer is tested against a mocked JSON-RPC fetch.
  • One manual run. The example spec was also run by hand against solana-test-validator (Agave 4.2). It created 3 funded wallets, an SPL mint and a Token-2022 mint, 4 ATAs and the balances, and a second run reused everything. The README reports no run against public devnet.

Why I built it

Test setup for a Solana project is repetitive, and the usual script has three weak points. It depends on airdrops that fail under rate limits. It is not safe to run twice. And it leaves the test code to find out which addresses were created.

A declarative spec answers all three. Because the tool knows the target state, it can compare it with the cluster and do only what is missing, which is what makes a second run free. Because it owns the airdrop step, it can chunk, back off and fall back to a funder in one place instead of in every project's script. And because it prints addresses under stable names, the tests read E2E_USDC_MINT and do not care how the mint came to exist.

The mainnet refusal and the rule about never printing secret keys come from the same idea. A tool that creates keypairs and runs inside CI logs should be hard to misuse by accident.

Get the code

The CLI, the example spec and the tests are on GitHub: https://github.com/AbdeldjalilChougui/devnet-fixtures. It is MIT licensed. Issues and pull requests are welcome.


Originally published at abdeldjalilchougui.biz.

Top comments (0)