> ## 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으로 커스텀 Solana 프로그램을 로드하고 테스트하기

커스텀 Solana 프로그램을 테스트하려면 컴파일된 `.so` 파일을 SVM에 로드하고,
프로그램이 필요로 하는 계정을 설정한 뒤, 해당 프로그램에 instruction을 전송해야 합니다.
LiteSVM은 이 모든 과정을 인프로세스(in-process)로 처리하므로 validator가 필요하지 않습니다.
호환되는 Kit Plugin을 사용할 수 있도록
[Codama JS Renderer](https://github.com/codama-idl/renderers-js)로 프로그램 클라이언트를 생성하는 것을 권장합니다.

## 프로그램 로드하기

<Note>
  `@my-program/sdk` import는 Codama가 생성한 자체 프로그램용 클라이언트를 나타내는 자리 표시자입니다.
  이 두 예제는 설명을 위한 기본 골격이므로, 실행하기 전에 플러그인, instruction, 계정 이름을
  직접 사용하는 이름으로 바꿔 주세요.
</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>
  `cargo build-sbf`로 Solana 프로그램을 빌드하여 `.so` 파일을 생성하세요.
</Info>

패턴은 항상 동일합니다:

1. **프로그램 로드**: `addProgramFromFile`을 사용해 컴파일된 프로그램을 로드하고
   클라이언트에서 myProgramPlugin()을 import합니다
2. **구성**: 필요한 경우 서명 검증과 같은 설정을 변경합니다.
   sysvar, 빌트인, 프리컴파일, 기본 프로그램은 이미 로드되어 있습니다
3. **계정 설정**: `setAccount`로 데이터 계정을 미리 채워 둡니다
4. **전송**: `client.myProgram.testInstruction({ /* args */ }).sendTransaction()`을 사용합니다.
   트랜잭션을 직접 구성할 필요가 없습니다
5. **검증**: 실행 후 계정 상태를 확인합니다
   (`client.myProgram.myAccount.fetch`)

이 기본 골격이 동작하면, instruction과 assertion을 더 추가하여
전체 테스트 스위트를 구축할 수 있습니다.
