@@ -25,15 +25,30 @@ interface NewAccountTestResult {
25
25
26
26
export const createNewWallet = async (
27
27
storageMode : StorageMode ,
28
- mutable : boolean
28
+ mutable : boolean ,
29
+ clientSeed ?: Uint8Array ,
30
+ isolatedClient ?: boolean
29
31
) : Promise < NewAccountTestResult > => {
32
+ // Serialize initSeed for Puppeteer
33
+ const serializedClientSeed = clientSeed ? Array . from ( clientSeed ) : null ;
34
+
30
35
return await testingPage . evaluate (
31
- async ( _storageMode , _mutable ) => {
32
- const client = window . client ;
36
+ async ( _storageMode , _mutable , _serializedClientSeed , _isolatedClient ) => {
37
+ if ( _isolatedClient ) {
38
+ // Reconstruct Uint8Array inside the browser context
39
+ const _clientSeed = _serializedClientSeed
40
+ ? new Uint8Array ( _serializedClientSeed )
41
+ : undefined ;
42
+
43
+ await window . helpers . refreshClient ( _clientSeed ) ;
44
+ }
45
+
46
+ let client = window . client ;
33
47
const accountStorageMode =
34
48
_storageMode === "private"
35
49
? window . AccountStorageMode . private ( )
36
50
: window . AccountStorageMode . public ( ) ;
51
+
37
52
const newWallet = await client . new_wallet ( accountStorageMode , _mutable ) ;
38
53
39
54
return {
@@ -50,7 +65,9 @@ export const createNewWallet = async (
50
65
} ;
51
66
} ,
52
67
storageMode ,
53
- mutable
68
+ mutable ,
69
+ serializedClientSeed ,
70
+ isolatedClient
54
71
) ;
55
72
} ;
56
73
@@ -110,6 +127,19 @@ describe("new_wallet tests", () => {
110
127
expect ( result . is_new ) . to . equal ( true ) ;
111
128
} ) ;
112
129
} ) ;
130
+
131
+ it ( "Constructs the same account when given the same init seed" , async ( ) => {
132
+ const clientSeed = new Uint8Array ( 32 ) ;
133
+ crypto . getRandomValues ( clientSeed ) ;
134
+
135
+ // Isolate the client instance both times to ensure the outcome is deterministic
136
+ await createNewWallet ( StorageMode . PUBLIC , false , clientSeed , true ) ;
137
+
138
+ // This should fail, as the wallet is already tracked within the same browser context
139
+ await expect (
140
+ createNewWallet ( StorageMode . PUBLIC , false , clientSeed , true )
141
+ ) . to . be . rejectedWith ( / F a i l e d t o i n s e r t n e w w a l l e t : A c c o u n t A l r e a d y T r a c k e d / ) ;
142
+ } ) ;
113
143
} ) ;
114
144
115
145
// new_faucet tests
0 commit comments