Skip to content

Commit

Permalink
fix: Resolve various problems to enable tests from local-node and sma…
Browse files Browse the repository at this point in the history
…rt-contracts to run agains solo network (#402)

Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Jeffrey Tang <jeffrey@swirldslabs.com>
Co-authored-by: Jeffrey Tang <jeffrey@swirldslabs.com>
Co-authored-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent 77a3dd9 commit c99d881
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/templates/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
autoRenew.targetTypes=
hedera.config.version=0
hedera.config.version=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
}

0 comments on commit c99d881

Please sign in to comment.