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, blockNum uint64, su *core.StateUpdate)
- func AssertStateHistoryPruned(t *testing.T, r db.KeyValueReader, blockNum uint64, su *core.StateUpdate)
- 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 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 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, 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
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.