Skip to content

[PR #31] ChainProvider concrete struct — no trait for mock substitution in CI #90

@obchain

Description

@obchain

PR: #31 (feat/06-chainprovider-ws)
File: crates/charon-scanner/src/provider.rs
Lines: 19-62

Problem: ChainProvider is concrete struct. Downstream scanner crates (block listener, executor) will take &ChainProvider as hard dep. CI has no live BSC node; every unit test touching provider-dependent code must be skipped or will panic.

Breaks trait-first design established in PR #28 (LendingProtocol trait), which PRD Testing section requires for all scanner abstractions.

Impact: No unit-test coverage possible for scanner hot path. Future PR reviewers cannot validate logic without fork test env.

Fix: Extract ChainProviderT trait:

#[async_trait::async_trait]
pub trait ChainProviderT: Send + Sync {
    async fn get_block_number(&self) -> Result<u64>;
    async fn subscribe_blocks(&self) -> Result</* stream */>;
}

impl ChainProviderT for ChainProvider { ... }

pub struct MockChainProvider { pub block_number: u64 }
#[async_trait::async_trait]
impl ChainProviderT for MockChainProvider {
    async fn get_block_number(&self) -> Result<u64> { Ok(self.block_number) }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polishtype:testTests, fuzz, fork, integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions