Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walrus Site ID #237

Open
wants to merge 2 commits into
base: ml/new-payments-design
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/suins/sources/controller.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use suins::suins_registration::SuinsRegistration;

const AVATAR: vector<u8> = b"avatar";
const CONTENT_HASH: vector<u8> = b"content_hash";
const WALRUS_SITE_ID: vector<u8> = b"walrus_site_id";

use fun registry_mut as SuiNS.registry_mut;

Expand Down Expand Up @@ -73,7 +74,7 @@ public fun set_user_data(

registry.assert_nft_is_authorized(nft, clock);
let key_bytes = *key.as_bytes();
assert!(key_bytes == AVATAR || key_bytes == CONTENT_HASH, EUnsupportedKey);
assert!(key_bytes == AVATAR || key_bytes == CONTENT_HASH || key_bytes == WALRUS_SITE_ID, EUnsupportedKey);

if (data.contains(&key)) {
data.remove(&key);
Expand Down
26 changes: 26 additions & 0 deletions packages/suins/tests/controller_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SECOND_ADDRESS: address = @0xB002;
const DOMAIN_NAME: vector<u8> = b"abc.sui";
const AVATAR: vector<u8> = b"avatar";
const CONTENT_HASH: vector<u8> = b"content_hash";
const WALRUS_SITE_ID: vector<u8> = b"walrus_site_id";

fun test_init(): Scenario {
let mut scenario_val = test_scenario::begin(SUINS_ADDRESS);
Expand Down Expand Up @@ -441,6 +442,19 @@ fun test_set_user_data() {
assert_eq(*data.get(&AVATAR.to_string()), b"value_avatar".to_string());
assert_eq(*data.get(&utf8(CONTENT_HASH)), b"value_content_hash".to_string());

set_user_data_util(
scenario,
FIRST_ADDRESS,
utf8(WALRUS_SITE_ID),
b"value_walrus_site_id".to_string(),
0,
);
let data = &scenario.get_user_data(DOMAIN_NAME.to_string());
assert_eq(data.size(), 3);
assert_eq(*data.get(&AVATAR.to_string()), b"value_avatar".to_string());
assert_eq(*data.get(&utf8(CONTENT_HASH)), b"value_content_hash".to_string());
assert_eq(*data.get(&WALRUS_SITE_ID.to_string()), b"value_walrus_site_id".to_string());

scenario_val.end();
}

Expand Down Expand Up @@ -562,8 +576,20 @@ fun test_unset_user_data() {
b"value_avatar".to_string(),
0,
);
scenario.set_user_data_util(
FIRST_ADDRESS,
WALRUS_SITE_ID.to_string(),
b"value_walrus_site_id".to_string(),
0,
);
scenario.unset_user_data_util(FIRST_ADDRESS, utf8(CONTENT_HASH), 0);
let data = &scenario.get_user_data(DOMAIN_NAME.to_string());
assert_eq(data.size(), 2);
assert_eq(*data.get(&AVATAR.to_string()), b"value_avatar".to_string());
assert_eq(*data.get(&WALRUS_SITE_ID.to_string()), b"value_walrus_site_id".to_string());

scenario.unset_user_data_util(FIRST_ADDRESS, WALRUS_SITE_ID.to_string(), 0);
let data = &scenario.get_user_data(DOMAIN_NAME.to_string());
assert_eq(data.size(), 1);
assert_eq(*data.get(&AVATAR.to_string()), b"value_avatar".to_string());

Expand Down
Loading