Skip to content

[CE-049] integration_test.rs uses hardcoded Stellar addresses — should use generated test addresses #89

Description

@Jaydbrown

Problem

tests/integration_test.rs contains hardcoded Stellar testnet addresses in test fixtures. These addresses are testnet-specific and will fail on mainnet or if the test environment changes.

Hardcoded addresses like "GABC...XYZ" (sender), "GDEF...UVW" (recipient), and contract IDs are embedded in the test file. These addresses:

  1. May be test accounts that get cleaned up or run out of testnet XLM
  2. Create a dependency on external testnet state (account must exist and be funded)
  3. Cannot be reused in unit tests without a live Stellar testnet connection
  4. Make the test suite non-deterministic (fails if testnet is down or accounts are unfunded)

Root Cause

Integration tests were written using real Stellar testnet addresses without parameterization or mock infrastructure.

Impact

  • CI may fail intermittently when testnet is unavailable or accounts are unfunded
  • Tests cannot run in offline/unit mode — every test requires a live network connection
  • Hardcoded addresses become outdated as test accounts are rotated or funded differently
  • A contributor changing the mock adapter cannot easily test without a live testnet connection

Fix

Step 1 — Define test constants in a separate module:

// tests/helpers/fixtures.rs
//
// These are Stellar-format test addresses used in unit tests.
// They are NOT real accounts — they use the correct G.../S... format
// for format validation but are NOT expected to exist on-chain.

pub const TEST_SENDER: &str = "GAHJJJKMOKYE4RVPZEWZTKH5FVI4PA3VL7GK2LFNUBSGBV3UXBOMQKF";
pub const TEST_RECIPIENT: &str = "GBPJPPNLQS2LO27WLMQXMFKTKTOMKQZXLRXDPXAJMKHG2GNIEBDBWGJ";
pub const TEST_TOKEN: &str = "XLM";
pub const TEST_AMOUNT: u64 = 100_0000000;  // 100 XLM in stroops

// Stellar key format validation constants
pub const VALID_G_PREFIX: &str = "GAHJJJKMOKYE4RVPZEWZTKH5FVI4PA3VL7GK2LFNUBSGBV3UXBOMQKF";
pub const INVALID_ADDRESS: &str = "not_a_stellar_address";
pub const SHORT_ADDRESS: &str = "GSHORT";

Step 2 — Use mock adapter for unit tests:

The src/adapters/mock module already exists (pub mod mock in src/adapters/mod.rs). Use it in integration tests:

// tests/integration_test.rs
mod helpers;
use helpers::fixtures::*;
use nodus_core_engine::adapters::mock::MockAdapter;
use nodus_core_engine::engine::Engine;
use nodus_core_engine::retry::RetryConfig;

#[tokio::test]
async fn test_payment_initiation_success() {
    // Uses mock adapter — no network needed
    let adapter = Arc::new(MockAdapter::success("mock_tx_hash_abc123".into()));
    let engine = Engine::new(vec![adapter], RetryConfig::new(3, 10));

    let result = engine.initiate(
        TEST_SENDER.into(),
        TEST_RECIPIENT.into(),
        TEST_AMOUNT,
        TEST_TOKEN.into(),
        Urgency::Standard,
    ).await;

    assert!(result.is_ok());
    let payment = result.unwrap();
    assert_eq!(payment.tx_hash, Some("mock_tx_hash_abc123".into()));
    assert_eq!(payment.status, PaymentStatus::Confirmed);
}

Step 3 — Separate integration tests (need live Stellar) from unit tests:

// tests/integration_stellar_test.rs — ONLY runs in CI with real Stellar testnet
//go:build integration (Rust equivalent: cfg(feature = "integration"))
#[cfg(feature = "integration")]
mod stellar_integration {
    const STELLAR_SENDER: &str = std::env!("TEST_STELLAR_SENDER",
        "Set TEST_STELLAR_SENDER env var for integration tests");
    // ...
}
# Cargo.toml
[features]
integration = []  # Run with: cargo test --features integration

Steps to Verify

  1. cargo test runs without any network — mock adapter handles all interactions
  2. cargo test --features integration requires TEST_STELLAR_SENDER env var, fails without it
  3. Remove hardcoded "GABC..." strings from tests/integration_test.rs — zero results in grep "GA[A-Z0-9]\{55\}" tests/
  4. CI cargo test step passes without Stellar testnet credentials

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignenhancementNew feature or requestpriority: lowCosmetic, docs, or minor improvements

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions