Skip to content

Commit 1dc4473

Browse files
committed
working version
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 713f3f0 commit 1dc4473

File tree

1 file changed

+122
-3
lines changed

1 file changed

+122
-3
lines changed

test/e2e/commands/node.test.mjs

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getTestConfigManager,
3232
TEST_CLUSTER
3333
} from '../../test_util.js'
34+
import { sleep } from '../../../src/core/helpers.mjs'
3435

3536
describe.each([
3637
// { releaseTag: 'v0.47.0-alpha.0', keyFormat: constants.KEY_FORMAT_PFX, testName: 'node-cmd-e2e-pfx' },
@@ -42,10 +43,11 @@ describe.each([
4243
argv[flags.namespace.name] = namespace
4344
argv[flags.releaseTag.name] = input.releaseTag
4445
argv[flags.keyFormat.name] = input.keyFormat
45-
argv[flags.nodeIDs.name] = 'node0,node1,node2'
46+
argv[flags.nodeIDs.name] = 'node0,node1,node2,node3'
4647
argv[flags.generateGossipKeys.name] = true
4748
argv[flags.generateTlsKeys.name] = true
4849
argv[flags.clusterName.name] = TEST_CLUSTER
50+
argv[flags.chartDirectory.name] = 'charts' // TODO remove before pushing
4951
const bootstrapResp = bootstrapNetwork(testName, argv)
5052
const accountManager = bootstrapResp.opts.accountManager
5153
const k8 = bootstrapResp.opts.k8
@@ -113,7 +115,7 @@ describe.each([
113115
}, 20000)
114116
})
115117

116-
describe(`Node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
118+
describe(`Killed node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
117119
let podName = ''
118120
beforeAll(async () => {
119121
argv[flags.nodeIDs.name] = 'node0'
@@ -126,11 +128,96 @@ describe.each([
126128
podName = podArray[0].metadata.name
127129
const resp = await k8.kubeClient.deleteNamespacedPod(podName, namespace)
128130
expect(resp.response.statusCode).toEqual(200)
131+
await sleep(20000) // sleep to wait for pod to finish terminating
129132
} else {
130133
throw new Error('pod for node0 not found')
131134
}
135+
}, 30000)
136+
137+
it('Node0 should be running', async () => {
138+
expect(podName).toContain('node0')
139+
try {
140+
await expect(nodeCmd.checkNetworkNodePod(namespace, 'node0')).resolves.toBeTruthy()
141+
} catch (e) {
142+
nodeCmd.logger.showUserError(e)
143+
expect(e).toBeNull()
144+
} finally {
145+
await nodeCmd.close()
146+
}
147+
}, 20000)
148+
149+
it('Node0 should not be ACTIVE', async () => {
150+
expect(3)
151+
expect(podName).toContain('node0')
152+
try {
153+
await expect(nodeCmd.checkNetworkNodeStarted('node0', 5)).rejects.toThrowError()
154+
} catch (e) {
155+
nodeCmd.logger.showUserError(e)
156+
expect(e).not.toBeNull()
157+
} finally {
158+
await nodeCmd.close()
159+
}
132160
}, 20000)
133161

162+
it('Node0 refresh should succeed', async () => {
163+
await expect(nodeCmd.refresh(argv)).resolves.toBeTruthy()
164+
}, 1200000)
165+
// TODO need to test with PVCs
166+
// TODO will have changes when configMap/secrets are implemented
167+
it('Balance query and account create should succeed', async () => {
168+
expect.assertions(3)
169+
170+
try {
171+
await accountManager.loadNodeClient(namespace)
172+
expect(accountManager._nodeClient).not.toBeNull()
173+
174+
const balance = await new AccountBalanceQuery()
175+
.setAccountId(accountManager._nodeClient.getOperator().accountId)
176+
.execute(accountManager._nodeClient)
177+
178+
expect(balance.hbars).not.toBeNull()
179+
180+
const accountKey = PrivateKey.generate()
181+
182+
let transaction = await new AccountCreateTransaction()
183+
.setNodeAccountIds([constants.HEDERA_NODE_ACCOUNT_ID_START])
184+
.setInitialBalance(new Hbar(0))
185+
.setKey(accountKey.publicKey)
186+
.freezeWith(accountManager._nodeClient)
187+
188+
transaction = await transaction.sign(accountKey)
189+
const response = await transaction.execute(accountManager._nodeClient)
190+
const receipt = await response.getReceipt(accountManager._nodeClient)
191+
192+
expect(receipt.accountId).not.toBeNull()
193+
} catch (e) {
194+
nodeCmd.logger.showUserError(e)
195+
expect(e).toBeNull()
196+
} finally {
197+
await nodeCmd.close()
198+
}
199+
}, 120000)
200+
})
201+
202+
describe(`Stopped node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
203+
let podName = ''
204+
beforeAll(async () => {
205+
argv[flags.nodeIDs.name] = 'node0'
206+
const configManager = getTestConfigManager(`${testName}-solo.config`)
207+
configManager.update(argv, true)
208+
209+
const podArray = await k8.getPodsByLabel(['app=network-node0', 'fullstack.hedera.com/type=network-node'])
210+
211+
if (podArray.length > 0) {
212+
podName = podArray[0].metadata.name
213+
const resp = await k8.kubeClient.deleteNamespacedPod(podName, namespace)
214+
expect(resp.response.statusCode).toEqual(200)
215+
await sleep(20000) // sleep to wait for pod to finish terminating
216+
} else {
217+
throw new Error('pod for node0 not found')
218+
}
219+
}, 30000)
220+
134221
it('Node0 should be running', async () => {
135222
expect(podName).toContain('node0')
136223
try {
@@ -147,7 +234,6 @@ describe.each([
147234
expect(3)
148235
expect(podName).toContain('node0')
149236
try {
150-
await expect(nodeCmd.stop(argv)).resolves.toBeTruthy()
151237
await expect(nodeCmd.checkNetworkNodeStarted('node0', 5)).rejects.toThrowError()
152238
} catch (e) {
153239
nodeCmd.logger.showUserError(e)
@@ -162,5 +248,38 @@ describe.each([
162248
}, 1200000)
163249
// TODO need to test with PVCs
164250
// TODO will have changes when configMap/secrets are implemented
251+
it('Balance query and account create should succeed', async () => {
252+
expect.assertions(3)
253+
254+
try {
255+
await accountManager.loadNodeClient(namespace)
256+
expect(accountManager._nodeClient).not.toBeNull()
257+
258+
const balance = await new AccountBalanceQuery()
259+
.setAccountId(accountManager._nodeClient.getOperator().accountId)
260+
.execute(accountManager._nodeClient)
261+
262+
expect(balance.hbars).not.toBeNull()
263+
264+
const accountKey = PrivateKey.generate()
265+
266+
let transaction = await new AccountCreateTransaction()
267+
.setNodeAccountIds([constants.HEDERA_NODE_ACCOUNT_ID_START])
268+
.setInitialBalance(new Hbar(0))
269+
.setKey(accountKey.publicKey)
270+
.freezeWith(accountManager._nodeClient)
271+
272+
transaction = await transaction.sign(accountKey)
273+
const response = await transaction.execute(accountManager._nodeClient)
274+
const receipt = await response.getReceipt(accountManager._nodeClient)
275+
276+
expect(receipt.accountId).not.toBeNull()
277+
} catch (e) {
278+
nodeCmd.logger.showUserError(e)
279+
expect(e).toBeNull()
280+
} finally {
281+
await nodeCmd.close()
282+
}
283+
}, 120000)
165284
})
166285
})

0 commit comments

Comments
 (0)