Skip to content

Commit

Permalink
feat: add freeze account (#436)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Tang <[email protected]>
  • Loading branch information
JeffreyDallas authored Jul 30, 2024
1 parent df68a81 commit 8fe5a41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { BaseCommand } from './base.mjs'
import * as flags from './flags.mjs'
import * as prompts from './prompts.mjs'
import {
AccountBalanceQuery,
AccountId,
FileContentsQuery,
FileId,
Expand All @@ -35,6 +36,7 @@ import {
Timestamp
} from '@hashgraph/sdk'
import * as crypto from 'crypto'
import { FREEZE_ADMIN_ACCOUNT } from '../core/constants.mjs'

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

try {
// transfer some tiny amount to the freeze admin account
await this.accountManager.transferAmount(constants.TREASURY_ACCOUNT_ID, FREEZE_ADMIN_ACCOUNT, 100000)

// query the balance
const balance = await new AccountBalanceQuery()
.setAccountId(FREEZE_ADMIN_ACCOUNT)
.execute(this.accountManager._nodeClient)
this.logger.debug(`Freeze admin account balance: ${balance.hbars}`)

// set operator of freeze transaction as freeze admin account
const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace)
const freezeAdminPrivateKey = accountKeys.privateKey
client.setOperator(FREEZE_ADMIN_ACCOUNT, freezeAdminPrivateKey)

// fetch special file
const fileId = FileId.fromString('0.0.150')
const fileQuery = new FileContentsQuery().setFileId(fileId)
Expand Down
2 changes: 2 additions & 0 deletions src/core/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ export const DEFAULT_CHART_REPO = new Map()
export const OPERATOR_ID = process.env.SOLO_OPERATOR_ID || '0.0.2'
export const OPERATOR_KEY = process.env.SOLO_OPERATOR_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137'
export const OPERATOR_PUBLIC_KEY = process.env.SOLO_OPERATOR_PUBLIC_KEY || '302a300506032b65700321000aa8e21064c61eab86e2a9c164565b4e7a9a4146106e0a6cd03a8c395a110e92'
export const FREEZE_ADMIN_ACCOUNT = process.env.FREEZE_ADMIN_ACCOUNT || '0.0.58'
export const TREASURY_ACCOUNT_ID = `${HEDERA_NODE_ACCOUNT_ID_START.realm}.${HEDERA_NODE_ACCOUNT_ID_START.shard}.2`
export const GENESIS_KEY = process.env.GENESIS_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137'
export const SYSTEM_ACCOUNTS = [[3, 100], [200, 349], [400, 750], [900, 1000]] // do account 0.0.2 last and outside the loop
export const SHORTER_SYSTEM_ACCOUNTS = [[3, 100], [200, 349]]
export const TREASURY_ACCOUNT = 2
export const LOCAL_NODE_START_PORT = process.env.LOCAL_NODE_START_PORT || 30212
export const LOCAL_NODE_PROXY_START_PORT = process.env.LOCAL_NODE_PROXY_START_PORT || 30313
Expand Down
9 changes: 8 additions & 1 deletion test/e2e/e2e_node_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import { getNodeLogs, sleep } from '../../src/core/helpers.mjs'
import path from 'path'
import fs from 'fs'
import crypto from 'crypto'
import { ROOT_CONTAINER } from '../../src/core/constants.mjs'
import { ROOT_CONTAINER, SHORTER_SYSTEM_ACCOUNTS } from '../../src/core/constants.mjs'
import { NodeCommand } from '../../src/commands/node.mjs'
import { AccountCommand } from '../../src/commands/account.mjs'

export function e2eNodeKeyRefreshAddTest (keyFormat, testName, mode, releaseTag = HEDERA_PLATFORM_VERSION_TAG) {
const defaultTimeout = 120000
Expand All @@ -71,6 +72,7 @@ export function e2eNodeKeyRefreshAddTest (keyFormat, testName, mode, releaseTag
const accountManager = bootstrapResp.opts.accountManager
const k8 = bootstrapResp.opts.k8
const nodeCmd = bootstrapResp.cmd.nodeCmd
const accountCmd = new AccountCommand(bootstrapResp.opts, SHORTER_SYSTEM_ACCOUNTS)

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

accountCreationShouldSucceed(accountManager, nodeCmd, namespace)

it('should succeed with init command', async () => {
const status = await accountCmd.init(argv)
expect(status).toBeTruthy()
}, 450000)

it(`add ${nodeId} to the network`, async () => {
try {
await expect(nodeCmd.add(argv)).resolves.toBeTruthy()
Expand Down

0 comments on commit 8fe5a41

Please sign in to comment.