Skip to content

Commit 9d34c3d

Browse files
committed
added new constants ( seconds and munites ), started using them, improved tests and their readibility
Signed-off-by: instamenta <[email protected]>
1 parent 1a679c6 commit 9d34c3d

27 files changed

+396
-391
lines changed

Diff for: src/core/constants.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ export const UPGRADE_FILE_ID = FileId.fromString('0.0.150')
153153
export const UPGRADE_FILE_CHUNK_SIZE = 1024 * 5 // 5Kb
154154

155155
export const JVM_DEBUG_PORT = 5005
156+
157+
export const SECONDS = 1000
158+
export const MINUTES = 60 * SECONDS

Diff for: test/e2e/commands/account.test.mjs

+20-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
* @mocha-environment steps
1717
*/
18-
1918
import { AccountId, PrivateKey } from '@hashgraph/sdk'
2019
import { constants } from '../../../src/core/index.mjs'
2120
import * as version from '../../../version.mjs'
@@ -29,11 +28,13 @@ import {
2928
import { AccountCommand } from '../../../src/commands/account.mjs'
3029
import { flags } from '../../../src/commands/index.mjs'
3130
import { getNodeLogs } from '../../../src/core/helpers.mjs'
31+
import { MINUTES, SECONDS } from '../../../src/core/constants.mjs';
32+
33+
const defaultTimeout = 20 * SECONDS
3234

3335
describe('AccountCommand', () => {
3436
const testName = 'account-cmd-e2e'
3537
const namespace = testName
36-
const defaultTimeout = 20000
3738
const testSystemAccounts = [[3, 5]]
3839
const argv = getDefaultArgv()
3940
argv[flags.namespace.name] = namespace
@@ -44,7 +45,7 @@ describe('AccountCommand', () => {
4445
argv[flags.clusterName.name] = TEST_CLUSTER
4546
argv[flags.fstChartVersion.name] = version.FST_CHART_VERSION
4647
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
47-
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
48+
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ?? undefined
4849
const bootstrapResp = bootstrapNetwork(testName, argv)
4950
const accountCmd = new AccountCommand(bootstrapResp.opts, testSystemAccounts)
5051
bootstrapResp.cmd.accountCmd = accountCmd
@@ -54,7 +55,7 @@ describe('AccountCommand', () => {
5455
const nodeCmd = bootstrapResp.cmd.nodeCmd
5556

5657
after(async function () {
57-
this.timeout(180_000)
58+
this.timeout(3 * MINUTES)
5859

5960
await getNodeLogs(k8, namespace)
6061
await k8.deleteNamespace(namespace)
@@ -67,43 +68,45 @@ describe('AccountCommand', () => {
6768
it(`proxy should be UP: ${nodeId} `, async () => {
6869
await k8.waitForPodReady(
6970
[`app=haproxy-${nodeId}`, 'fullstack.hedera.com/type=haproxy'],
70-
1, 300, 2000)
71-
}).timeout(30_000)
71+
1, 300, 2 * SECONDS)
72+
}).timeout(30 * SECONDS)
7273
}
7374
})
7475

7576
describe('account init command', () => {
7677
it('should succeed with init command', async () => {
7778
const status = await accountCmd.init(argv)
7879
expect(status).to.be.ok
79-
}).timeout(180_000)
80+
}).timeout(3 * MINUTES)
8081

8182
describe('special accounts should have new keys', () => {
8283
const genesisKey = PrivateKey.fromStringED25519(constants.GENESIS_KEY)
8384
const realm = constants.HEDERA_NODE_ACCOUNT_ID_START.realm
8485
const shard = constants.HEDERA_NODE_ACCOUNT_ID_START.shard
8586

8687
before(async function () {
87-
this.timeout(20_000)
88+
this.timeout(20 * SECONDS)
8889
await accountManager.loadNodeClient(namespace)
8990
})
9091

9192
after(async function () {
92-
this.timeout(20_000)
93+
this.timeout(20 * SECONDS)
9394
await accountManager.close()
9495
})
9596

9697
for (const [start, end] of testSystemAccounts) {
9798
for (let i = start; i <= end; i++) {
9899
it(`account ${i} should not have genesis key`, async () => {
99100
expect(accountManager._nodeClient).not.to.be.null
101+
100102
const accountId = `${realm}.${shard}.${i}`
101103
nodeCmd.logger.info(`Fetching account keys: accountId ${accountId}`)
102104
const keys = await accountManager.getAccountKeys(accountId)
103105
nodeCmd.logger.info(`Fetched account keys: accountId ${accountId}`)
106+
104107
expect(keys.length).not.to.equal(0)
105108
expect(keys[0].toString()).not.to.equal(genesisKey.toString())
106-
}).timeout(20_000)
109+
}).timeout(20 * SECONDS)
107110
}
108111
}
109112
})
@@ -117,17 +120,20 @@ describe('AccountCommand', () => {
117120
argv[flags.amount.name] = 200
118121
await expect(accountCmd.create(argv)).to.eventually.be.ok
119122
const accountInfo = accountCmd.accountInfo
123+
120124
expect(accountInfo).not.to.be.null
121125
expect(accountInfo.accountId).not.to.be.null
126+
122127
accountId1 = accountInfo.accountId
128+
123129
expect(accountInfo.privateKey).not.to.be.null
124130
expect(accountInfo.publicKey).not.to.be.null
125131
expect(accountInfo.balance).to.equal(configManager.getFlag(flags.amount))
126132
} catch (e) {
127133
testLogger.showUserError(e)
128134
expect(e).to.be.null
129135
}
130-
}).timeout(40_000)
136+
}).timeout(40 * SECONDS)
131137

