tests.rs

Overview

This file contains a suite of unit tests designed to validate the functionality of the MessageDurableStorage component and its interaction with message serialization, storage, retrieval, and querying. The tests focus on verifying the correctness of message persistence operations such as writing messages to durable storage, reading them back, fetching database row IDs by message hash, iterating over stored messages, and retrieving remaining messages starting from a given message identifier.

The file operates primarily with base64-encoded serialized messages, deserializing them into tvm_block::Message instances, wrapping them into WrappedMessage structures, and then storing or querying these objects through the MessageDurableStorage interface.

Details of Functions and Their Usage

setup_db

fn setup_db(db_path: PathBuf) -> MessageDurableStorage

test_write_and_read_message

#[test]
fn test_write_and_read_message()

test_get_rowid_by_hash

#[test]
fn test_get_rowid_by_hash()

test_next_simple

#[test]
fn test_next_simple()

test_remaining

#[test]
fn test_remaining()

Important Implementation Details

Interaction with Other Components

Visual Diagram

flowchart TD
A[setup_db] --> B[MessageDurableStorage]
subgraph Tests
TWAR[test_write_and_read_message]
TGHB[test_get_rowid_by_hash]
TNS[test_next_simple]
TR[test_remaining]
end
TWAR --> B
TGHB --> B
TNS --> B
TR --> B
B -->|write_message| C[Store message blob]
B -->|read_message| D[Retrieve message by hash]
B -->|get_rowid_by_hash| E[Lookup row ID]
B -->|next_simple| F[Fetch next messages]
B -->|remaining_messages| G[Fetch remaining messages]
TWAR -.->|uses| H[tvm_block::Message]
TWAR -.->|uses| I[WrappedMessage]
TNS -.->|mutates| J[MsgAddressInt/MsgAddrStd]
style Tests fill:#f9f,stroke:#333,stroke-width:1px
style B fill:#bbf,stroke:#333,stroke-width:1px

This flowchart illustrates the relationship between the test functions, the MessageDurableStorage component under test, and the key storage operations utilized by these tests. It also shows interactions with message data structures and address types used to prepare test inputs.