@@ -54,4 +54,91 @@ describe('DPNSFacade', () => {
5454 expect ( wasmSdk . getDpnsUsernameByName ) . to . be . calledOnceWithExactly ( 'u' ) ;
5555 expect ( wasmSdk . getDpnsUsernameByNameWithProofInfo ) . to . be . calledOnceWithExactly ( 'u' ) ;
5656 } ) ;
57+
58+ describe ( 'registerName validation' , ( ) => {
59+ it ( 'should throw error when publicKeyId is not provided' , async ( ) => {
60+ try {
61+ await client . dpns . registerName ( {
62+ label : 'test' ,
63+ identityId : 'someId' ,
64+ privateKeyWif : 'someKey' ,
65+ // publicKeyId intentionally omitted
66+ } ) ;
67+ expect . fail ( 'Should have thrown an error' ) ;
68+ } catch ( error ) {
69+ expect ( error . message ) . to . include ( 'publicKeyId is required' ) ;
70+ expect ( error . message ) . to . include ( 'CRITICAL or HIGH security level' ) ;
71+ expect ( error . message ) . to . include ( 'Do NOT use Key 0' ) ;
72+ }
73+ } ) ;
74+
75+ it ( 'should throw error when publicKeyId is undefined' , async ( ) => {
76+ try {
77+ await client . dpns . registerName ( {
78+ label : 'test' ,
79+ identityId : 'someId' ,
80+ publicKeyId : undefined ,
81+ privateKeyWif : 'someKey' ,
82+ } ) ;
83+ expect . fail ( 'Should have thrown an error' ) ;
84+ } catch ( error ) {
85+ expect ( error . message ) . to . include ( 'publicKeyId is required' ) ;
86+ expect ( error . message ) . to . include ( 'CRITICAL or HIGH security level' ) ;
87+ expect ( error . message ) . to . include ( 'Do NOT use Key 0' ) ;
88+ }
89+ } ) ;
90+
91+ it ( 'should throw error when publicKeyId is null' , async ( ) => {
92+ try {
93+ await client . dpns . registerName ( {
94+ label : 'test' ,
95+ identityId : 'someId' ,
96+ publicKeyId : null ,
97+ privateKeyWif : 'someKey' ,
98+ } ) ;
99+ expect . fail ( 'Should have thrown an error' ) ;
100+ } catch ( error ) {
101+ expect ( error . message ) . to . include ( 'publicKeyId is required' ) ;
102+ }
103+ } ) ;
104+
105+ it ( 'should throw error when publicKeyId is negative' , async ( ) => {
106+ try {
107+ await client . dpns . registerName ( {
108+ label : 'test' ,
109+ identityId : 'someId' ,
110+ publicKeyId : - 1 ,
111+ privateKeyWif : 'someKey' ,
112+ } ) ;
113+ expect . fail ( 'Should have thrown an error' ) ;
114+ } catch ( error ) {
115+ expect ( error . message ) . to . include ( 'must be a non-negative number' ) ;
116+ expect ( error . message ) . to . include ( 'got: -1' ) ;
117+ }
118+ } ) ;
119+
120+ it ( 'should throw error when publicKeyId is not a number' , async ( ) => {
121+ try {
122+ await client . dpns . registerName ( {
123+ label : 'test' ,
124+ identityId : 'someId' ,
125+ publicKeyId : '1' ,
126+ privateKeyWif : 'someKey' ,
127+ } ) ;
128+ expect . fail ( 'Should have thrown an error' ) ;
129+ } catch ( error ) {
130+ expect ( error . message ) . to . include ( 'must be a non-negative number' ) ;
131+ }
132+ } ) ;
133+
134+ it ( 'should accept valid publicKeyId' , async ( ) => {
135+ await client . dpns . registerName ( {
136+ label : 'test' ,
137+ identityId : 'someId' ,
138+ publicKeyId : 1 ,
139+ privateKeyWif : 'someKey' ,
140+ } ) ;
141+ expect ( wasmSdk . dpnsRegisterName ) . to . be . calledOnce ( ) ;
142+ } ) ;
143+ } ) ;
57144} ) ;
0 commit comments