Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Apr 3, 2024
1 parent 713f3f0 commit 1dc4473
Showing 1 changed file with 122 additions and 3 deletions.
125 changes: 122 additions & 3 deletions test/e2e/commands/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
})
})

0 comments on commit 1dc4473

Please sign in to comment.