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

# 계정 관리

> Go에서 계정, 잔액, rent를 관리하는 메서드

계정에 자금을 충전하고, 읽고, 쓰는 메서드입니다.

## Airdrop

```go
func (s *LiteSVM) Airdrop(pubkey solana.PublicKey, lamports uint64) error
```

계정에 lamports를 충전합니다. 내부 faucet에서 실제 System Program 전송을 수행하는
방식으로 구현되므로, 수신자는 결과 잔액을 보유할 수 있어야 합니다.

```go
priv, err := solana.NewRandomPrivateKey()
if err != nil {
    t.Fatal(err)
}
payer := priv.PublicKey()

// Airdrop 5 SOL
if err := svm.Airdrop(payer, 5_000_000_000); err != nil {
    t.Fatal(err)
}
```

## Balance

```go
func (s *LiteSVM) Balance(pubkey solana.PublicKey) (uint64, bool, error)
```

계정의 SOL 잔액을 반환합니다. 계정이 존재하지 않으면 두 번째 값은 `false`이며,
이는 "계정은 존재하지만 lamports가 0인 경우"와 구분됩니다.

```go
lamports, ok, err := svm.Balance(payer)
if err != nil {
    t.Fatal(err)
}
if !ok {
    t.Log("account does not exist")
} else {
    t.Logf("balance: %d lamports (%.3f SOL)", lamports, float64(lamports)/1e9)
}
```

## GetAccount

```go
func (s *LiteSVM) GetAccount(pubkey solana.PublicKey) *solana.Account
```

계정의 사본을 가져오며, 계정이 존재하지 않으면 `nil`을 반환합니다.
`*solana.Account`는 [`gagliardetto/solana-go`](https://github.com/gagliardetto/solana-go)의
일반 구조체이므로 닫아야 할 항목이 없으며, 반환된 값을 변경해도 `SetAccount`에
전달하기 전까지는 SVM 상태가 바뀌지 않습니다.

```go
acct := svm.GetAccount(payer)
if acct == nil {
    t.Fatal("account missing")
}

_ = acct.Lamports   // uint64
_ = acct.Owner      // solana.PublicKey
_ = acct.Executable // bool
_ = acct.RentEpoch  // uint64
_ = acct.Data       // []byte (copy)
```

### 계정 필드

| 필드        | 타입               | 설명                       |
| ------------ | ------------------ | --------------------------------- |
| `Lamports`   | `uint64`           | SOL 잔액                       |
| `Owner`      | `solana.PublicKey` | 소유 프로그램                    |
| `Executable` | `bool`             | 계정의 실행 가능 여부 |
| `RentEpoch`  | `uint64`           | Rent epoch                        |
| `Data`       | `[]byte`           | 계정 데이터의 사본          |

## NewAccount

```go
func NewAccount(lamports uint64, data []byte, owner solana.PublicKey, executable bool, rentEpoch uint64) (*solana.Account, error)
```

`SetAccount`에 전달할 `*solana.Account`를 생성합니다. 오류 반환값은 항상
`nil`이며, `&solana.Account{Lamports: rent, Data: payload, Owner: ownerProgramID}`와
같은 복합 리터럴로도 동일한 작업을 할 수 있습니다.

```go
payload := []byte{1, 2, 3, 4}
rent, err := svm.MinimumBalanceForRentExemption(len(payload))
if err != nil {
    t.Fatal(err)
}

acct, err := litesvm.NewAccount(rent, payload, ownerProgramID, false, 0)
if err != nil {
    t.Fatal(err)
}
t.Logf("account: %d lamports, owner %s", acct.Lamports, acct.Owner)
```

## SetAccount

```go
func (s *LiteSVM) SetAccount(pubkey solana.PublicKey, acct *solana.Account) error
```

`acct`의 사본을 `pubkey`에 저장하며, 기존 계정이 있으면 대체합니다. SVM은
데이터의 자체 사본을 보관합니다. sysvar 주소에 쓰면 해당 sysvar가 갱신되고,
lamports가 0인 계정은 저장되는 대신 삭제됩니다.

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

<Info>
  테스트를 위해 많은 계정을 미리 채워 두기만 하면 될 때는 `SetAccount`가 트랜잭션을 실행하는 것보다
  훨씬 빠릅니다. lamports 값이 해당 데이터 크기의 rent 면제 최소값 이상인지
  확인하세요.
</Info>

## MinimumBalanceForRentExemption

```go
func (s *LiteSVM) MinimumBalanceForRentExemption(dataLen int) (uint64, error)
```

주어진 데이터 길이의 계정이 rent 면제 상태가 되기 위해 필요한 lamports를
계산합니다.

```go
for _, size := range []int{0, 100, 1024} {
    min, err := svm.MinimumBalanceForRentExemption(size)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("%4d bytes -> %d lamports", size, min)
}
```

## 프로그램 관리

### AddProgram

```go
func (s *LiteSVM) AddProgram(programID solana.PublicKey, programBytes []byte) error
```

메모리 내 바이트에서 SBF 프로그램을 로드합니다.

```go
bytes, err := os.ReadFile("./target/deploy/my_program.so")
if err != nil {
    t.Fatal(err)
}
if err := svm.AddProgram(programID, bytes); err != nil {
    t.Fatal(err)
}
```

### AddProgramFromFile

```go
func (s *LiteSVM) AddProgramFromFile(programID solana.PublicKey, path string) error
```

`.so` 파일 경로에서 SBF 프로그램을 로드합니다.

```go
if err := svm.AddProgramFromFile(programID, "./target/deploy/my_program.so"); err != nil {
    t.Fatal(err)
}
```

### AddProgramWithLoader

```go
func (s *LiteSVM) AddProgramWithLoader(programID solana.PublicKey, programBytes []byte, loader solana.PublicKey) error
```

특정 로더로 SBF 프로그램을 로드합니다. 기본이 아닌 BPF 로더 버전으로
테스트할 때 유용합니다.

## 계정 일괄 설정

미리 채워진 계정이 많이 필요한 테스트에서는 `SetAccount`를 반복 호출하세요:

```go
const N = 10
for i := 0; i < N; i++ {
    pk := solana.NewWallet().PublicKey()
    data := []byte{byte(i)}
    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(pk, acct); err != nil {
        t.Fatal(err)
    }
}
```

<Info>
  `SetAccount`는 계정 데이터를 복사하므로, 호출 후에 `acct`를 재사용하거나 수정해도
  SVM에는 영향을 주지 않습니다.
</Info>