132138
it('should create account with private key and hbar amount options', async () => {
133139
try {
@@ -139,7 +145,7 @@ describe('AccountCommand', () => {
139145

140146
const accountInfo = accountCmd.accountInfo
141147
expect(accountInfo).not.to.be.null
142-
expect(accountInfo.accountId).not.to.be.null)
148+
expect(accountInfo.accountId).not.to.be.null
143149
accountId2 = accountInfo.accountId
144150
expect(accountInfo.privateKey.toString()).to.equal(constants.GENESIS_KEY)
145151
expect(accountInfo.publicKey).not.to.be.null
@@ -184,7 +190,7 @@ describe('AccountCommand', () => {
184190
expect(accountInfo.accountId).to.equal(argv[flags.accountId.name])
185191
expect(accountInfo.privateKey).to.be.undefined
186192
expect(accountInfo.publicKey).not.to.be.null
187-
expect(accountInfo.balance).to.equal(1110)
193+
expect(accountInfo.balance).to.equal(1_110)
188194
} catch (e) {
189195
testLogger.showUserError(e)
190196
expect(e).to.be.null
@@ -220,7 +226,7 @@ describe('AccountCommand', () => {
220226
expect(accountInfo.accountId).to.equal(argv[flags.accountId.name])
221227
expect(accountInfo.privateKey).to.be.undefined
222228
expect(accountInfo.publicKey).to.be.ok
223-
expect(accountInfo.balance).to.equal(1110)
229+
expect(accountInfo.balance).to.equal(1_110)
224230
} catch (e) {
225231
testLogger.showUserError(e)
226232
expect(e).to.be.null

Diff for: test/e2e/commands/cluster.test.mjs

+13-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { constants, logging } from '../../../src/core/index.mjs'
2121
import { flags } from '../../../src/commands/index.mjs'
2222
import { sleep } from '../../../src/core/helpers.mjs'
2323
import * as version from '../../../version.mjs'
24+
import { MINUTES, SECONDS } from '../../../src/core/constants.mjs';
2425

2526
describe('ClusterCommand', () => {
2627
// mock showUser and showJSON to silent logging during tests
@@ -36,6 +37,7 @@ describe('ClusterCommand', () => {
3637

3738
const testName = 'cluster-cmd-e2e'
3839
const namespace = testName
40+
3941
const argv = getDefaultArgv()
4042
argv[flags.namespace.name] = namespace
4143
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG
@@ -46,7 +48,7 @@ describe('ClusterCommand', () => {
4648
argv[flags.fstChartVersion.name] = version.FST_CHART_VERSION
4749
argv[flags.force.name] = true
4850
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
49-
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
51+
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ?? undefined
5052

5153
const bootstrapResp = bootstrapTestVariables(testName, argv)
5254
const k8 = bootstrapResp.opts.k8
@@ -56,14 +58,14 @@ describe('ClusterCommand', () => {
5658
const clusterCmd = bootstrapResp.cmd.clusterCmd
5759

5860
after(async function () {
59-
this.timeout(180_000)
61+
this.timeout(3 * MINUTES)
6062

6163
await k8.deleteNamespace(namespace)
6264
argv[flags.clusterSetupNamespace.name] = constants.FULLSTACK_SETUP_NAMESPACE
6365
configManager.update(argv, true)
6466
await clusterCmd.setup(argv) // restore fullstack-cluster-setup for other e2e tests to leverage
6567
do {
66-
await sleep(5000)
68+
await sleep(5 * SECONDS)
6769
} while (!await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART))
6870
})
6971

@@ -76,31 +78,31 @@ describe('ClusterCommand', () => {
7678
if (await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) {
7779
await expect(clusterCmd.reset(argv)).to.be.ok
7880
}
79-
}).timeout(60_000)
81+
}).timeout(1 * MINUTES)
8082

8183
it('solo cluster setup should fail with invalid cluster name', async () => {
8284
argv[flags.clusterSetupNamespace.name] = 'INVALID'
8385
configManager.update(argv, true)
8486
await expect(clusterCmd.setup(argv)).to.eventually.be.rejected('Error on cluster setup')
85-
}).timeout(60_000)
87+
}).timeout(1 * MINUTES)
8688

8789
it('solo cluster setup should work with valid args', async () => {
8890
argv[flags.clusterSetupNamespace.name] = namespace
8991
configManager.update(argv, true)
9092
await expect(clusterCmd.setup(argv)).to.eventually.be.ok
91-
}).timeout(60_000)
93+
}).timeout(1 * MINUTES)
9294

9395
it('function getClusterInfo should return true', async () => {
9496
await expect(clusterCmd.getClusterInfo()).to.eventually.be.ok
95-
}).timeout(60_000)
97+
}).timeout(1 * MINUTES)
9698

9799
it('function showClusterList should return right true', async () => {
98100
await expect(clusterCmd.showClusterList()).to.eventually.be.ok
99-
}).timeout(60_000)
101+
}).timeout(1 * MINUTES)
100102

101103
it('function showInstalledChartList should return right true', async () => {
102104
await expect(clusterCmd.showInstalledChartList()).to.eventually.be.undefined
103-
}).timeout(60_000)
105+
}).timeout(1 * MINUTES)
104106

105107
// helm list would return an empty list if given invalid namespace
106108
it('solo cluster reset should fail with invalid cluster name', async () => {
@@ -113,11 +115,11 @@ describe('ClusterCommand', () => {
113115
clusterCmd.logger.showUserError(e)
114116
expect(e).to.be.null
115117
}
116-
}).timeout(60000)
118+
}).timeout(1 * MINUTES)
117119

118120
it('solo cluster reset should work with valid args', async () => {
119121
argv[flags.clusterSetupNamespace.name] = namespace
120122
configManager.update(argv, true)
121123
await expect(clusterCmd.reset(argv)).to.eventually.be.ok
122-
}, 60000)
124+
}).timeout(1 * MINUTES)
123125
})

