Skip to content

[Enhancement] Add env.token(symbol) accessor to retrieve registered MockTokens by name after build() #786

Description

@ekelemepraise-code

Summary

Tokens registered via .with_token("USDC", 6) during builder configuration are inaccessible after build() completes. Users must re-construct the token or store it before the builder is consumed.

let env = MockEnv::builder()
    .with_token("USDC", 6)
    .build();

// Currently impossible — no way to get the USDC token back
let usdc = env.token("USDC"); // method does not exist

Proposed API

impl MockEnv {
    pub fn token(&self, symbol: &str) -> MockToken { ... }
    pub fn token_opt(&self, symbol: &str) -> Option<MockToken> { ... }
}

Implementation

  • MockEnv should store a HashMap<String, MockToken> populated during build()
  • token() panics with a clear message if the symbol was not registered
  • token_opt() returns None gracefully

Acceptance Criteria

  • env.token("USDC") works after with_token("USDC", 6).build()
  • Clear panic message when symbol not found
  • Works alongside manually constructed MockToken::new() (separate code path)
  • Exported via prelude

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions