@@ -43,7 +43,7 @@ describe('CreateLocalKeyChain codec tests', function () {
4343 } ) ;
4444
4545 describe ( 'CreateLocalKeyChainResponse' , function ( ) {
46- it ( 'should validate response with required fields ' , function ( ) {
46+ it ( 'should validate response with required xprv field ' , function ( ) {
4747 const validResponse = {
4848 xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
4949 xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
@@ -52,20 +52,17 @@ describe('CreateLocalKeyChain codec tests', function () {
5252 const decoded = assertDecode ( CreateLocalKeyChainResponse , validResponse ) ;
5353 assert . strictEqual ( decoded . xprv , validResponse . xprv ) ;
5454 assert . strictEqual ( decoded . xpub , validResponse . xpub ) ;
55- assert . strictEqual ( decoded . ethAddress , undefined ) ; // Optional field
5655 } ) ;
5756
58- it ( 'should validate response with all fields including optional ones ' , function ( ) {
57+ it ( 'should validate response with both xprv and xpub fields ' , function ( ) {
5958 const validResponse = {
6059 xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
6160 xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
62- ethAddress : '0x1234567890123456789012345678901234567890' ,
6361 } ;
6462
6563 const decoded = assertDecode ( CreateLocalKeyChainResponse , validResponse ) ;
6664 assert . strictEqual ( decoded . xprv , validResponse . xprv ) ;
6765 assert . strictEqual ( decoded . xpub , validResponse . xpub ) ;
68- assert . strictEqual ( decoded . ethAddress , validResponse . ethAddress ) ;
6966 } ) ;
7067
7168 it ( 'should reject response with missing xprv' , function ( ) {
@@ -78,14 +75,15 @@ describe('CreateLocalKeyChain codec tests', function () {
7875 } ) ;
7976 } ) ;
8077
81- it ( 'should reject response with missing xpub ' , function ( ) {
82- const invalidResponse = {
78+ it ( 'should allow response with missing ethAddress (optional) ' , function ( ) {
79+ const validResponse = {
8380 xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
81+ xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
8482 } ;
8583
86- assert . throws ( ( ) => {
87- assertDecode ( CreateLocalKeyChainResponse , invalidResponse ) ;
88- } ) ;
84+ const decoded = assertDecode ( CreateLocalKeyChainResponse , validResponse ) ;
85+ assert . strictEqual ( decoded . xprv , validResponse . xprv ) ;
86+ assert . strictEqual ( decoded . xpub , validResponse . xpub ) ;
8987 } ) ;
9088
9189 it ( 'should reject response with non-string xprv' , function ( ) {
@@ -109,18 +107,6 @@ describe('CreateLocalKeyChain codec tests', function () {
109107 assertDecode ( CreateLocalKeyChainResponse , invalidResponse ) ;
110108 } ) ;
111109 } ) ;
112-
113- it ( 'should reject response with non-string ethAddress' , function ( ) {
114- const invalidResponse = {
115- xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
116- xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
117- ethAddress : 123 , // number instead of string
118- } ;
119-
120- assert . throws ( ( ) => {
121- assertDecode ( CreateLocalKeyChainResponse , invalidResponse ) ;
122- } ) ;
123- } ) ;
124110 } ) ;
125111
126112 describe ( 'Edge cases' , function ( ) {
@@ -177,6 +163,7 @@ describe('CreateLocalKeyChain codec tests', function () {
177163 const mockKeychainResponse = {
178164 xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
179165 xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
166+ ethAddress : '0x1234567890123456789012345678901234567890' ,
180167 } ;
181168
182169 afterEach ( function ( ) {
@@ -541,6 +528,7 @@ describe('CreateLocalKeyChain codec tests', function () {
541528 create : sinon . stub ( ) . resolves ( {
542529 xprv : longXprv ,
543530 xpub : longXpub ,
531+ ethAddress : '0x1234567890123456789012345678901234567890' ,
544532 } ) ,
545533 } ;
546534
@@ -560,32 +548,6 @@ describe('CreateLocalKeyChain codec tests', function () {
560548 assert . strictEqual ( decodedResponse . xprv , longXprv ) ;
561549 } ) ;
562550
563- it ( 'should handle response with empty ethAddress' , async function ( ) {
564- const requestBody = { } ;
565-
566- const mockKeychains = {
567- create : sinon . stub ( ) . resolves ( {
568- xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
569- xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
570- ethAddress : '' ,
571- } ) ,
572- } ;
573-
574- sinon . stub ( BitGo . prototype , 'keychains' ) . returns ( mockKeychains as any ) ;
575-
576- const result = await agent
577- . post ( '/api/v1/keychain/local' )
578- . set ( 'Authorization' , 'Bearer test_access_token_12345' )
579- . set ( 'Content-Type' , 'application/json' )
580- . send ( requestBody ) ;
581-
582- assert . strictEqual ( result . status , 200 ) ;
583- assert . strictEqual ( result . body . ethAddress , '' ) ;
584-
585- const decodedResponse = assertDecode ( CreateLocalKeyChainResponse , result . body ) ;
586- assert . strictEqual ( decodedResponse . ethAddress , '' ) ;
587- } ) ;
588-
589551 it ( 'should handle response with additional unexpected fields' , async function ( ) {
590552 const requestBody = { } ;
591553
@@ -608,11 +570,7 @@ describe('CreateLocalKeyChain codec tests', function () {
608570
609571 assert . strictEqual ( result . status , 200 ) ;
610572 // Codec validation should still pass with required fields present
611- const decodedResponse = assertDecode ( CreateLocalKeyChainResponse , {
612- xprv : result . body . xprv ,
613- xpub : result . body . xpub ,
614- ethAddress : result . body . ethAddress ,
615- } ) ;
573+ const decodedResponse = assertDecode ( CreateLocalKeyChainResponse , result . body ) ;
616574 assert . ok ( decodedResponse ) ;
617575 } ) ;
618576
@@ -683,15 +641,17 @@ describe('CreateLocalKeyChain codec tests', function () {
683641 } ) ;
684642 } ) ;
685643
686- it ( 'should reject response with missing xpub field' , async function ( ) {
644+ it ( 'should allow response with missing ethAddress field (optional) ' , async function ( ) {
687645 const requestBody = { } ;
688646
689- const invalidResponse = {
647+ const validResponse = {
690648 xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
649+ xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
650+ // ethAddress is optional, so missing it is valid
691651 } ;
692652
693653 const mockKeychains = {
694- create : sinon . stub ( ) . resolves ( invalidResponse ) ,
654+ create : sinon . stub ( ) . resolves ( validResponse ) ,
695655 } ;
696656
697657 sinon . stub ( BitGo . prototype , 'keychains' ) . returns ( mockKeychains as any ) ;
@@ -702,11 +662,11 @@ describe('CreateLocalKeyChain codec tests', function () {
702662 . set ( 'Content-Type' , 'application/json' )
703663 . send ( requestBody ) ;
704664
705- // Framework returns 200 with invalid response, codec validation should fail
665+ // pub is optional, so this should pass
706666 assert . strictEqual ( result . status , 200 ) ;
707- assert . throws ( ( ) => {
708- assertDecode ( CreateLocalKeyChainResponse , result . body ) ;
709- } ) ;
667+ const decodedResponse = assertDecode ( CreateLocalKeyChainResponse , result . body ) ;
668+ assert . strictEqual ( decodedResponse . xprv , validResponse . xprv ) ;
669+ assert . strictEqual ( decodedResponse . xpub , validResponse . xpub ) ;
710670 } ) ;
711671
712672 it ( 'should reject response with wrong type for xprv' , async function ( ) {
@@ -763,34 +723,6 @@ describe('CreateLocalKeyChain codec tests', function () {
763723 } ) ;
764724 } ) ;
765725
766- it ( 'should reject response with wrong type for ethAddress' , async function ( ) {
767- const requestBody = { } ;
768-
769- const invalidResponse = {
770- xprv : 'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2' ,
771- xpub : 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8' ,
772- ethAddress : 123 , // number instead of string
773- } ;
774-
775- const mockKeychains = {
776- create : sinon . stub ( ) . resolves ( invalidResponse ) ,
777- } ;
778-
779- sinon . stub ( BitGo . prototype , 'keychains' ) . returns ( mockKeychains as any ) ;
780-
781- const result = await agent
782- . post ( '/api/v1/keychain/local' )
783- . set ( 'Authorization' , 'Bearer test_access_token_12345' )
784- . set ( 'Content-Type' , 'application/json' )
785- . send ( requestBody ) ;
786-
787- // Framework returns 200 with invalid response, codec validation should fail
788- assert . strictEqual ( result . status , 200 ) ;
789- assert . throws ( ( ) => {
790- assertDecode ( CreateLocalKeyChainResponse , result . body ) ;
791- } ) ;
792- } ) ;
793-
794726 it ( 'should reject response with empty object' , async function ( ) {
795727 const requestBody = { } ;
796728
0 commit comments