Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add freeze account #436

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading