> ## 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-go로 테스트 계정과 상태 설정하기

트랜잭션을 실행하지 않고 `SetAccount`로 계정 상태를 직접 설정하는 방법을 보여줍니다.
테스트에 많은 계정이 필요할 때, 런타임을 통해 에어드롭 + 자금 충전을 하는 것보다
훨씬 빠릅니다.

## 기본 계정 설정

```go
package mytest

import (
    "testing"

    litesvm "github.com/LiteSVM/litesvm-go"
    solana "github.com/gagliardetto/solana-go"
)

func TestBasicAccountSetup(t *testing.T) {
    svm, err := litesvm.New()
    if err != nil {
        t.Fatal(err)
    }
    defer svm.Close()

    // Calculate minimum balance for rent exemption.
    accountData := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    minBalance, err := svm.MinimumBalanceForRentExemption(len(accountData))
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("minimum balance for %d bytes: %d lamports", len(accountData), minBalance)

    // Owner program (system program in this trivial example).
    owner := solana.SystemProgramID
    testAddr := solana.NewWallet().PublicKey()

    // Build the account, then store it.
    acct, err := litesvm.NewAccount(minBalance, accountData, owner, false, 0)
    if err != nil {
        t.Fatal(err)
    }

    if err := svm.SetAccount(testAddr, acct); err != nil {
        t.Fatal(err)
    }
    t.Log("account state set successfully")

    // Retrieve a copy of the account.
    retrieved := svm.GetAccount(testAddr)
    if retrieved == nil {
        t.Fatal("expected account to exist")
    }

    t.Logf("  address:    %s", testAddr)
    t.Logf("  lamports:   %d", retrieved.Lamports)
    t.Logf("  owner:      %s", retrieved.Owner)
    t.Logf("  executable: %v", retrieved.Executable)
    t.Logf("  data:       %v", retrieved.Data)

    // Or just read the balance.
    bal, _, err := svm.Balance(testAddr)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("balance: %d lamports", bal)
}
```

## 여러 계정 설정하기

```go
func TestMultipleAccounts(t *testing.T) {
    svm, err := litesvm.New()
    if err != nil {
        t.Fatal(err)
    }
    defer svm.Close()

    owner := solana.SystemProgramID

    // Set up 5 accounts with different data payloads.
    addrs := make([]solana.PublicKey, 5)
    for i := range addrs {
        addrs[i] = solana.NewWallet().PublicKey()

        data := []byte{byte(i), byte(i + 1), byte(i + 2)}
        rent, err := svm.MinimumBalanceForRentExemption(len(data))
        if err != nil {
            t.Fatal(err)
        }

        acct, err := litesvm.NewAccount(rent, data, owner, false, 0)
        if err != nil {
            t.Fatal(err)
        }
        if err := svm.SetAccount(addrs[i], acct); err != nil {
            t.Fatal(err)
        }

        t.Logf("account %d: %s", i, addrs[i])
    }

    // Verify each account.
    for i, addr := range addrs {
        a := svm.GetAccount(addr)
        if a == nil {
            t.Fatalf("account %d missing", i)
        }
        t.Logf("  account %d: %d lamports, data[0]=%d", i, a.Lamports, a.Data[0])
    }
}
```

## 프로그램 데이터 계정 설정

구조체 레이아웃을 직렬화하여 계정의 `data`에 넣는 방식으로 프로그램 소유 데이터 계정을
설정합니다. 이 코드 조각은 추가로 `encoding/binary`를 임포트합니다:

```go
import "encoding/binary"

func TestProgramDataAccount(t *testing.T) {
    svm, err := litesvm.New()
    if err != nil {
        t.Fatal(err)
    }
    defer svm.Close()

    programID := solana.NewWallet().PublicKey()
    dataAddr := solana.NewWallet().PublicKey()

    // Example layout: [u8 discriminator, u64 counter, 32-byte owner pubkey]
    data := make([]byte, 1+8+32)
    data[0] = 0x01                                      // discriminator
    binary.LittleEndian.PutUint64(data[1:9], 100)       // counter
    // copy(data[9:], ownerPubkey[:])                   // owner

    rent, err := svm.MinimumBalanceForRentExemption(len(data))
    if err != nil {
        t.Fatal(err)
    }

    acct, err := litesvm.NewAccount(rent, data, programID, false, 0)
    if err != nil {
        t.Fatal(err)
    }

    if err := svm.SetAccount(dataAddr, acct); err != nil {
        t.Fatal(err)
    }

    t.Logf("program data account set up: %s", dataAddr)
}
```

<Info>
  `SetAccount`는 대량의 계정을 설정할 때 트랜잭션을 실행하는 것보다 빠르며,
  상태를 구성하기 위한 번거로운 작업이 아니라 테스트하려는 동작에
  테스트 코드가 집중할 수 있도록 해줍니다.
</Info>

## 핵심 사항

1. **직접 상태 설정** - `SetAccount`는 런타임을 거치지 않고
   계정 상태를 직접 기록합니다.
2. **렌트 면제** - 계정을 구성하기 전에 `MinimumBalanceForRentExemption`을 사용하여
   lamports를 계산하세요.
3. **일반 값** - 계정은 `*solana.Account` 구조체입니다. `SetAccount`와
   `GetAccount`는 데이터를 복사하므로 별도로 닫을 필요가 없습니다.
4. **검증** - `GetAccount`로 계정을 다시 읽거나, lamports만 확인하려면
   `Balance`를 사용하세요.
