22//
33// SPDX-License-Identifier: Apache-2.0
44
5- import crypto from 'crypto'
5+
66import { expect , describe , it , vi } from 'vitest'
77import { DstackClient , TappdClient } from '../index'
88import { toViemAccount , toViemAccountSecure } from '../viem'
@@ -13,7 +13,7 @@ describe('viem support', () => {
1313 const client = new DstackClient ( )
1414 const result = await client . getKey ( '/' , 'test' )
1515 const account = toViemAccount ( result )
16-
16+
1717 expect ( account . source ) . toBe ( 'privateKey' )
1818 expect ( typeof account . sign ) . toBe ( 'function' )
1919 expect ( typeof account . signMessage ) . toBe ( 'function' )
@@ -22,30 +22,30 @@ describe('viem support', () => {
2222 it ( 'should able to get account from deriveKey with TappdClient' , async ( ) => {
2323 const client = new TappdClient ( )
2424 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
25-
25+
2626 const result = await client . deriveKey ( '/' , 'test' )
2727 const account = toViemAccount ( result )
28-
28+
2929 expect ( account . source ) . toBe ( 'privateKey' )
3030 expect ( typeof account . sign ) . toBe ( 'function' )
3131 expect ( typeof account . signMessage ) . toBe ( 'function' )
3232 expect ( consoleSpy ) . toHaveBeenCalledWith ( 'toViemAccount: Please don\'t use `deriveKey` method to get key, use `getKey` instead.' )
33-
33+
3434 consoleSpy . mockRestore ( )
3535 } )
3636
3737 it ( 'should able to get account from getTlsKey with DstackClient' , async ( ) => {
3838 const client = new DstackClient ( )
3939 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
40-
40+
4141 const result = await client . getTlsKey ( )
4242 const account = toViemAccount ( result )
43-
43+
4444 expect ( account . source ) . toBe ( 'privateKey' )
4545 expect ( typeof account . sign ) . toBe ( 'function' )
4646 expect ( typeof account . signMessage ) . toBe ( 'function' )
4747 expect ( consoleSpy ) . toHaveBeenCalledWith ( 'toViemAccount: Please don\'t use `deriveKey` method to get key, use `getKey` instead.' )
48-
48+
4949 consoleSpy . mockRestore ( )
5050 } )
5151 } )
@@ -55,7 +55,7 @@ describe('viem support', () => {
5555 const client = new DstackClient ( )
5656 const result = await client . getKey ( '/' , 'test' )
5757 const account = toViemAccountSecure ( result )
58-
58+
5959 expect ( account . source ) . toBe ( 'privateKey' )
6060 expect ( typeof account . sign ) . toBe ( 'function' )
6161 expect ( typeof account . signMessage ) . toBe ( 'function' )
@@ -64,47 +64,31 @@ describe('viem support', () => {
6464 it ( 'should able to get account from deriveKey with TappdClient' , async ( ) => {
6565 const client = new TappdClient ( )
6666 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
67-
67+
6868 const result = await client . deriveKey ( '/' , 'test' )
6969 const account = toViemAccountSecure ( result )
70-
70+
7171 expect ( account . source ) . toBe ( 'privateKey' )
7272 expect ( typeof account . sign ) . toBe ( 'function' )
7373 expect ( typeof account . signMessage ) . toBe ( 'function' )
7474 expect ( consoleSpy ) . toHaveBeenCalledWith ( 'toViemAccountSecure: Please don\'t use `deriveKey` method to get key, use `getKey` instead.' )
75-
75+
7676 consoleSpy . mockRestore ( )
7777 } )
7878
7979 it ( 'should able to get account from getTlsKey with DstackClient' , async ( ) => {
8080 const client = new DstackClient ( )
8181 const consoleSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
82-
82+
8383 const result = await client . getTlsKey ( )
8484 const account = toViemAccountSecure ( result )
85-
85+
8686 expect ( account . source ) . toBe ( 'privateKey' )
8787 expect ( typeof account . sign ) . toBe ( 'function' )
8888 expect ( typeof account . signMessage ) . toBe ( 'function' )
8989 expect ( consoleSpy ) . toHaveBeenCalledWith ( 'toViemAccountSecure: Please don\'t use `deriveKey` method to get key, use `getKey` instead.' )
90-
91- consoleSpy . mockRestore ( )
92- } )
9390
94- it ( 'should throw error when sha256 is not supported' , async ( ) => {
95- const client = new DstackClient ( )
96- const result = await client . getTlsKey ( )
97-
98- // Mock crypto.createHash to simulate missing sha256 support
99- const originalCreateHash = crypto . createHash
100- crypto . createHash = ( ) => {
101- throw new Error ( 'sha256 not supported' )
102- }
103-
104- expect ( ( ) => toViemAccountSecure ( result ) ) . toThrow ( 'toViemAccountSecure: missing sha256 support' )
105-
106- // Restore original createHash
107- crypto . createHash = originalCreateHash
91+ consoleSpy . mockRestore ( )
10892 } )
10993 } )
11094} )
0 commit comments