diff --git a/test/e2e/commands/node.test.mjs b/test/e2e/commands/node.test.mjs index 61377288d..d69f91c79 100644 --- a/test/e2e/commands/node.test.mjs +++ b/test/e2e/commands/node.test.mjs @@ -31,6 +31,7 @@ import { getTestConfigManager, TEST_CLUSTER } from '../../test_util.js' +import { sleep } from '../../../src/core/helpers.mjs' describe.each([ // { releaseTag: 'v0.47.0-alpha.0', keyFormat: constants.KEY_FORMAT_PFX, testName: 'node-cmd-e2e-pfx' }, @@ -42,10 +43,11 @@ describe.each([ argv[flags.namespace.name] = namespace argv[flags.releaseTag.name] = input.releaseTag argv[flags.keyFormat.name] = input.keyFormat - argv[flags.nodeIDs.name] = 'node0,node1,node2' + argv[flags.nodeIDs.name] = 'node0,node1,node2,node3' argv[flags.generateGossipKeys.name] = true argv[flags.generateTlsKeys.name] = true argv[flags.clusterName.name] = TEST_CLUSTER + argv[flags.chartDirectory.name] = 'charts' // TODO remove before pushing const bootstrapResp = bootstrapNetwork(testName, argv) const accountManager = bootstrapResp.opts.accountManager const k8 = bootstrapResp.opts.k8 @@ -113,7 +115,7 @@ describe.each([ }, 20000) }) - describe(`Node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => { + describe(`Killed node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => { let podName = '' beforeAll(async () => { argv[flags.nodeIDs.name] = 'node0' @@ -126,11 +128,96 @@ describe.each([ podName = podArray[0].metadata.name const resp = await k8.kubeClient.deleteNamespacedPod(podName, namespace) expect(resp.response.statusCode).toEqual(200) + await sleep(20000) // sleep to wait for pod to finish terminating } else { throw new Error('pod for node0 not found') } + }, 30000) + + it('Node0 should be running', async () => { + expect(podName).toContain('node0') + try { + await expect(nodeCmd.checkNetworkNodePod(namespace, 'node0')).resolves.toBeTruthy() + } catch (e) { + nodeCmd.logger.showUserError(e) + expect(e).toBeNull() + } finally { + await nodeCmd.close() + } + }, 20000) + + it('Node0 should not be ACTIVE', async () => { + expect(3) + expect(podName).toContain('node0') + try { + await expect(nodeCmd.checkNetworkNodeStarted('node0', 5)).rejects.toThrowError() + } catch (e) { + nodeCmd.logger.showUserError(e) + expect(e).not.toBeNull() + } finally { + await nodeCmd.close() + } }, 20000) + it('Node0 refresh should succeed', async () => { + await expect(nodeCmd.refresh(argv)).resolves.toBeTruthy() + }, 1200000) + // TODO need to test with PVCs + // TODO will have changes when configMap/secrets are implemented + it('Balance query and account create should succeed', async () => { + expect.assertions(3) + + try { + await accountManager.loadNodeClient(namespace) + expect(accountManager._nodeClient).not.toBeNull() + + const balance = await new AccountBalanceQuery() + .setAccountId(accountManager._nodeClient.getOperator().accountId) + .execute(accountManager._nodeClient) + + expect(balance.hbars).not.toBeNull() + + const accountKey = PrivateKey.generate() + + let transaction = await new AccountCreateTransaction() + .setNodeAccountIds([constants.HEDERA_NODE_ACCOUNT_ID_START]) + .setInitialBalance(new Hbar(0)) + .setKey(accountKey.publicKey) + .freezeWith(accountManager._nodeClient) + + transaction = await transaction.sign(accountKey) + const response = await transaction.execute(accountManager._nodeClient) + const receipt = await response.getReceipt(accountManager._nodeClient) + + expect(receipt.accountId).not.toBeNull() + } catch (e) { + nodeCmd.logger.showUserError(e) + expect(e).toBeNull() + } finally { + await nodeCmd.close() + } + }, 120000) + }) + + describe(`Stopped node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => { + let podName = '' + beforeAll(async () => { + argv[flags.nodeIDs.name] = 'node0' + const configManager = getTestConfigManager(`${testName}-solo.config`) + configManager.update(argv, true) + + const podArray = await k8.getPodsByLabel(['app=network-node0', 'fullstack.hedera.com/type=network-node']) + + if (podArray.length > 0) { + podName = podArray[0].metadata.name + const resp = await k8.kubeClient.deleteNamespacedPod(podName, namespace) + expect(resp.response.statusCode).toEqual(200) + await sleep(20000) // sleep to wait for pod to finish terminating + } else { + throw new Error('pod for node0 not found') + } + }, 30000) + it('Node0 should be running', async () => { expect(podName).toContain('node0') try { @@ -147,7 +234,6 @@ describe.each([ expect(3) expect(podName).toContain('node0') try { - await expect(nodeCmd.stop(argv)).resolves.toBeTruthy() await expect(nodeCmd.checkNetworkNodeStarted('node0', 5)).rejects.toThrowError() } catch (e) { nodeCmd.logger.showUserError(e) @@ -162,5 +248,38 @@ describe.each([ }, 1200000) // TODO need to test with PVCs // TODO will have changes when configMap/secrets are implemented + it('Balance query and account create should succeed', async () => { + expect.assertions(3) + + try { + await accountManager.loadNodeClient(namespace) + expect(accountManager._nodeClient).not.toBeNull() + + const balance = await new AccountBalanceQuery() + .setAccountId(accountManager._nodeClient.getOperator().accountId) + .execute(accountManager._nodeClient) + + expect(balance.hbars).not.toBeNull() + + const accountKey = PrivateKey.generate() + + let transaction = await new AccountCreateTransaction() + .setNodeAccountIds([constants.HEDERA_NODE_ACCOUNT_ID_START]) + .setInitialBalance(new Hbar(0)) + .setKey(accountKey.publicKey) + .freezeWith(accountManager._nodeClient) + + transaction = await transaction.sign(accountKey) + const response = await transaction.execute(accountManager._nodeClient) + const receipt = await response.getReceipt(accountManager._nodeClient) + + expect(receipt.accountId).not.toBeNull() + } catch (e) { + nodeCmd.logger.showUserError(e) + expect(e).toBeNull() + } finally { + await nodeCmd.close() + } + }, 120000) }) })