1
- import type { NodeId } from 'polykey/dist/ids' ;
2
1
import path from 'path' ;
3
2
import fs from 'fs' ;
4
3
import Logger , { LogLevel , StreamHandler } from '@matrixai/logger' ;
5
4
import PolykeyAgent from 'polykey/dist/PolykeyAgent' ;
6
5
import * as keysUtils from 'polykey/dist/keys/utils' ;
7
6
import * as nodesUtils from 'polykey/dist/nodes/utils' ;
7
+ import { sleep } from 'polykey/dist/utils' ;
8
8
import * as testUtils from '../utils' ;
9
9
10
10
describe ( 'reset' , ( ) => {
11
11
const logger = new Logger ( 'reset test' , LogLevel . WARN , [ new StreamHandler ( ) ] ) ;
12
- const password = 'helloworld ' ;
12
+ const password = 'helloWorld ' ;
13
13
let dataDir : string ;
14
14
let nodePath : string ;
15
15
let pkAgent : PolykeyAgent ;
16
- let oldNodeId : NodeId ;
17
16
beforeEach ( async ( ) => {
18
17
dataDir = await fs . promises . mkdtemp (
19
18
path . join ( globalThis . tmpDir , 'polykey-test-' ) ,
@@ -33,7 +32,6 @@ describe('reset', () => {
33
32
} ,
34
33
logger,
35
34
} ) ;
36
- oldNodeId = pkAgent . keyRing . getNodeId ( ) ;
37
35
} , globalThis . defaultTimeout * 2 ) ;
38
36
afterEach ( async ( ) => {
39
37
await pkAgent . stop ( ) ;
@@ -87,6 +85,11 @@ describe('reset', () => {
87
85
} ,
88
86
) ) ;
89
87
expect ( exitCode ) . toBe ( 0 ) ;
88
+ // Wait for keys changes to propagate to the network
89
+ await sleep ( 1000 ) ;
90
+ const nodeIdEncodedNew = nodesUtils . encodeNodeId (
91
+ pkAgent . keyRing . getNodeId ( ) ,
92
+ ) ;
90
93
// Get new keypair and nodeId and compare against old
91
94
( { exitCode, stdout } = await testUtils . pkStdio (
92
95
[ 'keys' , 'keypair' , '--format' , 'json' ] ,
@@ -95,9 +98,7 @@ describe('reset', () => {
95
98
PK_NODE_PATH : nodePath ,
96
99
PK_PASSWORD : 'password-new' ,
97
100
PK_PASSWORD_NEW : 'some-password' ,
98
- // Client server still using old nodeId, this should be removed if
99
- // this is fixed.
100
- PK_NODE_ID : nodesUtils . encodeNodeId ( oldNodeId ) ,
101
+ PK_NODE_ID : nodeIdEncodedNew ,
101
102
PK_CLIENT_HOST : '127.0.0.1' ,
102
103
PK_CLIENT_PORT : `${ pkAgent . clientServicePort } ` ,
103
104
} ,
@@ -113,9 +114,7 @@ describe('reset', () => {
113
114
env : {
114
115
PK_NODE_PATH : nodePath ,
115
116
PK_PASSWORD : 'password-new' ,
116
- // Client server still using old nodeId, this should be removed if
117
- // this is fixed.
118
- PK_NODE_ID : nodesUtils . encodeNodeId ( oldNodeId ) ,
117
+ PK_NODE_ID : nodeIdEncodedNew ,
119
118
PK_CLIENT_HOST : '127.0.0.1' ,
120
119
PK_CLIENT_PORT : `${ pkAgent . clientServicePort } ` ,
121
120
} ,
0 commit comments