Skip to content

Marketplace initialize never writes consolidated Config key — load_config always falls back to legacy migration path #351

Description

@Mac-5

Description

contracts/marketplace/src/lib.rs has a load_config helper (lines 291–332) that first tries to read a DataKey::Config struct, and if absent falls back to reading individual keys (Admin, InvoiceNft, FinancingPool, Treasury, FeeBps) and writing them into a consolidated Config entry.

The problem is that initialize (lines 45–67) never writes DataKey::Config. It only writes the individual keys:

env.storage().instance().set(&DataKey::Admin, &admin);
env.storage().instance().set(&DataKey::InvoiceNft, &invoice_nft);
// ...no Config write

This means:

  1. Every single call to any function that uses load_config (e.g., list_invoice, cancel_listing, whitelist_token) triggers the legacy migration path, doing 5 storage reads + 1 write instead of 1 read.
  2. The first call to any of those functions mutates storage as a side effect — unexpected behaviour for read-like operations.
  3. The get_config test (test_get_config_returns_initialized_values) relies on get_config being available, but that function is not defined in the contract either (see related compilation issue).

Fix

At the end of initialize, write the consolidated config:

let config = MarketplaceConfig { admin, invoice_nft, financing_pool, treasury, fee_bps };
env.storage().instance().set(&DataKey::Config, &config);

Acceptance Criteria

  • initialize writes DataKey::Config as part of its setup.
  • load_config reads the config in a single storage lookup on all subsequent calls.
  • The legacy fallback path can be removed or kept only for forward compatibility with already-deployed instances.
  • Tests confirm config is readable immediately after initialization.

Complexity: Low (75 points)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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