Skip to content

Commit 0f2c6a8

Browse files
committed
fixed bugs
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent edadcb2 commit 0f2c6a8

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

src/commands/node.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class NodeCommand extends BaseCommand {
108108
const output = await this.k8.execContainer(podName, constants.ROOT_CONTAINER, ['tail', '-10', logfilePath])
109109
if (output && output.indexOf('Terminating Netty') < 0 && // make sure we are not at the beginning of a restart
110110
(output.indexOf(`Now current platform status = ${status}`) > 0 ||
111-
output.indexOf(`is ${status}`))) { // 'is ACTIVE' is for newer versions, first seen in v0.49.0
111+
output.indexOf(`is ${status}`) > 0)) { // 'is ACTIVE' is for newer versions, first seen in v0.49.0
112112
this.logger.debug(`Node ${nodeId} is ${status} [ attempt: ${attempt}/${maxAttempt}]`)
113113
isActive = true
114114
break

test/e2e/commands/node.test.mjs

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
* limitations under the License.
1515
*
1616
*/
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'
1824
import {
1925
afterAll,
2026
beforeAll,
@@ -35,8 +41,8 @@ import {
3541
import { sleep } from '../../../src/core/helpers.mjs'
3642

3743
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' }
4046
])('NodeCommand', (input) => {
4147
const testName = input.testName
4248
const namespace = testName
@@ -61,7 +67,7 @@ describe.each([
6167
describe(`Node should start successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
6268
balanceQueryShouldSucceed(accountManager, nodeCmd, namespace)
6369

64-
accountCreationShouldSucceed(accountManager, nodeCmd)
70+
accountCreationShouldSucceed(accountManager, nodeCmd, namespace)
6571

6672
it('Node Proxy should be UP', async () => {
6773
expect.assertions(1)
@@ -77,33 +83,20 @@ describe.each([
7783
}, 20000)
7884
})
7985

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}]`, () => {
10087
const nodeId = 'node0'
10188

10289
beforeAll(async () => {
10390
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+
}
107100
}, 120000)
108101

109102
nodeShouldBeRunning(nodeCmd, namespace, nodeId)
@@ -114,29 +107,36 @@ describe.each([
114107

115108
balanceQueryShouldSucceed(accountManager, nodeCmd, namespace)
116109

117-
accountCreationShouldSucceed(accountManager, nodeCmd)
110+
accountCreationShouldSucceed(accountManager, nodeCmd, namespace)
118111
})
119112
})
120113

121-
function accountCreationShouldSucceed (accountManager, nodeCmd) {
114+
function accountCreationShouldSucceed (accountManager, nodeCmd, namespace) {
122115
it('Account creation should succeed', async () => {
123-
expect.assertions(2)
116+
expect.assertions(3)
124117

125118
try {
119+
await accountManager.loadNodeClient(namespace)
126120
expect(accountManager._nodeClient).not.toBeNull()
127-
const accountKey = PrivateKey.generate()
121+
const privateKey = PrivateKey.generate()
122+
const amount = 100
128123

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)
134128

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+
}
138137

139-
expect(receipt.accountId).not.toBeNull()
138+
expect(accountInfo.accountId).not.toBeNull()
139+
expect(accountInfo.balance).toEqual(amount)
140140
} catch (e) {
141141
nodeCmd.logger.showUserError(e)
142142
expect(e).toBeNull()
@@ -179,7 +179,14 @@ function nodeShouldBeRunning (nodeCmd, namespace, nodeId) {
179179

180180
function nodeRefreshShouldSucceed (nodeId, nodeCmd, argv) {
181181
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+
}
183190
}, 1200000)
184191
}
185192

@@ -203,7 +210,7 @@ async function nodeRefreshTestSetup (argv, testName, k8, nodeId) {
203210
configManager.update(argv, true)
204211

205212
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'])
207214

208215
if (podArray.length > 0) {
209216
const podName = podArray[0].metadata.name

0 commit comments

Comments
 (0)