Diff for: test/e2e/commands/mirror_node.test.mjs

+17-15
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ import { MirrorNodeCommand } from '../../../src/commands/mirror_node.mjs'
3030
import * as core from '../../../src/core/index.mjs'
3131
import { Status, TopicCreateTransaction, TopicMessageSubmitTransaction } from '@hashgraph/sdk'
3232
import * as http from 'http'
33+
import { MINUTES, SECONDS } from '../../../src/core/constants.mjs'
3334

3435
describe('MirrorNodeCommand', () => {
3536
const testName = 'mirror-cmd-e2e'
3637
const namespace = testName
38+
3739
const argv = getDefaultArgv()
3840
argv[flags.namespace.name] = namespace
3941
argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG
@@ -46,7 +48,7 @@ describe('MirrorNodeCommand', () => {
4648
argv[flags.force.name] = true
4749
argv[flags.relayReleaseTag.name] = flags.relayReleaseTag.definition.defaultValue
4850
// set the env variable SOLO_FST_CHARTS_DIR if developer wants to use local FST charts
49-
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ? process.env.SOLO_FST_CHARTS_DIR : undefined
51+
argv[flags.chartDirectory.name] = process.env.SOLO_FST_CHARTS_DIR ?? undefined
5052
argv[flags.quiet.name] = true
5153

5254
const bootstrapResp = bootstrapNetwork(testName, argv)
@@ -64,7 +66,7 @@ describe('MirrorNodeCommand', () => {
6466
})
6567

6668
after(async function () {
67-
this.timeout(180_000)
69+
this.timeout(3 * MINUTES)
6870

6971
await getNodeLogs(k8, namespace)
7072
await k8.deleteNamespace(namespace)
@@ -94,7 +96,7 @@ describe('MirrorNodeCommand', () => {
9496
flags.quiet.constName,
9597
flags.tlsClusterIssuerType.constName
9698
])
97-
}).timeout(600_000)
99+
}).timeout(10 * MINUTES)
98100

99101
it('mirror node API should be running', async () => {
100102
await accountManager.loadNodeClient(namespace)
@@ -104,30 +106,30 @@ describe('MirrorNodeCommand', () => {
104106
const explorerPod = pods[0]
105107

106108
portForwarder = await k8.portForward(explorerPod.metadata.name, 8_080, 8_080)
107-
await sleep(2_000)
109+
await sleep(2 * SECONDS)
108110

109111
// check if mirror node api server is running
110112
const apiURL = 'http://127.0.0.1:8080/api/v1/transactions'
111113
await expect(downloader.urlExists(apiURL)).to.eventually.be.ok
112-
await sleep(2_000)
114+
await sleep(2 * SECONDS)
113115
} catch (e) {
114116
mirrorNodeCmd.logger.showUserError(e)
115117
expect(e).to.be.null
116118
}
117-
}).timeout(60_000)
119+
}).timeout(1 * MINUTES)
118120

119121
it('Explorer GUI should be running', async () => {
120122
try {
121123
const guiURL = 'http://127.0.0.1:8080/localnet/dashboard'
122124
await expect(downloader.urlExists(guiURL)).to.eventually.be.ok
123-
await sleep(2_000)
125+
await sleep(2 * SECONDS)
124126

125127
mirrorNodeCmd.logger.debug('mirror node API and explorer GUI are running')
126128
} catch (e) {
127129
mirrorNodeCmd.logger.showUserError(e)
128130
expect(e).to.be.null
129131
}
130-
}).timeout(60_000)
132+
}).timeout(1 * MINUTES)
131133

