> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Тестування програм

> Завантаження та тестування власних програм Solana за допомогою LiteSVM

Тестування власної програми Solana означає завантаження її скомпільованого `.so`-файлу в
SVM, налаштування акаунтів, яких вона очікує, і надсилання їй інструкцій.
LiteSVM виконує все це в межах процесу — validator не потрібен. Рекомендуємо
генерувати клієнти програм за допомогою
[Codama JS Renderer](https://github.com/codama-idl/renderers-js), щоб мати
доступ до сумісного плагіна Kit.

## Завантаження програми

<Note>
  Імпорт `@my-program/sdk` — це заглушка для клієнта, згенерованого Codama
  для вашої власної програми. Ці два приклади є ілюстративними шаблонами: перед запуском замініть
  назви плагіна, інструкції та акаунта на власні.
</Note>

```typescript
import { createClient, address, generateKeyPairSigner } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";
import { myProgramPlugin } from "@my-program/sdk";
import * as fs from "node:fs";

const mySigner = await generateKeyPairSigner();
const client = createClient()
  .use(signer(mySigner))
  .use(litesvm())
  .use(myProgramPlugin());

// Configure for program testing
client.svm
  .withSigverify(false)
  .withBlockhashCheck(false)
  .withSysvars()
  .withBuiltins();

// Load program from .so file
const programId = (await generateKeyPairSigner()).address;
const soPath = "/path/to/target/deploy/my_program.so";

if (fs.existsSync(soPath)) {
  client.svm.addProgramFromFile(programId, soPath);
  console.log("Program loaded:", programId);

  // Verify program account
  const programAccount = client.svm.getAccount(programId);
  if (programAccount.exists) {
    console.log("  Executable:", programAccount.executable);
    console.log("  Data size:", programAccount.data.length, "bytes");
  }
} else {
  console.log("Program file not found:", soPath);
  console.log("Build with: cargo build-sbf");
}
```

## Повне налаштування тесту програми

<Note>
  Ілюстративний шаблон: `myProgramPlugin`, `testInstruction` і `myAccount`
  походять із вашого власного згенерованого клієнта.
</Note>

```typescript
import { createClient, address, generateKeyPairSigner, lamports } from '@solana/kit';
import { litesvm } from '@solana/kit-plugin-litesvm';
import { signer } from '@solana/kit-plugin-signer';
import { myProgramPlugin } from '@my-program/sdk';
import * as fs from 'node:fs';

const mySigner = await generateKeyPairSigner();
const client = createClient()
    .use(signer(mySigner))
    .use(litesvm())
    .use(myProgramPlugin());

client.svm
    .withSigverify(false)
    .withBlockhashCheck(false)
    .withSysvars()
    .withBuiltins()
    .withPrecompiles()
    .withTransactionHistory(100n);

// Load program
const programId = (await generateKeyPairSigner()).address;
const soPath = '/path/to/target/deploy/my_program.so';

if (fs.existsSync(soPath)) {
    client.svm.addProgramFromFile(programId, soPath);
}

// Set up any required data accounts
const dataAccountAddress = (await generateKeyPairSigner()).address;
const minBalance = client.svm.minimumBalanceForRentExemption(100n);
client.svm.setAccount({
    address: dataAccountAddress,
    data: new Uint8Array(100),
    executable: false,
    lamports: lamports(minBalance),
    programAddress: programId,
    space: 100n,
});

// Send the transaction
await client.myProgram.testInstruction({ /* args */ }).sendTransaction();

// Verify state changes
const updatedAccount = client.myProgram.myAccount.fetch(dataAccountAddress);
// assert on decoded account
```

## Використання програм за замовчуванням

Клієнт `litesvm()` уже має завантажені стандартні програми: System
Program, завантажувачі BPF, Vote, Compute Budget, Stake, Address Lookup Table,
Token, Token-2022, Associated Token Account, Memo, а також прекомпайли ed25519, secp256k1
та secp256r1. Завантажуйте лише ті інші програми, які викликає ваш тест:

```typescript
const mySigner = await generateKeyPairSigner();
const client = createClient().use(signer(mySigner)).use(litesvm());

// Token, Token-2022, Associated Token Account and Memo are already loaded.
// Add any other program your program calls from its .so file
client.svm.addProgramFromFile(otherProgramId, "/path/to/other_program.so");
```

<Info>
  Зберіть свою програму Solana за допомогою `cargo build-sbf`, щоб згенерувати `.so`-файл.
</Info>

Схема завжди однакова:

1. **Завантаження програми**: використайте `addProgramFromFile`, щоб завантажити скомпільовані програми, і
   імпортуйте myProgramPlugin() зі свого клієнта
2. **Конфігурація**: за потреби змініть налаштування, як-от перевірку підписів;
   sysvars, вбудовані програми, прекомпайли та програми за замовчуванням уже
   завантажені
3. **Налаштування акаунтів**: заздалегідь заповніть акаунти даних за допомогою `setAccount`
4. **Надсилання**: використовуйте `client.myProgram.testInstruction({ /* args */ }).sendTransaction()` —
   без ручного створення транзакцій
5. **Перевірка**: перевірте стан акаунта після виконання
   (`client.myProgram.myAccount.fetch`)

Коли цей шаблон запрацює, ви зможете розширити його до повного набору тестів,
додаючи більше інструкцій і перевірок.
