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 ¶
- Variables
- func AssertBlockExists(t *testing.T, database db.KeyValueReader, block *StoredBlock)
- func AssertBlockPruned(t *testing.T, database db.KeyValueReader, block *StoredBlock)
- func AssertPostPruneState(t *testing.T, database db.KeyValueReader, blocks []*StoredBlock, ...)
- func AssertStateHistoryExists(t *testing.T, r db.KeyValueReader, block *StoredBlock)
- func AssertStateHistoryPruned(t *testing.T, r db.KeyValueReader, pruned []*StoredBlock)
- func BlockCommitmentsExist(database db.KeyValueReader, blockNum uint64) bool
- func BlockHeaderExists(database db.KeyValueReader, blockNum uint64) bool
- func BlockHeaderHashExists(database db.KeyValueReader, hash *felt.Felt) bool
- func HistoryAnswers(t *testing.T, database db.KeyValueStore, blocks []*StoredBlock, ...) map[string]felt.Felt
- func NewPebbleTestDB(t *testing.T) db.KeyValueStore
- func StateUpdateExists(database db.KeyValueReader, blockNum uint64) bool
- func TransactionsExist(database db.KeyValueReader, blockNum uint64) bool
- func WithBatch(t *testing.T, database db.KeyValueStore, fn func(db.Batch) error)
- type Layout
- type StoredBlock
- func StoreBlock(t *testing.T, database db.KeyValueStore, blockNum uint64) *StoredBlock
- func StoreBlockWithLayout(t *testing.T, database db.KeyValueStore, blockNum, timestamp uint64, ...) *StoredBlock
- func StoreBlockWithTimestamp(t *testing.T, database db.KeyValueStore, blockNum, timestamp uint64) *StoredBlock
Constants ¶
This section is empty.
Variables ¶
var ( )
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, block *StoredBlock)
AssertStateHistoryExists checks the block's history entries are present.
func AssertStateHistoryPruned ¶
func AssertStateHistoryPruned(t *testing.T, r db.KeyValueReader, pruned []*StoredBlock)
AssertStateHistoryPruned checks the history of the blocks below the floor, given in block order: an entry survives only in the new-state layout, and only if no later block below the floor rewrote its key.
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 HistoryAnswers ¶ added in v0.17.0
func HistoryAnswers( t *testing.T, database db.KeyValueStore, blocks []*StoredBlock, from, to uint64, ) map[string]felt.Felt
HistoryAnswers reads every key touched by blocks at every height in [from, to] through the history reader of the blocks' layout.
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
Types ¶
type Layout ¶ added in v0.17.0
type Layout byte
Layout is a state history layout.
const ( // DeprecatedLayout entries record the value before their block; pruning // removes every entry below the floor. DeprecatedLayout Layout = iota // NewStateLayout entries record the value after their block; pruning keeps // each key's latest entry below the floor, which reads at the floor need. NewStateLayout )
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
// Layout is the layout the block's state history is written in.
Layout Layout
}
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 StoreBlockWithLayout ¶ added in v0.17.0
func StoreBlockWithLayout( t *testing.T, database db.KeyValueStore, blockNum, timestamp uint64, layout Layout, ) *StoredBlock
StoreBlockWithLayout is StoreBlockWithTimestamp with state history in the given layout.
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.