> ## 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.

# اختبار البرامج

> حمّل برامج سولانا المخصصة واختبرها باستخدام LiteSVM

يعني اختبار برنامج سولانا مخصص تحميل ملف `.so` المُجمَّع الخاص به في
SVM، وإعداد الحسابات التي يتوقعها، وإرسال التعليمات إليه.
يتولى LiteSVM كل ذلك داخل العملية نفسها، دون الحاجة إلى validator. نوصي بإنشاء
عملاء البرامج باستخدام
[Codama JS Renderer](https://github.com/codama-idl/renderers-js) لتتمكن من
الوصول إلى Kit Plugin متوافقة.

## تحميل برنامج

<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، والبرامج المُسبقة (precompiles) الخاصة بـ 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>
  أنشئ برنامج سولانا الخاص بك باستخدام `cargo build-sbf` لتوليد ملف `.so`.
</Info>

النمط دائمًا هو نفسه:

1. **تحميل البرنامج**: استخدم `addProgramFromFile` لتحميل البرامج المُجمَّعة
   واستورد myProgramPlugin() من عميلك
2. **الإعداد**: غيّر الإعدادات مثل التحقق من التوقيعات عند
   الحاجة؛ فمتغيرات النظام (sysvars) والبرامج المدمجة والبرامج المُسبقة (precompiles) والبرامج الافتراضية محمَّلة
   بالفعل
3. **إعداد الحسابات**: املأ حسابات البيانات مسبقًا باستخدام `setAccount`
4. **الإرسال**: استخدم `client.myProgram.testInstruction({ /* args */ }).sendTransaction()` —
   دون بناء المعاملة يدويًا
5. **التحقق**: افحص حالة الحساب بعد التنفيذ
   (`client.myProgram.myAccount.fetch`)

بمجرد أن يعمل هذا الهيكل، يمكنك بناء مجموعة اختبارات كاملة
بإضافة المزيد من التعليمات وعبارات التحقق.
