시간을 조작하고 시스템 변수에 접근하는 메서드입니다. 모든 sysvar getter에는 대응하는 setter가 있으며, 구조체는 Solana 소스를 그대로 반영한 순수 Go 미러입니다.
클록 조작
WarpToSlot
func (s *LiteSVM) WarpToSlot(slot uint64) error
내부 클록을 특정 slot으로 이동합니다.
before, err := svm.Clock()if err != nil {t.Fatal(err)}t.Logf("current slot: %d", before.Slot)if err := svm.WarpToSlot(10_000_000); err != nil {t.Fatal(err)}after, err := svm.Clock()if err != nil {t.Fatal(err)}t.Logf("new slot: %d", after.Slot)
Clock
type Clock struct {Slot uint64EpochStartTimestamp int64Epoch uint64LeaderScheduleEpoch uint64UnixTimestamp int64}func (s *LiteSVM) Clock() (Clock, error)
Clock sysvar를 읽습니다.
c, err := svm.Clock()if err != nil {t.Fatal(err)}t.Logf("slot=%d epoch=%d unix=%d", c.Slot, c.Epoch, c.UnixTimestamp)
SetClock
func (s *LiteSVM) SetClock(c Clock) error
Clock sysvar를 덮어씁니다. WarpToSlot이 업데이트하지 않는 Epoch 또는
UnixTimestamp를 제어해야 할 때, 먼저 읽고 필드를 변경한 뒤 다시 씁니다.
c, err := svm.Clock()if err != nil {t.Fatal(err)}c.Slot = 1_000c.Epoch = 10c.UnixTimestamp = 1_735_689_600if err := svm.SetClock(c); err != nil {t.Fatal(err)}
WarpToSlot은 Slot만 업데이트합니다. 프로그램이 Clock sysvar에서
Epoch 또는 UnixTimestamp를 읽는 경우 SetClock을 사용하세요.
Rent
Rent / SetRent
type Rent struct {LamportsPerByteYear uint64ExemptionThreshold float64BurnPercent uint8}func (s *LiteSVM) Rent() (Rent, error)func (s *LiteSVM) SetRent(r Rent) error
r, err := svm.Rent()if err != nil {t.Fatal(err)}t.Logf("lamports/byte-year: %d", r.LamportsPerByteYear)t.Logf("exemption threshold: %.2f", r.ExemptionThreshold)t.Logf("burn percent: %d", r.BurnPercent)
MinimumBalanceForRentExemption
func (s *LiteSVM) MinimumBalanceForRentExemption(dataLen int) (uint64, error)
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)}
Epoch Schedule
type EpochSchedule struct {SlotsPerEpoch uint64LeaderScheduleSlotOffset uint64Warmup boolFirstNormalEpoch uint64FirstNormalSlot uint64}func (s *LiteSVM) EpochSchedule() (EpochSchedule, error)func (s *LiteSVM) SetEpochSchedule(e EpochSchedule) error
es, err := svm.EpochSchedule()if err != nil {t.Fatal(err)}t.Logf("slots per epoch: %d", es.SlotsPerEpoch)t.Logf("first normal epoch: %d", es.FirstNormalEpoch)t.Logf("first normal slot: %d", es.FirstNormalSlot)
Epoch Rewards
type EpochRewards struct {DistributionStartingBlockHeight uint64NumPartitions uint64ParentBlockhash solana.HashTotalPointsLo uint64 // low 64 bits of the u128 total_pointsTotalPointsHi uint64 // high 64 bitsTotalRewards uint64DistributedRewards uint64Active bool}func (s *LiteSVM) EpochRewards() (EpochRewards, error)func (s *LiteSVM) SetEpochRewards(e EpochRewards) error
total_points는 Solana 측에서 u128 타입입니다. litesvm-go는 Go 호출자가
u128 라이브러리 없이도 사용할 수 있도록 상위 절반과 하위 절반을 명시적으로 노출합니다.
64비트 내에 맞는 값의 경우 TotalPointsHi는 0이고 TotalPointsLo가 해당 값입니다.
Slot 정보
LastRestartSlot / SetLastRestartSlot
func (s *LiteSVM) LastRestartSlot() (uint64, error)func (s *LiteSVM) SetLastRestartSlot(slot uint64) error
last, err := svm.LastRestartSlot()if err != nil {t.Fatal(err)}if err := svm.SetLastRestartSlot(last + 1); err != nil {t.Fatal(err)}
SlotHashes / SetSlotHashes
type SlotHash struct {Slot uint64Hash solana.Hash}func (s *LiteSVM) SlotHashes() ([]SlotHash, error)func (s *LiteSVM) SetSlotHashes(items []SlotHash) error
SlotHistory
SlotHistory는 약 128KB 크기의 비트벡터입니다. litesvm-go는 이를 슬라이스가 아닌
핸들로 노출합니다.
sh, err := litesvm.NewSlotHistory()if err != nil {t.Fatal(err)}defer sh.Close()sh.Add(42)switch sh.Check(42) {case litesvm.SlotHistoryFound:// ...case litesvm.SlotHistoryNotFound:// ...case litesvm.SlotHistoryTooOld:// ...case litesvm.SlotHistoryFuture:// ...}if err := svm.SetSlotHistory(sh); err != nil {t.Fatal(err)}
| 메서드 | 설명 |
|---|---|
litesvm.NewSlotHistory() (*SlotHistory, error) | 빈 핸들 |
sh.Add(slot uint64) | slot 기록 |
sh.Check(slot uint64) SlotHistoryCheck | Future / TooOld / Found / NotFound |
sh.Oldest() uint64 | 추적 중인 가장 오래된 slot |
sh.Newest() uint64 | 추적 중인 가장 최근 slot |
sh.NextSlot() uint64 | 다음에 기록될 slot |
sh.SetNextSlot(slot uint64) error | 다음 slot 마커 재정의 |
sh.Close() | 핸들 해제 |
svm.SlotHistory() (*SlotHistory, error) | 새 핸들로 읽기 |
svm.SetSlotHistory(*SlotHistory) error | SVM에 설치 |
Stake History
type StakeHistoryItem struct {Epoch uint64Effective uint64Activating uint64Deactivating uint64}func (s *LiteSVM) StakeHistory() ([]StakeHistoryItem, error)func (s *LiteSVM) SetStakeHistory(items []StakeHistoryItem) error
시간 의존적 로직 테스트
단순 slot 기반 진행에는 WarpToSlot을, 완전한 제어가 필요할 때는 SetClock을 사용하세요:
func TestTimeLockedVault(t *testing.T) {svm, err := litesvm.New()if err != nil {t.Fatal(err)}defer svm.Close()const unlockSlot = uint64(10_000)// Setup: create the time-locked account ...// Test 1: Try to withdraw before unlock (should fail)before, err := svm.Clock()if err != nil {t.Fatal(err)}t.Logf("current slot: %d", before.Slot)// ... attempt withdrawal, expect failure ...// Warp time forward past unlock slotif err := svm.WarpToSlot(unlockSlot + 1); err != nil {t.Fatal(err)}// Test 2: Try to withdraw after unlock (should succeed)after, err := svm.Clock()if err != nil {t.Fatal(err)}t.Logf("new slot: %d", after.Slot)// ... attempt withdrawal, expect success ...}
Is this page helpful?