testutils

package
v0.16.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutils provides shared fixtures for tests that exercise the pruner's data layout. Both the pruner package's own tests and the historyprunner migration test depend on the same on-disk shape, so the helpers live here to avoid duplication.

Index

Constants

This section is empty.

Variables

View Source
var (
	SharedAddr1 = felt.NewFromUint64[felt.Felt](0xA001) //nolint:mnd // test fixture
	SharedAddr2 = felt.NewFromUint64[felt.Felt](0xA002) //nolint:mnd // test fixture
	SharedSlot  = felt.NewFromUint64[felt.Felt](0x5001) //nolint:mnd // test fixture
)

Two fixed addresses that appear across multiple blocks to simulate realistic state history where the same contract is touched repeatedly.

Functions

func AssertBlockExists

func AssertBlockExists(t *testing.T, database db.KeyValueReader, block *StoredBlock)

AssertBlockExists verifies all data for a block is present.

func AssertBlockPruned

func AssertBlockPruned(t *testing.T, database db.KeyValueReader, block *StoredBlock)

AssertBlockPruned verifies all data for a block is gone.

func AssertPostPruneState

func AssertPostPruneState(
	t *testing.T,
	database db.KeyValueReader,
	blocks []*StoredBlock,
	oldestKept uint64,
	lag uint64,
)

AssertPostPruneState validates the on-disk shape after a successful prune that retains blocks [oldestKept, len(blocks)) and applies the BlockHashLag carve-out plus the hash→number carve-out at oldestKept-1.

func AssertStateHistoryExists

func AssertStateHistoryExists(
	t *testing.T,
	r db.KeyValueReader,
	blockNum uint64,
	su *core.StateUpdate,
)

func AssertStateHistoryPruned

func AssertStateHistoryPruned(
	t *testing.T,
	r db.KeyValueReader,
	blockNum uint64,
	su *core.StateUpdate,
)

func BlockCommitmentsExist

func BlockCommitmentsExist(database db.KeyValueReader, blockNum uint64) bool

func BlockHeaderExists

func BlockHeaderExists(database db.KeyValueReader, blockNum uint64) bool

Helpers for individual bucket checks.

func BlockHeaderHashExists

func BlockHeaderHashExists(database db.KeyValueReader, hash *felt.Felt) bool

func NewPebbleTestDB

func NewPebbleTestDB(t *testing.T) db.KeyValueStore

NewPebbleTestDB returns an isolated pebble-backed KeyValueStore for the test. We use pebble (not the in-memory db) because pebble's batch DeleteRange performs a real range delete, while the memory implementation only scans keys with the start byte sequence as a literal prefix.

func StateUpdateExists

func StateUpdateExists(database db.KeyValueReader, blockNum uint64) bool

func TransactionsExist

func TransactionsExist(database db.KeyValueReader, blockNum uint64) bool

func WithBatch

func WithBatch(t *testing.T, database db.KeyValueStore, fn func(db.Batch) error)

Types

type StoredBlock

type StoredBlock struct {
	Header   *core.Header
	TxHashes []*felt.Felt
	// L1HandlerMsgHashes are the message hashes for any L1 handler txs in this block.
	L1HandlerMsgHashes [][]byte
	// StateUpdate is the state update written for this block.
	StateUpdate *core.StateUpdate
}

StoredBlock holds all data written for a block, so assertions can verify every pruned bucket.

func StoreBlock

func StoreBlock(t *testing.T, database db.KeyValueStore, blockNum uint64) *StoredBlock

StoreBlock writes a complete block into the database covering all pruned buckets:

  • Bucket 7: BlockHeaderNumbersByHash
  • Bucket 8: BlockHeadersByNumber
  • Bucket 9: TransactionBlockNumbersAndIndicesByHash
  • Bucket 12: StateUpdatesByBlockNumber
  • Bucket 21: BlockCommitments
  • Bucket 24: L1HandlerTxnHashByMsgHash (one L1 handler tx per block)
  • Bucket 40: BlockTransactions
  • Bucket 14: ContractStorageHistory
  • Bucket 15: ContractNonceHistory
  • Bucket 16: ContractClassHashHistory

func StoreBlockWithTimestamp

func StoreBlockWithTimestamp(
	t *testing.T,
	database db.KeyValueStore,
	blockNum,
	timestamp uint64,
) *StoredBlock

StoreBlockWithTimestamp is StoreBlock but lets the caller set the block header's Timestamp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL