Skip to content

[FEAT]: land SafHandle v1 contract, tests, tooling - #4

Merged
danbaruka merged 1 commit into
Safrochain-Org:mainfrom
mbagalwa:main
Jul 8, 2026
Merged

danbaruka merged 1 commit into
Safrochain-Org:mainfrom
mbagalwa:main

Conversation

@mbagalwa

@mbagalwa mbagalwa commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Land the SafHandle v1 CosmWasm contract (contracts/safhandle/): register / transfer /
    release short names, read queries (get_address, resolve_name, name_record, handles,
    config), governance (update_config), with exact-fee enforcement and contract-side name
    validation/normalization. Phone linking ships behind the phone Cargo feature (Phase 2, off by default).
  • Add cw-multi-test integration tests, generated JSON schema, and testnet deployment tooling
    (scripts/deploy-testnet.sh, config/).

Why

  • Upstream currently holds only the documentation scaffold; this brings in the implemented,
    testnet-deployed v1 contract. No linked issue.

Type of change

  • Specification change
  • Documentation update
  • Contract implementation
  • Deployment / tooling
  • CI / repository hygiene
  • Breaking change

Test plan

  • npm run verify passes locally
  • Contract tests added or updated — cw-multi-test integration tests (contracts/safhandle/tests/integration.rs) + unit tests in src/
  • Manual test on safro-testnet-1 — v1 deployed and live on testnet (see README status)

Steps:

  1. cargo test --workspace
  2. npm run verify

Security checklist

  • No private keys or secrets in code or commits — deploy-testnet.sh references a keyring key name only
  • Specification changes reviewed for resolution integrity — validation/normalization mirrors the documented name rules
  • Fee routing changes documented in FEES_AND_GOVERNANCE.md — exact-fee enforcement and dev_module_wallet routing

Documentation

  • README.md or docs/ updated — full docs; CLI guide and deploy script now in English
  • CHANGELOG.md updated — documented under [1.0.0] (this PR is the v1.0.0 landing)
  • Impact on safhandle-sdk noted — N/A (contract API unchanged; the SDK already targets it)

Summary by CodeRabbit

  • New Features

    • Added short-name registration, transfer, release, and lookup support in the contract.
    • Added governance-controlled configuration updates and migration support for reserved names.
  • Bug Fixes

    • Tightened name validation to reject emails, non-ASCII input, invalid punctuation, and reserved/numeric-only labels.
    • Improved fee checks so actions require the exact expected payment.
  • Documentation

    • Updated API, deployment, security, and usage docs to match the current v1 behavior and testnet setup.

@mbagalwa mbagalwa self-assigned this Jul 8, 2026
@mbagalwa mbagalwa added the enhancement New feature or request label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a315b75-f1a0-4845-b9a6-fa76f617f181

📥 Commits

Reviewing files that changed from the base of the PR and between a2d38ca and 19a41ac.

📒 Files selected for processing (54)
  • .cargo/config.toml
  • .gitignore
  • CHANGELOG.md
  • Cargo.toml
  • README.md
  • artifacts/checksums.txt
  • config/mainnet.json
  • config/testnet.json
  • contracts/safhandle/Cargo.toml
  • contracts/safhandle/schema/raw/execute.json
  • contracts/safhandle/schema/raw/instantiate.json
  • contracts/safhandle/schema/raw/migrate.json
  • contracts/safhandle/schema/raw/query.json
  • contracts/safhandle/schema/raw/response_to_config.json
  • contracts/safhandle/schema/raw/response_to_get_address.json
  • contracts/safhandle/schema/raw/response_to_handles.json
  • contracts/safhandle/schema/raw/response_to_name_record.json
  • contracts/safhandle/schema/raw/response_to_resolve_name.json
  • contracts/safhandle/schema/safhandle.json
  • contracts/safhandle/src/bin/schema.rs
  • contracts/safhandle/src/contract.rs
  • contracts/safhandle/src/error.rs
  • contracts/safhandle/src/helpers.rs
  • contracts/safhandle/src/lib.rs
  • contracts/safhandle/src/msg.rs
  • contracts/safhandle/src/state.rs
  • contracts/safhandle/src/validation.rs
  • contracts/safhandle/tests/integration.rs
  • docs/ANTI_SQUATTING.md
  • docs/ARCHITECTURE.md
  • docs/CLI_COMMANDS.md
  • docs/CONTRACT_API.md
  • docs/DEPLOYMENT.md
  • docs/FEES_AND_GOVERNANCE.md
  • docs/HOW_IT_WORKS.md
  • docs/MIGRATION.md
  • docs/NAME_RULES.md
  • docs/PHONE_LINKING.md
  • docs/README.md
  • docs/ROADMAP.md
  • docs/SECURITY_MODEL.md
  • docs/STATE_SCHEMA.md
  • schema/raw/execute.json
  • schema/raw/instantiate.json
  • schema/raw/migrate.json
  • schema/raw/query.json
  • schema/raw/response_to_config.json
  • schema/raw/response_to_get_address.json
  • schema/raw/response_to_handles.json
  • schema/raw/response_to_name_record.json
  • schema/raw/response_to_resolve_name.json
  • schema/safhandle.json
  • scripts/deploy-testnet.sh
  • scripts/verify-repo.test.mjs

