-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 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
Showing
17 changed files
with
1,025 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
17 changes: 17 additions & 0 deletions
17
crates/sui-indexer-alt-e2e-tests/packages/suins/sources/domain.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
crates/sui-indexer-alt-e2e-tests/packages/suins/sources/suins.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
crates/sui-indexer-alt-e2e-tests/tests/jsonrpc/name_service.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
103
crates/sui-indexer-alt-e2e-tests/tests/jsonrpc/name_service.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.