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 ,
20
26
beforeAll ,
@@ -35,8 +41,8 @@ import {
35
41
import { sleep } from '../../../src/core/helpers.mjs'
36
42
37
43
describe . each ( [
38
- { releaseTag : 'v0.49.0-alpha.1' , keyFormat : constants . KEY_FORMAT_PFX , testName : 'node-cmd-e2e-pfx' } ,
39
- { releaseTag : 'v0.49.0-alpha.1' , keyFormat : constants . KEY_FORMAT_PEM , testName : 'node-cmd-e2e-pem' }
44
+ { releaseTag : 'v0.49.0-alpha.1' , keyFormat : constants . KEY_FORMAT_PFX , testName : 'node-cmd-e2e-pfx' , mode : 'kill' } ,
45
+ { releaseTag : 'v0.49.0-alpha.1' , keyFormat : constants . KEY_FORMAT_PEM , testName : 'node-cmd-e2e-pem' , mode : 'stop' }
40
46
] ) ( 'NodeCommand' , ( input ) => {
41
47
const testName = input . testName
42
48
const namespace = testName
@@ -61,7 +67,7 @@ describe.each([
61
67
describe ( `Node should start successfully [release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
62
68
balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace )
63
69
64
- accountCreationShouldSucceed ( accountManager , nodeCmd )
70
+ accountCreationShouldSucceed ( accountManager , nodeCmd , namespace )
65
71
66
72
it ( 'Node Proxy should be UP' , async ( ) => {
67
73
expect . assertions ( 1 )
@@ -77,33 +83,20 @@ describe.each([
77
83
} , 20000 )
78
84
} )
79
85
80
- describe ( `Stopped node should refresh successfully [release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
81
- const nodeId = 'node0'
82
-
83
- beforeAll ( async ( ) => {
84
- await nodeRefreshTestSetup ( argv , testName , k8 , nodeId )
85
- await expect ( nodeCmd . stop ( argv ) ) . resolves . toBeTruthy ( )
86
- } , 120000 )
87
-
88
- nodeShouldBeRunning ( nodeCmd , namespace , nodeId )
89
-
90
- nodeShouldNotBeActive ( nodeCmd , nodeId )
91
-
92
- nodeRefreshShouldSucceed ( nodeId , nodeCmd , argv )
93
-
94
- balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace )
95
-
96
- accountCreationShouldSucceed ( accountManager , nodeCmd )
97
- } )
98
-
99
- describe ( `Killed node should refresh successfully [release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
86
+ describe ( `Node should refresh successfully [mode ${ input . mode } , release ${ input . releaseTag } , keyFormat: ${ input . keyFormat } ]` , ( ) => {
100
87
const nodeId = 'node0'
101
88
102
89
beforeAll ( async ( ) => {
103
90
const podName = await nodeRefreshTestSetup ( argv , testName , k8 , nodeId )
104
- const resp = await k8 . kubeClient . deleteNamespacedPod ( podName , namespace )
105
- expect ( resp . response . statusCode ) . toEqual ( 200 )
106
- await sleep ( 20000 ) // sleep to wait for pod to finish terminating
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
+ }
107
100
} , 120000 )
108
101
109
102
nodeShouldBeRunning ( nodeCmd , namespace , nodeId )
@@ -114,29 +107,36 @@ describe.each([
114
107
115
108
balanceQueryShouldSucceed ( accountManager , nodeCmd , namespace )
116
109
117
- accountCreationShouldSucceed ( accountManager , nodeCmd )
110
+ accountCreationShouldSucceed ( accountManager , nodeCmd , namespace )
118
111
} )
119
112
} )
120
113
121
- function accountCreationShouldSucceed ( accountManager , nodeCmd ) {
114
+ function accountCreationShouldSucceed ( accountManager , nodeCmd , namespace ) {
122
115
it ( 'Account creation should succeed' , async ( ) => {
123
- expect . assertions ( 2 )
116
+ expect . assertions ( 3 )
124
117
125
118
try {
119
+ await accountManager . loadNodeClient ( namespace )
126
120
expect ( accountManager . _nodeClient ) . not . toBeNull ( )
127
- const accountKey = PrivateKey . generate ( )
121
+ const privateKey = PrivateKey . generate ( )
122
+ const amount = 100
128
123
129
- let transaction = await new AccountCreateTransaction ( )
130
- . setNodeAccountIds ( [ constants . HEDERA_NODE_ACCOUNT_ID_START ] )
131
- . setInitialBalance ( new Hbar ( 0 ) )
132
- . setKey ( accountKey . publicKey )
133
- . freezeWith ( accountManager . _nodeClient )
124
+ const newAccount = await new AccountCreateTransaction ( )
125
+ . setKey ( privateKey )
126
+ . setInitialBalance ( Hbar . from ( amount , HbarUnit . Hbar ) )
127
+ . execute ( accountManager . _nodeClient )
134
128
135
- transaction = await transaction . sign ( accountKey )
136
- const response = await transaction . execute ( accountManager . _nodeClient )
137
- const receipt = await response . getReceipt ( accountManager . _nodeClient )
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
+ }
138
137
139
- expect ( receipt . accountId ) . not . toBeNull ( )
138
+ expect ( accountInfo . accountId ) . not . toBeNull ( )
139
+ expect ( accountInfo . balance ) . toEqual ( amount )
140
140
} catch ( e ) {
141
141
nodeCmd . logger . showUserError ( e )
142
142
expect ( e ) . toBeNull ( )
@@ -179,7 +179,14 @@ function nodeShouldBeRunning (nodeCmd, namespace, nodeId) {
179
179
180
180
function nodeRefreshShouldSucceed ( nodeId , nodeCmd , argv ) {
181
181
it ( `${ nodeId } refresh should succeed` , async ( ) => {
182
- await expect ( nodeCmd . refresh ( argv ) ) . resolves . toBeTruthy ( )
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
+ }
183
190
} , 1200000 )
184
191
}
185
192
@@ -203,7 +210,7 @@ async function nodeRefreshTestSetup (argv, testName, k8, nodeId) {
203
210
configManager . update ( argv , true )
204
211
205
212
const podArray = await k8 . getPodsByLabel (
206
- [ ' app=network-node0' , 'fullstack.hedera.com/type=network-node' ] )
213
+ [ ` app=network-${ nodeId } ` , 'fullstack.hedera.com/type=network-node' ] )
207
214
208
215
if ( podArray . length > 0 ) {
209
216
const podName = podArray [ 0 ] . metadata . name
0 commit comments