@@ -2,7 +2,7 @@ import {assert} from 'chai'
22import { execSync } from 'child_process'
33import * as fs from 'fs'
44import * as path from 'path'
5- import { APIClient , FetchProvider } from '@wharfkit/antelope'
5+ import { APIClient , FetchProvider , KeyType , PrivateKey } from '@wharfkit/antelope'
66import fetch from 'node-fetch'
77import {
88 E2ETestContext ,
@@ -67,23 +67,13 @@ suite('E2E: Wallet', () => {
6767
6868 test ( 'can add an existing private key to wallet' , function ( ) {
6969 if ( ! ctx ) this . skip ( )
70- // Generate a private key using the CLI first to get a valid key format
71- const createOutput = execSync ( `node ${ ctx . cliPath } wallet create --name tempkey` , {
72- encoding : 'utf8' ,
73- } )
74-
75- // Extract the private key from the output
76- const privateKeyMatch = createOutput . match ( / P r i v a t e K e y : ( P V T _ K 1 _ [ A - Z a - z 0 - 9 ] + ) / )
77- const publicKeyMatch = createOutput . match ( / P u b l i c K e y : ( P U B _ K 1 _ [ A - Z a - z 0 - 9 ] + ) / )
78- assert . isNotNull ( privateKeyMatch , 'Should have private key in output' )
79- assert . isNotNull ( publicKeyMatch , 'Should have public key in output' )
80-
81- const privateKey = privateKeyMatch ! [ 1 ]
82- const expectedPublicKey = publicKeyMatch ! [ 1 ]
70+ // Generate a fresh private key (not in wallet yet)
71+ const privateKey = PrivateKey . generate ( KeyType . K1 )
72+ const expectedPublicKey = privateKey . toPublic ( ) . toString ( )
8373
84- // Add the same private key with a different name
74+ // Add the private key to the wallet
8575 const addOutput = execSync (
86- `node ${ ctx . cliPath } wallet keys add ${ privateKey } --name imported-key` ,
76+ `node ${ ctx . cliPath } wallet keys add ${ privateKey . toString ( ) } --name imported-key` ,
8777 { encoding : 'utf8' }
8878 )
8979
@@ -101,27 +91,22 @@ suite('E2E: Wallet', () => {
10191 } )
10292 assert . fail ( 'Should have thrown an error' )
10393 } catch ( error : any ) {
104- assert . include ( error . message , 'Invalid private key format' )
94+ // The error message is in stdout (CLI outputs to stdout before exiting)
95+ const output = error . stdout || error . message
96+ assert . include ( output , 'Invalid private key' )
10597 }
10698 } )
10799
108100 test ( 'wallet keys add generates name when not specified' , function ( ) {
109101 if ( ! ctx ) this . skip ( )
110- // Generate a private key using the CLI first
111- const createOutput = execSync ( `node ${ ctx . cliPath } wallet create --name tempkey2` , {
112- encoding : 'utf8' ,
113- } )
114-
115- // Extract the private key from the output
116- const privateKeyMatch = createOutput . match ( / P r i v a t e K e y : ( P V T _ K 1 _ [ A - Z a - z 0 - 9 ] + ) / )
117- assert . isNotNull ( privateKeyMatch , 'Should have private key in output' )
118-
119- const privateKey = privateKeyMatch ! [ 1 ]
102+ // Generate a fresh private key (not in wallet yet)
103+ const privateKey = PrivateKey . generate ( KeyType . K1 )
120104
121105 // Add without specifying name
122- const addOutput = execSync ( `node ${ ctx . cliPath } wallet keys add ${ privateKey } ` , {
123- encoding : 'utf8' ,
124- } )
106+ const addOutput = execSync (
107+ `node ${ ctx . cliPath } wallet keys add ${ privateKey . toString ( ) } ` ,
108+ { encoding : 'utf8' }
109+ )
125110
126111 assert . include ( addOutput , '✅ Key added successfully!' )
127112 // Should have auto-generated name
0 commit comments