📝 Walkthrough

Walkthrough

This PR adds the SafHandle CosmWasm contract crate implementing short-name (.saf) registration with fee enforcement, ownership transfer/release, and governance-updatable config, plus a Cargo-feature-gated phone-linking subsystem (deferred to Phase 2, compiled out by default). It includes JSON schemas, integration tests, a testnet deployment script, workspace/build config, network config updates, and extensive documentation revisions aligning docs with v1 behavior.

Changes

SafHandle contract implementation

Layer / File(s) Summary
Workspace, build, and repo config
Cargo.toml, .cargo/config.toml, .gitignore, CHANGELOG.md
Adds workspace metadata/release profile, wasm target build flags and a wasm cargo alias, reorganizes gitignore rules, and documents the 1.0.0 release.
Crate manifest, state, and message contracts
contracts/safhandle/Cargo.toml, contracts/safhandle/src/lib.rs, contracts/safhandle/src/state.rs, contracts/safhandle/src/msg.rs
Defines the crate manifest with library/phone features, Config/NameRecord/PhoneRecord state and storage maps, and InstantiateMsg/ExecuteMsg/QueryMsg/MigrateMsg types with response structs.
Error types and fee helper
contracts/safhandle/src/error.rs, contracts/safhandle/src/helpers.rs
Adds the ContractError enum and assert_exact_fee helper enforcing exact single-coin payments.
Name and phone validation logic
contracts/safhandle/src/validation.rs
Implements normalize_name/validate_label and feature-gated validate_phone/looks_like_phone with unit tests covering rejection rules.
Contract entry points
contracts/safhandle/src/contract.rs, contracts/safhandle/src/bin/schema.rs
Implements instantiate, execute handlers (register/link/transfer/release/update_config/mark_verified), query routing, and migrate (including legacy phone re-keying), plus the schema-generation binary.
Integration test suite
contracts/safhandle/tests/integration.rs
Adds cw-multi-test-based tests for registration, fees, transfers, releases, reverse lookups, phone linking, and governance-only config updates.
Generated JSON schemas
contracts/safhandle/schema/*, schema/*
Adds JSON Schema definitions for all contract messages and responses in both the contract and root schema directories.
Deployment script and network config
scripts/deploy-testnet.sh, artifacts/checksums.txt, config/testnet.json, config/mainnet.json, scripts/verify-repo.test.mjs
Adds a testnet deployment/store/instantiate script, updates the wasm checksum, updates testnet explorer/contract/wallet addresses, removes phoneLinkFeeUsaf from mainnet config, and updates the repo verification test.
Documentation updates
README.md, docs/*
Revises README and docs (architecture, contract API, CLI commands, deployment, fees/governance, how-it-works, migration, name rules, phone linking, roadmap, security model) to reflect v1 short-name scope and Phase 2 phone-feature gating.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract as SafHandle Contract
    participant NAMES as NAMES Store
    participant OWNER_NAMES as OWNER_NAMES Index
    participant Bank as BankMsg

    User->>Contract: execute(RegisterName{name})
    Contract->>Contract: normalize_name(name)
    Contract->>Contract: check reserved / not taken
    Contract->>OWNER_NAMES: check sender does not already own a name
    Contract->>Contract: assert_exact_fee(info, denom, fee)
    Contract->>NAMES: save NameRecord{owner}
    Contract->>OWNER_NAMES: save sender -> name
    Contract->>Bank: fee_payout to dev_module_wallet
    Contract-->>User: Response(attributes, fee payout msg)
Loading
sequenceDiagram
    participant User
    participant Contract as SafHandle Contract (phone feature)
    participant PHONES as PHONES Store
    participant OWNER_PHONES as OWNER_PHONES Index
    participant Verifier as Governance/Verifier

    User->>Contract: execute(LinkPhone{phone})
    Contract->>Contract: validate_phone(phone)
    Contract->>PHONES: check phone not taken
    Contract->>OWNER_PHONES: check sender does not already own phone
    Contract->>Contract: assert_exact_fee(info, denom, phone_link_fee)
    Contract->>PHONES: save PhoneRecord{owner, verified=false}
    Contract->>OWNER_PHONES: save sender -> phone
    Contract-->>User: Response(attributes, fee payout msg)

    Verifier->>Contract: execute(MarkPhoneVerified{phone})
    Contract->>Contract: authorize governance_admin or VERIFIERS
    Contract->>PHONES: load PhoneRecord
    Contract->>PHONES: update verified=true, verified_at_time
    Contract-->>Verifier: Response(verified attributes)
Loading
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mbagalwa
mbagalwa requested a review from danbaruka July 8, 2026 09:01
@danbaruka
danbaruka merged commit 2b8977b into Safrochain-Org:main Jul 8, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants