Skip to content

Commit

Permalink
rpc-alt: resolveNameServiceAddress
Browse files Browse the repository at this point in the history
## Description

Adds support for SuiNS name resolution.

## Test plan

New E2E tests, based on `FullCluster`:

```
sui$ cargo nextest run -p sui-indexer-alt-e2e-tests \
  -- test_resolve name_service
```
  • Loading branch information
amnn committed Feb 13, 2025
1 parent b9a3b2c commit 59780d4
Show file tree
Hide file tree
Showing 17 changed files with 1,025 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ msim.workspace = true
[dev-dependencies]
async-trait.workspace = true
datatest-stable.workspace = true
jsonrpsee.workspace = true
reqwest.workspace = true
serde_json.workspace = true
telemetry-subscribers.workspace = true

move-core-types.workspace = true

sui-move-build.workspace = true
sui-transactional-test-runner.workspace = true
9 changes: 9 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/packages/suins/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "suins"
edition = "2024.beta"

[dependencies]
Sui = { local = "../../../sui-framework/packages/sui-framework" }

[addresses]
suins = "0x0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// A mock of the SuiNS Domain type. It needs to be in its own module because
/// we hash its type off-chain, and while we can control which address we find
/// the package at, we don't control which module it is found in.
module suins::domain;

use std::string::String;

public struct Domain has copy, drop, store {
labels: vector<String>,
}

public(package) fun new(labels: vector<String>): Domain {
Domain { labels }
}
52 changes: 52 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/packages/suins/sources/suins.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// A mock of the SuiNS Move package to use during testing.
///
/// It provides enough structure to query SuiNS's on-chain state, but it
/// doesn't maintain the same invariants.
module suins::suins;

use std::string::String;
use sui::table::{Self, Table};
use sui::vec_map::{Self, VecMap};

use suins::domain::{Self, Domain};

public struct NameRecord has copy, drop, store {
nft_id: ID,
expiration_timestamp_ms: u64,
target_address: Option<address>,
data: VecMap<String, String>,
}

public fun share_forward_registry(ctx: &mut TxContext) {
let registry: Table<Domain, NameRecord> = table::new(ctx);
transfer::public_share_object(registry)
}

public fun share_reverse_registry(ctx: &mut TxContext) {
let registry: Table<address, Domain> = table::new(ctx);
transfer::public_share_object(registry)
}

public fun add_domain(
forward_registry: &mut Table<Domain, NameRecord>,
reverse_registry: &mut Table<address, Domain>,
nft_id: ID,
labels: vector<String>,
target_address: Option<address>,
expiration_timestamp_ms: u64,
) {
let domain = domain::new(labels);

let name_record = NameRecord {
nft_id,
expiration_timestamp_ms,
target_address,
data: vec_map::empty(),
};

forward_registry.add(domain, name_record);
target_address.do!(|t| reverse_registry.add(t, domain));
}
66 changes: 66 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/tests/jsonrpc/name_service.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 70 --simulator

// Testing various input errors for the SuiNS name resolution:
// 1. Not enough labels (need at least two)
// 2. Too long
// 3. Bad (inconsistent) use of separators
// 4. Indvidual label too short
// 5. Individual label too long
// 6, 7, 8, 9. Bad characters (non-alphanumeric, or leading/trailing hyphen)

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["foo"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.toolong.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["foo*bar.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["foo..sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["-foo.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["foo-.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["foo_bar.sui"]
}

//# run-jsonrpc
{
"method": "suix_resolveNameServiceAddress",
"params": ["🫠.sui"]
}
103 changes: 103 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/tests/jsonrpc/name_service.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
---
processed 10 tasks

task 1, lines 14-18:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 0,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Domain must contain at least one label"
}
}

task 2, lines 20-24:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: String length: 243 exceeds maximum allowed length: 200"
}
}

task 3, lines 26-30:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Domain must include only one separator"
}
}

task 4, lines 32-36:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: String length: 0 outside of valid range: [1, 63]"
}
}

task 5, lines 38-42:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 4,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: String length: 70 outside of valid range: [1, 63]"
}
}

task 6, lines 44-48:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 5,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Hyphens are not allowed as the first or last character"
}
}

task 7, lines 50-54:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 6,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Hyphens are not allowed as the first or last character"
}
}

task 8, lines 56-60:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 7,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Only lowercase letters, numbers, and hyphens are allowed"
}
}

task 9, lines 62-66:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 8,
"error": {
"code": -32602,
"message": "Invalid Params: Name Service: Only lowercase letters, numbers, and hyphens are allowed"
}
}
Loading

0 comments on commit 59780d4

Please sign in to comment.