132134
it('Create topic and submit message should success', async () => {
133135
try {
@@ -148,7 +150,7 @@ describe('MirrorNodeCommand', () => {
148150
mirrorNodeCmd.logger.showUserError(e)
149151
expect(e).to.be.null
150152
}
151-
}).timeout(60_000)
153+
}).timeout(1 * MINUTES)
152154

153155
// trigger some extra transactions to trigger MirrorNode to fetch the transactions
154156
accountCreationShouldSucceed(accountManager, mirrorNodeCmd, namespace)
@@ -185,16 +187,16 @@ describe('MirrorNodeCommand', () => {
185187
mirrorNodeCmd.logger.debug(`problem with request: ${e.message}`)
186188
})
187189
req.end() // make the request
188-
await sleep(2_000)
190+
await sleep(2 * SECONDS)
189191
}
190-
await sleep(1_000)
192+
await sleep(SECONDS)
191193
expect(receivedMessage).to.equal(testMessage)
192194
await k8.stopPortForward(portForwarder)
193195
} catch (e) {
194196
mirrorNodeCmd.logger.showUserError(e)
195197
expect(e).to.be.null
196198
}
197-
}).timeout(300_000)
199+
}).timeout(5 * MINUTES)
198200

199201
it('mirror node destroy should success', async () => {
200202
try {
@@ -203,7 +205,7 @@ describe('MirrorNodeCommand', () => {
203205
mirrorNodeCmd.logger.showUserError(e)
204206
expect(e).to.be.null
205207
}
206-
}).timeout(60_000)
208+
}).timeout(1 * MINUTES)
207209

208210
it('should apply the mirror node version from the --mirror-node-version flag', async () => {
209211
const mirrorNodeVersion = '0.111.1'
@@ -212,7 +214,7 @@ describe('MirrorNodeCommand', () => {
212214
const valuesArg = await mirrorNodeCmd.prepareValuesArg(customArgv)
213215

214216
expect(valuesArg).to.contain(`--set global.image.tag=${mirrorNodeVersion}`)
215-
}).timeout(5_000)
217+
}).timeout(5 * SECONDS)
216218

217219
it('should not apply the mirror node version from the --mirror-node-version flag if left empty', async () => {
218220
const mirrorNodeVersion = ''
@@ -221,5 +223,5 @@ describe('MirrorNodeCommand', () => {
221223
const valuesArg = await mirrorNodeCmd.prepareValuesArg(customArgv)
222224

223225
expect(valuesArg).not.to.contain('--set global.image.tag=')
224-
}).timeout(5_000)
226+
}).timeout(5 * SECONDS)
225227
})

0 commit comments

Comments
 (0)