stub_repository.rs

Overview

This file defines stub implementations primarily intended for testing purposes within the repository layer of the system. It provides mock versions of core repository traits and optimistic state handling that emulate the behavior of their real counterparts without performing actual data operations. These stubs enable isolated testing of components that depend on repository interactions without requiring a full database or network setup.

The file contains:

These stubs serve as placeholders for the real implementations, facilitating unit tests and integration tests for modules interacting with repository abstractions.


Detailed Explanations

OptimisticStateStub

A mock structure implementing the OptimisticState trait. It is designed to represent an optimistic state snapshot of a blockchain shard or thread in a minimalistic way.

Definition

#[derive(Clone)]
pub struct OptimisticStateStub {
    _key: u64,
    _acc: u16,
    _state: tvm_block::Account,
}

Trait Implementation: OptimisticState

Implements the required methods for the OptimisticState trait with todo!() placeholders, except for the type declarations.

Associated Types
Important Methods

These methods are currently unimplemented (todo!()), indicating that this stub serves as a template or placeholder.

Usage Example
let mut state = OptimisticStateStub { _key: 0, _acc: 0, _state: some_account };
let thread_id = state.get_thread_id();

RepositoryStub

A mock repository implementation of the Repository trait, used for testing repository-dependent components.

Definition

pub struct RepositoryStub {
    _storage: HashMap<BlockIdentifier, Envelope<GoshBLS, AckiNackiBlock>>,
    optimistic_state: HashMap<BlockIdentifier, <Self as Repository>::OptimisticState>,
}

Initialization

impl Default for RepositoryStub {
    fn default() -> Self {
        Self::new()
    }
}

impl RepositoryStub {
    pub fn new() -> Self {
        Self { _storage: HashMap::new(), optimistic_state: HashMap::new() }
    }
}

Creates an empty stub repository with no stored blocks or states.

Trait Implementation: Repository

Implements the Repository trait with the following associated types:

Selected Methods and Behavior

Usage Example
let mut repo = RepositoryStub::new();
let block_id = some_block_identifier;
if let Ok(Some(state)) = repo.get_optimistic_state(&block_id, &some_thread_id, None) {
    // Use optimistic state for testing
}

Important Implementation Details and Algorithms


Interactions with Other System Components

For related abstractions and detailed trait descriptions, see:


Diagram: Structure of stub_repository.rs

classDiagram
class OptimisticStateStub {
-_key: u64
-_acc: u16
-_state: Account
+get_share_stare_refs()
+get_block_seq_no()
+get_block_id()
+serialize_into_buf()
+get_shard_state()
+get_block_info()
+apply_block()
+get_thread_id()
+add_slashing_messages()
}
class RepositoryStub {
-_storage: HashMap<BlockIdentifier, Envelope>
-optimistic_state: HashMap<BlockIdentifier, OptimisticStateStub>
+new()
+get_optimistic_state()
+get_full_optimistic_state()
+mark_block_as_finalized()
}
OptimisticStateStub ..|> OptimisticState
RepositoryStub ..|> Repository

This diagram highlights the two main stub structures, their key properties, and selected methods, including their trait implementations. It illustrates the core in-memory storage for blocks and optimistic states and the stubbed method interfaces.