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

fix: Resolve various problems to enable tests from local-node and smart-contracts to run agains solo network #402

Merged
Merged
Show file tree
Hide file tree
Changes from 16 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
11 changes: 9 additions & 2 deletions resources/templates/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
autoRenew.targetTypes=
hedera.config.version=0
ledger.id=0x01
netty.mode=DEV
leninmehedy marked this conversation as resolved.
Show resolved Hide resolved
contracts.chainId=298
hedera.recordStream.logPeriod=1
balances.exportPeriodSecs=400
files.maxSizeKb=2048
hedera.recordStream.compressFilesOnCreation=true
balances.compressOnCreation=true
contracts.maxNumWithHapiSigsAccess=0
51 changes: 51 additions & 0 deletions src/commands/mirror_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { constants } from '../core/index.mjs'
import { BaseCommand } from './base.mjs'
import * as flags from './flags.mjs'
import * as prompts from './prompts.mjs'
import { getFileContents, getEnvValue } from '../core/helpers.mjs'

export class MirrorNodeCommand extends BaseCommand {
constructor (opts) {
Expand Down Expand Up @@ -206,6 +207,56 @@ export class MirrorNodeCommand extends BaseCommand {
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})
}
},
{
title: 'Seed DB data',
task: async (ctx, parentTask) => {
const subTasks = [
{
title: 'Insert data in public.file_data',
task: async (ctx, _) => {
const namespace = self.configManager.getFlag(flags.namespace)

const feesFileIdNum = 111
const exchangeRatesFileIdNum = 112
const timestamp = Date.now()

const fees = await getFileContents(this.accountManager, namespace, feesFileIdNum)
const exchangeRates = await getFileContents(this.accountManager, namespace, exchangeRatesFileIdNum)

const importFeesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${fees}', 'hex'), ${timestamp + '000000'}, ${feesFileIdNum}, 17);`
const importExchangeRatesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${exchangeRates}', 'hex'), ${
timestamp + '000001'
}, ${exchangeRatesFileIdNum}, 17);`
const sqlQuery = [importFeesQuery, importExchangeRatesQuery].join('\n')

const pods = await this.k8.getPodsByLabel(['app.kubernetes.io/name=postgres'])
if (pods.length === 0) {
throw new FullstackTestingError('postgres pod not found')
}
const postgresPodName = pods[0].metadata.name
const postgresContainerName = 'postgresql'
const mirrorEnvVars = await self.k8.execContainer(postgresPodName, postgresContainerName, '/bin/bash -c printenv')
const mirrorEnvVarsArray = mirrorEnvVars.split('\n')
const HEDERA_MIRROR_IMPORTER_DB_OWNER = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_OWNER')
const HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD')
const HEDERA_MIRROR_IMPORTER_DB_NAME = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_NAME')

await self.k8.execContainer(postgresPodName, postgresContainerName, [
'psql',
`postgresql://${HEDERA_MIRROR_IMPORTER_DB_OWNER}:${HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD}@localhost:5432/${HEDERA_MIRROR_IMPORTER_DB_NAME}`,
'-c',
sqlQuery
])
}
}
]

return parentTask.newListr(subTasks, {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})
}
}
], {
concurrent: false,
Expand Down
1 change: 1 addition & 0 deletions src/core/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const HELM = 'helm'
export const KEYTOOL = 'keytool'
export const SOLO_CONFIG_FILE = `${SOLO_HOME_DIR}/solo.config`
export const RESOURCES_DIR = normalize(CUR_FILE_DIR + '/../../resources')
export const TEMP_DIR = normalize(CUR_FILE_DIR + '/../../temp')

export const ROOT_CONTAINER = 'root-container'

Expand Down
14 changes: 14 additions & 0 deletions src/core/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as semver from 'semver'
import { Templates } from './templates.mjs'
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.mjs'
import { constants } from './index.mjs'
import { FileContentsQuery, FileId } from '@hashgraph/sdk'

// cache current directory
const CUR_FILE_DIR = paths.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -228,3 +229,16 @@ export function getNodeAccountMap (nodeIDs) {
})
return accountMap
}

export async function getFileContents (accountManager, namespace, fileNum) {
await accountManager.loadNodeClient(namespace)
const client = accountManager._nodeClient
const fileId = FileId.fromString(`0.0.${fileNum}`)
const queryFees = new FileContentsQuery().setFileId(fileId)
return Buffer.from(await queryFees.execute(client)).toString('hex')
}

export function getEnvValue (envVarArray, name) {
const kvPair = envVarArray.find(v => v.startsWith(`${name}=`))
return kvPair ? kvPair.split('=')[1] : null
}
Loading