@@ -9,28 +9,21 @@ use polkadot_sdk::{
99} ;
1010use test_utils:: {
1111 as_tors, get_origin, new_test_ext, pallet_governance, pallet_permission0:: Permissions ,
12- Balances , Test ,
12+ Balances , Test , Torus0 ,
1313} ;
1414
1515/// Helper function to register an agent with a specific name and balance
1616fn register_agent_with ( account_id : u32 , name : & str , balance : u128 ) {
17- // Register the agent with the specified name
18- pallet_torus0:: Agents :: < Test > :: set (
19- account_id,
20- Some ( pallet_torus0:: agent:: Agent {
21- key : account_id,
22- name : name. as_bytes ( ) . to_vec ( ) . try_into ( ) . unwrap ( ) ,
23- url : Default :: default ( ) ,
24- metadata : Default :: default ( ) ,
25- weight_penalty_factor : Default :: default ( ) ,
26- registration_block : <polkadot_sdk:: frame_system:: Pallet < Test > >:: block_number ( ) ,
27- fees : Default :: default ( ) ,
28- last_update_block : Default :: default ( ) ,
29- } ) ,
30- ) ;
31-
3217 // Set the balance for the account
3318 let _ = Balances :: deposit_creating ( & account_id, balance) ;
19+ let name = name. as_bytes ( ) . to_vec ( ) ;
20+ Torus0 :: register_agent (
21+ get_origin ( account_id) ,
22+ name. clone ( ) ,
23+ name. clone ( ) ,
24+ name. clone ( ) ,
25+ )
26+ . unwrap ( ) ;
3427}
3528
3629fn set_namespace_config ( ) {
@@ -155,7 +148,7 @@ fn namespace_fee_zero_steepness() {
155148
156149 // steepness is 0, so always expect midpoint
157150 let expected = 1000 + 1000 ;
158- assert_eq ! ( fee_0, expected ) ;
151+ assert_eq ! ( fee_0, 0 ) ;
159152 assert_eq ! ( fee_10, expected) ;
160153 assert_eq ! ( fee_20, expected) ;
161154 } ) ;
@@ -239,9 +232,9 @@ fn namespace_deposit_basic() {
239232 max_fee_multiplier : 100 ,
240233 } ;
241234
242- // The simple agent path
235+ // The root agent path has no deposit requirement
243236 let path_agent = "agent.alice" . parse ( ) . unwrap ( ) ;
244- assert_eq ! ( config. namespace_deposit( & path_agent) , 1100 ) ;
237+ assert_eq ! ( config. namespace_deposit( & path_agent) , 0 ) ;
245238
246239 // Single character
247240 let path_a = "agent.alice.a" . parse ( ) . unwrap ( ) ;
@@ -340,7 +333,7 @@ fn namespace_fee_precision_handling() {
340333 let fee_1 = config. namespace_fee ( 1 ) . unwrap ( ) ;
341334 let fee_2 = config. namespace_fee ( 2 ) . unwrap ( ) ;
342335
343- assert ! ( fee_0 > as_tors ( 1 ) ) ;
336+ assert_eq ! ( fee_0, 0 ) ;
344337 assert ! ( fee_1 > fee_0) ;
345338 assert ! ( fee_2 > fee_1) ;
346339 } ) ;
@@ -534,6 +527,7 @@ fn calculate_cost_no_existing_namespaces() {
534527 test_utils:: register_empty_agent ( owner) ;
535528
536529 let paths: & [ NamespacePath ] = & [
530+ "agent.alice" . parse ( ) . unwrap ( ) ,
537531 "agent.alice.v1" . parse ( ) . unwrap ( ) ,
538532 "agent.alice.v1.compute" . parse ( ) . unwrap ( ) ,
539533 "agent.alice.v1.compute.gpu" . parse ( ) . unwrap ( ) ,
@@ -763,7 +757,7 @@ fn namespace_must_start_with_agent_prefix() {
763757 // Verify that a valid namespace starting with "agent." works
764758 assert_ok ! ( pallet_torus0:: Pallet :: <Test >:: create_namespace(
765759 get_origin( 0 ) ,
766- BoundedVec :: truncate_from( b"agent.alice" . to_vec( ) )
760+ BoundedVec :: truncate_from( b"agent.alice.bla " . to_vec( ) )
767761 ) ) ;
768762 } ) ;
769763}
@@ -776,13 +770,13 @@ fn create_namespace_simple() {
776770
777771 assert_ok ! ( pallet_torus0:: Pallet :: <Test >:: create_namespace(
778772 get_origin( 0 ) ,
779- BoundedVec :: truncate_from( b"agent.alice" . to_vec( ) )
773+ BoundedVec :: truncate_from( b"agent.alice.a " . to_vec( ) )
780774 ) ) ;
781775
782776 // Verify namespace was created
783777 assert ! ( pallet_torus0:: Namespaces :: <Test >:: contains_key(
784778 pallet_torus0:: namespace:: NamespaceOwnership :: Account ( 0 ) ,
785- pallet_torus0_api:: NamespacePath :: new_agent( b"agent.alice" ) . unwrap( )
779+ pallet_torus0_api:: NamespacePath :: new_agent( b"agent.alice.a " ) . unwrap( )
786780 ) ) ;
787781 } ) ;
788782}
@@ -830,11 +824,11 @@ fn create_namespace_already_exists() {
830824 } ;
831825
832826 // Create namespace first time
833- assert_ok ! ( create_namespace( b"agent.alice" ) ) ;
827+ assert_ok ! ( create_namespace( b"agent.alice.a " ) ) ;
834828
835829 // Try to create same namespace again
836830 assert_err ! (
837- create_namespace( b"agent.alice" ) ,
831+ create_namespace( b"agent.alice.a " ) ,
838832 pallet_torus0:: Error :: <Test >:: NamespaceAlreadyExists
839833 ) ;
840834 } ) ;
@@ -882,7 +876,7 @@ fn create_namespace_insufficient_balance() {
882876 assert_err ! (
883877 pallet_torus0:: Pallet :: <Test >:: create_namespace(
884878 get_origin( 0 ) ,
885- BoundedVec :: truncate_from( b"agent.alice" . to_vec( ) )
879+ BoundedVec :: truncate_from( b"agent.alice.b " . to_vec( ) )
886880 ) ,
887881 pallet_balances:: Error :: <Test >:: InsufficientBalance
888882 ) ;
0 commit comments