14
14
* limitations under the License.
15
15
*
16
16
*/
17
- import { AccountBalanceQuery , AccountCreateTransaction , Hbar , PrivateKey } from '@hashgraph/sdk'
17
+ import {
18
+ AccountBalanceQuery ,
19
+ AccountCreateTransaction ,
20
+ Hbar ,
21
+ HbarUnit ,
22
+ PrivateKey
23
+ } from '@hashgraph/sdk'
18
24
import {
19
25
afterAll ,
26
+ beforeAll ,
20
27
describe ,
21
28
expect ,
22
29
it
@@ -28,20 +35,22 @@ import {
28
35
import {
29
36
bootstrapNetwork ,
30
37
getDefaultArgv ,
38
+ getTestConfigManager ,
31
39
TEST_CLUSTER
32
40
} from '../../test_util.js'
41
+ import { sleep } from '../../../src/core/helpers.mjs'
33
42
34
43
describe . each ( [
35
- { releaseTag : 'v0.47 .0-alpha.0 ' , keyFormat : constants . KEY_FORMAT_PFX , testName : 'node-cmd-e2e-pfx' } ,
36
- { releaseTag : 'v0.47 .0-alpha.0 ' , keyFormat : constants . KEY_FORMAT_PEM , testName : 'node-cmd-e2e-pem' }
44
+ { releaseTag : 'v0.49 .0-alpha.2 ' , keyFormat : constants . KEY_FORMAT_PFX , testName : 'node-cmd-e2e-pfx' , mode : 'kill ' } ,
45
+ { releaseTag : 'v0.49 .0-alpha.2 ' , keyFormat : constants . KEY_FORMAT_PEM , testName : 'node-cmd-e2e-pem' , mode : 'stop ' }
37
46
] ) ( 'NodeCommand' , ( input ) => {
38
47
const testName = input . testName
39
48
const namespace = testName
40
49
const argv = getDefaultArgv ( )
41
50
argv [ flags . namespace . name ] = namespace
42
51
argv [ flags . releaseTag . name ] = input . releaseTag
43
52
argv [ flags . keyFormat . name ] = input . keyFormat
44
- argv [ flags . nodeIDs . name ] = 'node0,node1,node2'
53
+ argv [ flags . nodeIDs . name ] = 'node0,node1,node2,node3 '
45
54
argv [ flags . generateGossipKeys . name ] = true
46
55
argv [ flags . generateTlsKeys . name ] = true
47
56
argv [ flags . clusterName . name ] = TEST_CLUSTER
@@ -55,60 +64,159 @@ describe.each([
55
64
await accountManager . close ( )
56
65
} )
57
66
58
- describe ( `Node should start successfully [release ${ input . keyFormat } , keyFormat: ${ input . releaseTag } ]` , ( ) => {
59
- it ( 'Balance query should succeed' , async ( ) => {
60
- expect . assertions ( 2 )
67
+ describe ( `Node should start successfully [release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
68
+ balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace )
61
69
62
- try {
63
- await accountManager . loadNodeClient ( namespace )
64
- expect ( accountManager . _nodeClient ) . not . toBeNull ( )
70
+ accountCreationShouldSucceed ( accountManager , nodeCmd , namespace )
65
71
66
- const balance = await new AccountBalanceQuery ( )
67
- . setAccountId ( accountManager . _nodeClient . getOperator ( ) . accountId )
68
- . execute ( accountManager . _nodeClient )
72
+ it ( 'Node Proxy should be UP' , async ( ) => {
73
+ expect . assertions ( 1 )
69
74
70
- expect ( balance . hbars ) . not . toBeNull ( )
75
+ try {
76
+ await expect ( nodeCmd . checkNetworkNodeProxyUp ( 'node0' , 30399 ) ) . resolves . toBeTruthy ( )
71
77
} catch ( e ) {
72
78
nodeCmd . logger . showUserError ( e )
73
79
expect ( e ) . toBeNull ( )
80
+ } finally {
81
+ await nodeCmd . close ( )
74
82
}
75
- } , 120000 )
83
+ } , 20000 )
84
+ } )
76
85
77
- it ( 'Account creation should succeed' , async ( ) => {
78
- expect . assertions ( 2 )
86
+ describe ( `Node should refresh successfully [mode ${ input . mode } , release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
87
+ const nodeId = 'node0'
79
88
80
- try {
81
- expect ( accountManager . _nodeClient ) . not . toBeNull ( )
82
- const accountKey = PrivateKey . generate ( )
89
+ beforeAll ( async ( ) => {
90
+ const podName = await nodeRefreshTestSetup ( argv , testName , k8 , nodeId )
91
+ if ( input . mode === 'kill' ) {
92
+ const resp = await k8 . kubeClient . deleteNamespacedPod ( podName , namespace )
93
+ expect ( resp . response . statusCode ) . toEqual ( 200 )
94
+ await sleep ( 20000 ) // sleep to wait for pod to finish terminating
95
+ } else if ( input . mode === 'stop' ) {
96
+ await expect ( nodeCmd . stop ( argv ) ) . resolves . toBeTruthy ( )
97
+ } else {
98
+ throw new Error ( `invalid mode: ${ input . mode } ` )
99
+ }
100
+ } , 120000 )
83
101
84
- let transaction = await new AccountCreateTransaction ( )
85
- . setNodeAccountIds ( [ constants . HEDERA_NODE_ACCOUNT_ID_START ] )
86
- . setInitialBalance ( new Hbar ( 0 ) )
87
- . setKey ( accountKey . publicKey )
88
- . freezeWith ( accountManager . _nodeClient )
102
+ nodeShouldBeRunning ( nodeCmd , namespace , nodeId )
89
103
90
- transaction = await transaction . sign ( accountKey )
91
- const response = await transaction . execute ( accountManager . _nodeClient )
92
- const receipt = await response . getReceipt ( accountManager . _nodeClient )
104
+ nodeShouldNotBeActive ( nodeCmd , nodeId )
93
105
94
- expect ( receipt . accountId ) . not . toBeNull ( )
95
- } catch ( e ) {
96
- nodeCmd . logger . showUserError ( e )
97
- expect ( e ) . toBeNull ( )
98
- }
99
- } , 20000 )
106
+ nodeRefreshShouldSucceed ( nodeId , nodeCmd , argv )
100
107
101
- it ( 'Node Proxy should be UP' , async ( ) => {
102
- expect . assertions ( 1 )
108
+ balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace )
103
109
104
- try {
105
- await expect ( nodeCmd . checkNetworkNodeProxyUp ( 'node0' , 30313 ) ) . resolves . toBeTruthy ( )
106
- } catch ( e ) {
107
- nodeCmd . logger . showUserError ( e )
108
- expect ( e ) . toBeNull ( )
109
- } finally {
110
- await nodeCmd . close ( )
111
- }
112
- } , 20000 )
110
+ accountCreationShouldSucceed ( accountManager , nodeCmd , namespace )
113
111
} )
114
112
} )
113
+
114
+ function accountCreationShouldSucceed ( accountManager , nodeCmd , namespace ) {
115
+ it ( 'Account creation should succeed' , async ( ) => {
116
+ expect . assertions ( 3 )
117
+
118
+ try {
119
+ await accountManager . loadNodeClient ( namespace )
120
+ expect ( accountManager . _nodeClient ) . not . toBeNull ( )
121
+ const privateKey = PrivateKey . generate ( )
122
+ const amount = 100
123
+
124
+ const newAccount = await new AccountCreateTransaction ( )
125
+ . setKey ( privateKey )
126
+ . setInitialBalance ( Hbar . from ( amount , HbarUnit . Hbar ) )
127
+ . execute ( accountManager . _nodeClient )
128
+
129
+ // Get the new account ID
130
+ const getReceipt = await newAccount . getReceipt ( accountManager . _nodeClient )
131
+ const accountInfo = {
132
+ accountId : getReceipt . accountId . toString ( ) ,
133
+ privateKey : privateKey . toString ( ) ,
134
+ publicKey : privateKey . publicKey . toString ( ) ,
135
+ balance : amount
136
+ }
137
+
138
+ expect ( accountInfo . accountId ) . not . toBeNull ( )
139
+ expect ( accountInfo . balance ) . toEqual ( amount )
140
+ } catch ( e ) {
141
+ nodeCmd . logger . showUserError ( e )
142
+ expect ( e ) . toBeNull ( )
143
+ }
144
+ } , 20000 )
145
+ }
146
+
147
+ function balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace ) {
148
+ it ( 'Balance query should succeed' , async ( ) => {
149
+ expect . assertions ( 2 )
150
+
151
+ try {
152
+ await accountManager . loadNodeClient ( namespace )
153
+ expect ( accountManager . _nodeClient ) . not . toBeNull ( )
154
+
155
+ const balance = await new AccountBalanceQuery ( )
156
+ . setAccountId ( accountManager . _nodeClient . getOperator ( ) . accountId )
157
+ . execute ( accountManager . _nodeClient )
158
+
159
+ expect ( balance . hbars ) . not . toBeNull ( )
160
+ } catch ( e ) {
161
+ nodeCmd . logger . showUserError ( e )
162
+ expect ( e ) . toBeNull ( )
163
+ }
164
+ } , 20000 )
165
+ }
166
+
167
+ function nodeShouldBeRunning ( nodeCmd , namespace , nodeId ) {
168
+ it ( `${ nodeId } should be running` , async ( ) => {
169
+ try {
170
+ await expect ( nodeCmd . checkNetworkNodePod ( namespace , nodeId ) ) . resolves . toBeTruthy ( )
171
+ } catch ( e ) {
172
+ nodeCmd . logger . showUserError ( e )
173
+ expect ( e ) . toBeNull ( )
174
+ } finally {
175
+ await nodeCmd . close ( )
176
+ }
177
+ } , 20000 )
178
+ }
179
+
180
+ function nodeRefreshShouldSucceed ( nodeId , nodeCmd , argv ) {
181
+ it ( `${ nodeId } refresh should succeed` , async ( ) => {
182
+ try {
183
+ await expect ( nodeCmd . refresh ( argv ) ) . resolves . toBeTruthy ( )
184
+ } catch ( e ) {
185
+ nodeCmd . logger . showUserError ( e )
186
+ expect ( e ) . toBeNull ( )
187
+ } finally {
188
+ await nodeCmd . close ( )
189
+ }
190
+ } , 1200000 )
191
+ }
192
+
193
+ function nodeShouldNotBeActive ( nodeCmd , nodeId ) {
194
+ it ( `${ nodeId } should not be ACTIVE` , async ( ) => {
195
+ expect ( 2 )
196
+ try {
197
+ await expect ( nodeCmd . checkNetworkNodeStarted ( nodeId , 5 ) ) . rejects . toThrowError ( )
198
+ } catch ( e ) {
199
+ nodeCmd . logger . showUserError ( e )
200
+ expect ( e ) . not . toBeNull ( )
201
+ } finally {
202
+ await nodeCmd . close ( )
203
+ }
204
+ } , 20000 )
205
+ }
206
+
207
+ async function nodeRefreshTestSetup ( argv , testName , k8 , nodeId ) {
208
+ argv [ flags . nodeIDs . name ] = nodeId
209
+ const configManager = getTestConfigManager ( `${ testName } -solo.config` )
210
+ configManager . update ( argv , true )
211
+
212
+ const podArray = await k8 . getPodsByLabel (
213
+ [ `app=network-${ nodeId } ` , 'fullstack.hedera.com/type=network-node' ] )
214
+
215
+ if ( podArray . length > 0 ) {
216
+ const podName = podArray [ 0 ] . metadata . name
217
+ k8 . logger . info ( `nodeRefreshTestSetup: podName: ${ podName } ` )
218
+ return podName
219
+ } else {
220
+ throw new Error ( `pod for ${ nodeId } not found` )
221
+ }
222
+ }
0 commit comments