Skip to content

JSON-RPC support for serving fake coins#25916

Open
mystenmark wants to merge 16 commits intointegrate-coin-smashingfrom
mlogan-json-rpc-fake-coins
Open

JSON-RPC support for serving fake coins#25916
mystenmark wants to merge 16 commits intointegrate-coin-smashingfrom
mlogan-json-rpc-fake-coins

Conversation

@mystenmark
Copy link
Contributor

Summary

  • Add JSON-RPC support for serving fake coins via suix_getCoins and sui_getObject
  • Fake coin representing address balance is always returned at position 1 (second position) in getCoins results
  • Pagination is handled correctly - fake coin only appears once
  • Add RPC integration tests

Stack: Depends on #25818

Changes

  • Add encode_object_ref() helper to coin_reservation module
  • Add get_address_balance_coin_info() to AuthorityState
  • Update get_object_read() to return fake coins for masked object IDs
  • Update get_owned_coins() to include fake coin at position 1

Test plan

  • test_rpc_get_object_returns_fake_coin: verifies sui_getObject
  • test_rpc_get_coins_includes_fake_coin_at_position_1: verifies fake coin at position 1
  • test_rpc_get_coins_pagination_handles_fake_coin: verifies pagination
  • test_rpc_get_balance_includes_address_balance: verifies suix_getBalance

🤖 Generated with Claude Code

@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:11 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sui-docs Ready Ready Preview, Comment Mar 20, 2026 11:00pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
multisig-toolkit Ignored Ignored Preview Mar 20, 2026 11:00pm
sui-kiosk Ignored Ignored Preview Mar 20, 2026 11:00pm

Request Review

When clients don't understand address balances, the JSON-RPC server can
return "fake" coin objects representing address balances. The fake coin
is always returned at position 1 (second position) in the getCoins
results, after the first real coin.

Changes:
- Add encode_object_ref() helper to coin_reservation module
- Add get_address_balance_coin_info() to AuthorityState
- Update get_owned_coins() to include fake coin at position 1
- Handle pagination correctly - fake coin only returned once
- Add RPC integration tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mystenmark mystenmark force-pushed the mlogan-json-rpc-fake-coins branch from 5d32db1 to 3594b9c Compare March 20, 2026 17:26
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:26 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:26 — with GitHub Actions Inactive
- Extract to_sui_coin helper function (eliminates 7 repetitions)
- Only fetch first_real_coin when actually needed
- Use iterator chaining with .extend() and .take()
- Reduce deeply nested conditionals

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use grpc_client instead of deprecated rpc_client field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:38 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:39 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:41 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:43 — with GitHub Actions Inactive
@mystenmark mystenmark force-pushed the mlogan-json-rpc-fake-coins branch from a30cd39 to 5114936 Compare March 20, 2026 17:48
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:48 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:48 — with GitHub Actions Inactive
@mystenmark mystenmark force-pushed the mlogan-json-rpc-fake-coins branch from 5114936 to e58c5ba Compare March 20, 2026 17:53
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:53 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:53 — with GitHub Actions Inactive
@mystenmark mystenmark force-pushed the mlogan-json-rpc-fake-coins branch from e58c5ba to 0af0fa5 Compare March 20, 2026 17:57
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 17:57 — with GitHub Actions Inactive
Only need limit+1 real coins when skip_first is true (cursor at fake coin),
not limit*2 in all cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mystenmark mystenmark force-pushed the mlogan-json-rpc-fake-coins branch from 485ad32 to cb71388 Compare March 20, 2026 19:58
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 19:58 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 19:58 — with GitHub Actions Inactive
- Remove extra DB query to check cursor_at_first_real
- Replace multiple state variables with two HashMaps (fake_emitted, seen_first_real)
- Simplify cursor state detection: non-zero cursor not at fake = past fake slot
- Cleaner iteration loop with less branching

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The getAllCoins test requires real coins to exist for each coin type
to verify fake coin ordering. Modify publish_and_mint_trusted_coin to
mint two coins: one for address balance and one to keep as a real coin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 20:35 — with GitHub Actions Inactive
@mystenmark mystenmark temporarily deployed to sui-typescript-aws-kms-test-env March 20, 2026 20:35 — with GitHub Actions Inactive
Per PR review feedback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bug fix: When getAllCoins was called with multiple coin types where some
types had only address balance (no real coins), the fake coins for those
types were not being emitted. This is because the fallback logic only
triggered when ALL types had no real coins.

Also refactored the RPC tests to use a data-driven approach:
- Added CoinTypeConfig struct to specify test scenarios
- Added helper methods: transfer_sui_coin, fund_address_balance_for_recipient,
  publish_trusted_coin_and_setup
- Created parameterized scenario tests that verify both getCoins and
  getAllCoins return correct real/fake coin counts
- Added test_scenario_two_types_custom_address_balance_only which
  specifically tests the bug fix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Refactored TestEnv to use composable building blocks:
- publish_trusted_coin: just publishes, returns (package_id, coin_type, treasury_cap)
- mint_trusted_coin: mints one coin, returns (coin_ref, new_treasury_cap)
- transfer_coin: transfers any coin to recipient
- transfer_sui: transfers SUI from gas to recipient
- transfer_sui_to_address_balance: transfers SUI to recipient's address balance

publish_trusted_coin_and_setup now composes these primitives.
Legacy publish_and_mint_trusted_coin preserved as a wrapper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants