Skip to content

Commit 39bc168

Browse files
authored
simplify the set_pool in token admin registry (#106)
* simplify the set_pool in token admin registry * fix test
1 parent b8f7aee commit 39bc168

File tree

4 files changed

+35
-47
lines changed

4 files changed

+35
-47
lines changed

bindings/generated/ccip/ccip/token_admin_registry/token_admin_registry.go

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/ccip/ccip/sources/token_admin_registry.move

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,19 @@ fun unregister_pool_internal(
445445
public fun set_pool<TypeProof: drop>(
446446
ref: &mut CCIPObjectRef,
447447
coin_metadata_address: address,
448-
token_pool_package_id: address,
449-
token_pool_module: String,
450448
lock_or_burn_params: vector<address>,
451449
release_or_mint_params: vector<address>,
452450
_: TypeProof,
453451
ctx: &mut TxContext,
454452
) {
455-
let token_pool_type_proof_tn = type_name::with_defining_ids<TypeProof>();
456-
let token_pool_type_proof_str = type_name::into_string(token_pool_type_proof_tn);
453+
let proof_tn = type_name::with_defining_ids<TypeProof>();
454+
let proof_package_id = address::from_ascii_bytes(&proof_tn.address_string().into_bytes());
455+
let token_pool_module = proof_tn.module_string().into_bytes().to_string();
456+
let token_pool_type_proof_str = type_name::into_string(proof_tn);
457457
set_pool_internal(
458458
ref,
459459
coin_metadata_address,
460-
token_pool_package_id,
460+
proof_package_id,
461461
token_pool_module,
462462
lock_or_burn_params,
463463
release_or_mint_params,

contracts/ccip/ccip/tests/token_admin_registry_tests.move

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const RANDOM_USER: address = @0x3;
3535
// Mock pool addresses
3636
const MOCK_TOKEN_POOL_PACKAGE_ID_1: address =
3737
@0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b;
38-
const MOCK_TOKEN_POOL_PACKAGE_ID_2: address =
39-
@0x8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7;
4038

4139
// === Helper Functions ===
4240

@@ -351,8 +349,6 @@ public fun test_register_and_set_pool() {
351349
registry::set_pool(
352350
&mut ref,
353351
local_token,
354-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
355-
string::utf8(b"mock_token_pool_2"),
356352
vector<address>[], // lock_or_burn_params
357353
vector<address>[], // release_or_mint_params
358354
TypeProof2 {},
@@ -370,12 +366,17 @@ public fun test_register_and_set_pool() {
370366
{
371367
let mut ref = scenario.take_shared<CCIPObjectRef>();
372368

373-
// Verify updated configuration
369+
// Since TypeProof and TypeProof2 have the same package ID, the configuration should remain unchanged
370+
let tn = type_name::with_defining_ids<TypeProof>();
371+
let expected_package_id = address::from_ascii_bytes(&tn.address_string().into_bytes());
372+
let expected_module = tn.module_string().into_bytes().to_string();
373+
374+
// Verify configuration remains unchanged (same package ID means no update)
374375
assert_token_config(
375376
&ref,
376377
local_token,
377-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
378-
b"mock_token_pool_2",
378+
expected_package_id,
379+
expected_module.into_bytes(),
379380
type_name::with_defining_ids<TOKEN_ADMIN_REGISTRY_TESTS>().into_string(),
380381
TOKEN_ADMIN_ADDRESS,
381382
TOKEN_ADMIN_ADDRESS_2,
@@ -388,7 +389,8 @@ public fun test_register_and_set_pool() {
388389
assert!(
389390
token_type == ascii::string(b"0000000000000000000000000000000000000000000000000000000000001000::token_admin_registry_tests::TOKEN_ADMIN_REGISTRY_TESTS"),
390391
);
391-
assert!(type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof2>()));
392+
// Since TypeProof and TypeProof2 have the same package ID, the type proof should remain as TypeProof
393+
assert!(type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof>()));
392394

393395
// Accept admin role
394396
registry::accept_admin_role(&mut ref, local_token, scenario.ctx());
@@ -584,20 +586,23 @@ public fun test_set_pool_comprehensive() {
584586
registry::set_pool(
585587
&mut ref,
586588
local_token,
587-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
588-
string::utf8(b"updated_token_pool"),
589589
vector<address>[], // lock_or_burn_params
590590
vector<address>[], // release_or_mint_params
591591
TypeProof2 {},
592592
ctx,
593593
);
594594

595-
// Verify pool was updated
595+
// Since TypeProof and TypeProof2 have the same package ID, the configuration should remain unchanged
596+
let tn = type_name::with_defining_ids<TypeProof>();
597+
let expected_package_id = address::from_ascii_bytes(&tn.address_string().into_bytes());
598+
let expected_module = tn.module_string().into_bytes().to_string();
599+
600+
// Verify pool was NOT updated (same package ID means no change)
596601
assert_token_config(
597602
&ref,
598603
local_token,
599-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
600-
b"updated_token_pool",
604+
expected_package_id,
605+
expected_module.into_bytes(),
601606
type_name::with_defining_ids<TOKEN_ADMIN_REGISTRY_TESTS>().into_string(),
602607
TOKEN_ADMIN_ADDRESS,
603608
@0x0,
@@ -607,16 +612,15 @@ public fun test_set_pool_comprehensive() {
607612
&ref,
608613
local_token,
609614
);
615+
// Since TypeProof and TypeProof2 have the same package ID, the type proof should remain as TypeProof
610616
assert!(
611-
updated_type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof2>()),
617+
updated_type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof>()),
612618
);
613619

614620
// Test set_pool with same package ID (should not trigger update)
615621
registry::set_pool(
616622
&mut ref,
617623
local_token,
618-
MOCK_TOKEN_POOL_PACKAGE_ID_2, // same package ID
619-
string::utf8(b"should_not_update"),
620624
vector<address>[], // lock_or_burn_params
621625
vector<address>[], // release_or_mint_params
622626
TypeProof {},
@@ -627,8 +631,8 @@ public fun test_set_pool_comprehensive() {
627631
assert_token_config(
628632
&ref,
629633
local_token,
630-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
631-
b"updated_token_pool", // unchanged
634+
expected_package_id, // unchanged from TypeProof
635+
expected_module.into_bytes(), // unchanged from TypeProof
632636
type_name::with_defining_ids<TOKEN_ADMIN_REGISTRY_TESTS>().into_string(),
633637
TOKEN_ADMIN_ADDRESS,
634638
@0x0,
@@ -639,7 +643,7 @@ public fun test_set_pool_comprehensive() {
639643
local_token,
640644
);
641645
assert!(
642-
final_type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof2>()),
646+
final_type_proof == type_name::into_string(type_name::with_defining_ids<TypeProof>()),
643647
); // unchanged
644648

645649
transfer::public_transfer(treasury_cap, ctx.sender());
@@ -750,8 +754,6 @@ public fun test_set_pool_unregistered_token() {
750754
registry::set_pool(
751755
&mut ref,
752756
@0x999, // unregistered token
753-
MOCK_TOKEN_POOL_PACKAGE_ID_1,
754-
string::utf8(b"test_pool"),
755757
vector<address>[], // lock_or_burn_params
756758
vector<address>[], // release_or_mint_params
757759
TypeProof {},
@@ -800,8 +802,6 @@ public fun test_set_pool_unauthorized() {
800802
registry::set_pool(
801803
&mut ref,
802804
local_token,
803-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
804-
string::utf8(b"unauthorized_update"),
805805
vector<address>[], // lock_or_burn_params
806806
vector<address>[], // release_or_mint_params
807807
TypeProof2 {},
@@ -1442,8 +1442,6 @@ public fun test_set_pool_function_not_allowed() {
14421442
registry::set_pool(
14431443
&mut ref,
14441444
local_token,
1445-
MOCK_TOKEN_POOL_PACKAGE_ID_2,
1446-
string::utf8(b"updated_pool"),
14471445
vector<address>[], // lock_or_burn_params
14481446
vector<address>[], // release_or_mint_params
14491447
TypeProof2 {},

0 commit comments

Comments
 (0)