Skip to content

Commit 8fe5a41

Browse files
feat: add freeze account (#436)
Signed-off-by: Jeffrey Tang <[email protected]>
1 parent df68a81 commit 8fe5a41

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/commands/node.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { BaseCommand } from './base.mjs'
2727
import * as flags from './flags.mjs'
2828
import * as prompts from './prompts.mjs'
2929
import {
30+
AccountBalanceQuery,
3031
AccountId,
3132
FileContentsQuery,
3233
FileId,
@@ -35,6 +36,7 @@ import {
3536
Timestamp
3637
} from '@hashgraph/sdk'
3738
import * as crypto from 'crypto'
39+
import { FREEZE_ADMIN_ACCOUNT } from '../core/constants.mjs'
3840

3941
/**
4042
* Defines the core functionalities of 'node' command
@@ -1705,6 +1707,20 @@ export class NodeCommand extends BaseCommand {
17051707
const client = this.accountManager._nodeClient
17061708

17071709
try {
1710+
// transfer some tiny amount to the freeze admin account
1711+
await this.accountManager.transferAmount(constants.TREASURY_ACCOUNT_ID, FREEZE_ADMIN_ACCOUNT, 100000)
1712+
1713+
// query the balance
1714+
const balance = await new AccountBalanceQuery()
1715+
.setAccountId(FREEZE_ADMIN_ACCOUNT)
1716+
.execute(this.accountManager._nodeClient)
1717+
this.logger.debug(`Freeze admin account balance: ${balance.hbars}`)
1718+
1719+
// set operator of freeze transaction as freeze admin account
1720+
const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace)
1721+
const freezeAdminPrivateKey = accountKeys.privateKey
1722+
client.setOperator(FREEZE_ADMIN_ACCOUNT, freezeAdminPrivateKey)
1723+
17081724
// fetch special file
17091725
const fileId = FileId.fromString('0.0.150')
17101726
const fileQuery = new FileContentsQuery().setFileId(fileId)

src/core/constants.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ export const DEFAULT_CHART_REPO = new Map()
6767
export const OPERATOR_ID = process.env.SOLO_OPERATOR_ID || '0.0.2'
6868
export const OPERATOR_KEY = process.env.SOLO_OPERATOR_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137'
6969
export const OPERATOR_PUBLIC_KEY = process.env.SOLO_OPERATOR_PUBLIC_KEY || '302a300506032b65700321000aa8e21064c61eab86e2a9c164565b4e7a9a4146106e0a6cd03a8c395a110e92'
70+
export const FREEZE_ADMIN_ACCOUNT = process.env.FREEZE_ADMIN_ACCOUNT || '0.0.58'
7071
export const TREASURY_ACCOUNT_ID = `${HEDERA_NODE_ACCOUNT_ID_START.realm}.${HEDERA_NODE_ACCOUNT_ID_START.shard}.2`
7172
export const GENESIS_KEY = process.env.GENESIS_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137'
7273
export const SYSTEM_ACCOUNTS = [[3, 100], [200, 349], [400, 750], [900, 1000]] // do account 0.0.2 last and outside the loop
74+
export const SHORTER_SYSTEM_ACCOUNTS = [[3, 100], [200, 349]]
7375
export const TREASURY_ACCOUNT = 2
7476
export const LOCAL_NODE_START_PORT = process.env.LOCAL_NODE_START_PORT || 30212
7577
export const LOCAL_NODE_PROXY_START_PORT = process.env.LOCAL_NODE_PROXY_START_PORT || 30313

test/e2e/e2e_node_util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ import { getNodeLogs, sleep } from '../../src/core/helpers.mjs'
4747
import path from 'path'
4848
import fs from 'fs'
4949
import crypto from 'crypto'
50-
import { ROOT_CONTAINER } from '../../src/core/constants.mjs'
50+
import { ROOT_CONTAINER, SHORTER_SYSTEM_ACCOUNTS } from '../../src/core/constants.mjs'
5151
import { NodeCommand } from '../../src/commands/node.mjs'
52+
import { AccountCommand } from '../../src/commands/account.mjs'
5253

5354
export function e2eNodeKeyRefreshAddTest (keyFormat, testName, mode, releaseTag = HEDERA_PLATFORM_VERSION_TAG) {
5455
const defaultTimeout = 120000
@@ -71,6 +72,7 @@ export function e2eNodeKeyRefreshAddTest (keyFormat, testName, mode, releaseTag
7172
const accountManager = bootstrapResp.opts.accountManager
7273
const k8 = bootstrapResp.opts.k8
7374
const nodeCmd = bootstrapResp.cmd.nodeCmd
75+
const accountCmd = new AccountCommand(bootstrapResp.opts, SHORTER_SYSTEM_ACCOUNTS)
7476

7577
afterEach(async () => {
7678
await nodeCmd.close()
@@ -159,6 +161,11 @@ export function e2eNodeKeyRefreshAddTest (keyFormat, testName, mode, releaseTag
159161

160162
accountCreationShouldSucceed(accountManager, nodeCmd, namespace)
161163

164+
it('should succeed with init command', async () => {
165+
const status = await accountCmd.init(argv)
166+
expect(status).toBeTruthy()
167+
}, 450000)
168+
162169
it(`add ${nodeId} to the network`, async () => {
163170
try {
164171
await expect(nodeCmd.add(argv)).resolves.toBeTruthy()

0 commit comments

Comments
 (0)