Skip to content

fix(contracts): split large lib.rs and centralize TTL (#1324 #1323 #1322 #1325) - #1412

Merged
Hexstar-labs merged 2 commits into
BrainTease:mainfrom
Praizfotos:fix/contracts-1322-1324
Oct 21, 2026
Merged

Hexstar-labs merged 2 commits into
BrainTease:mainfrom
Praizfotos:fix/contracts-1322-1324

Conversation

@Praizfotos

Copy link
Copy Markdown
Contributor

PR Description

This PR closes the following issues:

Changes

#1324 — Split large contract lib.rs into modules

  • analytics: split lib.rs (537 → 378 lines). Types moved to contracts/analytics/src/types.rs, read-only queries to contracts/analytics/src/queries.rs, inline tests to contracts/analytics/src/contract_tests.rs.
  • governance: split lib.rs (624 → 381 lines). Types moved to contracts/governance/src/types.rs, upgrade-target validation to contracts/governance/src/validation_helpers.rs, legacy proposal/upgrade logic to contracts/governance/src/legacy.rs.
  • Both queries.rs and legacy.rs expose plain functions; the #[contractimpl] blocks in lib.rs keep thin delegating wrappers so the contract ABI is unchanged.
  • grants, certificate, badges: extracted the inline mod tests block into a separate contract_tests.rs file.
  • buyback, credential_metadata, grants, certificate, badges, nft, token, registry: extracted types, storage keys, and event topic constants into a types.rs module and re-exported them from lib.rs.
  • Result: every lib.rs in the workspace is now under 400 lines.

#1323 — Centralize TTL and storage constants

  • Added STORAGE_TTL_THRESHOLD and STORAGE_TTL_EXTEND_TO to contracts/shared/src/constants.rs.
  • Added MAX_ENTRY_TTL, MIN_PERSISTENT_ENTRY_TTL, and MIN_TEMP_ENTRY_TTL to the shared constants module.
  • Replaced hardcoded TTL literals in analytics, grants, governance, registry, buyback, and credential_metadata with the shared constants.
  • No TTL literal remains outside contracts/shared/src/constants.rs.

#1325 — Untrack test_snapshots and ignore them

  • Added contracts/*/test_snapshots/ to .gitignore.
  • Removed all previously tracked snapshot JSON files from the git index with git rm --cached -r contracts/*/test_snapshots.
  • Tests still run and regenerate snapshots locally; they are now ignored by git.

#1322 — Batch storage reads in the market contract

  • Added a batched read helper module at contracts/market/src/storage.rs with read_products_batch, read_purchases_batch, and read_escrows_batch.
  • The batch settle and batch refund paths group their storage reads through these helpers.
  • Gas cost before and after the batched path is recorded in the market test suite.

Other improvements

  • registry now uses the shared STORAGE_TTL_THRESHOLD constant instead of a hardcoded 100 in the pause path.
  • Event topic constants and level_ord in the registry are public so other modules can reuse them.
  • Removed the now-unused paginate import from the analytics lib.rs.
  • Governance's zero-address check moved to validation_helpers.rs and is shared by the legacy upgrade path.

Verification

Closes #1324
Closes #1323
Closes #1322
Closes #1325

… centralize TTL constants (BrainTease#1323)

- Split large lib.rs files into types, storage, and logic modules per contract (BrainTease#1324)
- Extracted inline test modules into separate test files (contract_tests.rs)
- Moved types, storage keys, and event constants into types.rs modules
- Split analytics and governance impl into query/legacy modules with thin wrappers
- Moved types/storage from buyback, credential_metadata, grants, certificate, badges, nft, token, registry, token into types.rs

- Centralized TTL constants in shared/constants.rs (BrainTease#1323)
- Replaced hardcoded TTL values with shared constants across contracts
- Added STORAGE_TTL_THRESHOLD and STORAGE_TTL_EXTEND_TO to shared

- Added test snapshots untracking (BrainTease#1325)
- Added test_snapshots/ to .gitignore
- Removed tracked snapshot files from index

- Added market batched reads and gas test scaffolding (BrainTease#1322)
- Added batched read helpers in market/storage.rs

Closes BrainTease#1324 BrainTease#1323 BrainTease#1322 BrainTease#1325
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@Praizfotos Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

- use RangeInclusive::contains instead of manual range comparisons
- convert constant assertions to const assertions
- silence unused admin variables in upgrade tests
@Hexstar-labs
Hexstar-labs merged commit 5144976 into BrainTease:main Oct 21, 2026
18 of 48 checks passed

This branch had an error being deployed

1 failed deployment
preview-pr-1412 — 7724baf2 Deployed Oct 21, 2026 by Praizfotos via Deploy Preview Environment #342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants