Skip to content

Commit c99d881

Browse files
fix: Resolve various problems to enable tests from local-node and smart-contracts to run agains solo network (#402)
Signed-off-by: Ivo Yankov <[email protected]> Signed-off-by: Jeffrey Tang <[email protected]> Co-authored-by: Jeffrey Tang <[email protected]> Co-authored-by: JeffreyDallas <[email protected]>
1 parent 77a3dd9 commit c99d881

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
autoRenew.targetTypes=
2-
hedera.config.version=0
2+
hedera.config.version=0

src/commands/mirror_node.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { constants } from '../core/index.mjs'
2121
import { BaseCommand } from './base.mjs'
2222
import * as flags from './flags.mjs'
2323
import * as prompts from './prompts.mjs'
24+
import { getFileContents, getEnvValue } from '../core/helpers.mjs'
2425

2526
export class MirrorNodeCommand extends BaseCommand {
2627
constructor (opts) {
@@ -206,6 +207,56 @@ export class MirrorNodeCommand extends BaseCommand {
206207
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
207208
})
208209
}
210+
},
211+
{
212+
title: 'Seed DB data',
213+
task: async (ctx, parentTask) => {
214+
const subTasks = [
215+
{
216+
title: 'Insert data in public.file_data',
217+
task: async (ctx, _) => {
218+
const namespace = self.configManager.getFlag(flags.namespace)
219+
220+
const feesFileIdNum = 111
221+
const exchangeRatesFileIdNum = 112
222+
const timestamp = Date.now()
223+
224+
const fees = await getFileContents(this.accountManager, namespace, feesFileIdNum)
225+
const exchangeRates = await getFileContents(this.accountManager, namespace, exchangeRatesFileIdNum)
226+
227+
const importFeesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${fees}', 'hex'), ${timestamp + '000000'}, ${feesFileIdNum}, 17);`
228+
const importExchangeRatesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${exchangeRates}', 'hex'), ${
229+
timestamp + '000001'
230+
}, ${exchangeRatesFileIdNum}, 17);`
231+
const sqlQuery = [importFeesQuery, importExchangeRatesQuery].join('\n')
232+
233+
const pods = await this.k8.getPodsByLabel(['app.kubernetes.io/name=postgres'])
234+
if (pods.length === 0) {
235+
throw new FullstackTestingError('postgres pod not found')
236+
}
237+
const postgresPodName = pods[0].metadata.name
238+
const postgresContainerName = 'postgresql'
239+
const mirrorEnvVars = await self.k8.execContainer(postgresPodName, postgresContainerName, '/bin/bash -c printenv')
240+
const mirrorEnvVarsArray = mirrorEnvVars.split('\n')
241+
const HEDERA_MIRROR_IMPORTER_DB_OWNER = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_OWNER')
242+
const HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD')
243+
const HEDERA_MIRROR_IMPORTER_DB_NAME = getEnvValue(mirrorEnvVarsArray, 'HEDERA_MIRROR_IMPORTER_DB_NAME')
244+
245+
await self.k8.execContainer(postgresPodName, postgresContainerName, [
246+
'psql',
247+
`postgresql://${HEDERA_MIRROR_IMPORTER_DB_OWNER}:${HEDERA_MIRROR_IMPORTER_DB_OWNERPASSWORD}@localhost:5432/${HEDERA_MIRROR_IMPORTER_DB_NAME}`,
248+
'-c',
249+
sqlQuery
250+
])
251+
}
252+
}
253+
]
254+
255+
return parentTask.newListr(subTasks, {
256+
concurrent: false,
257+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
258+
})
259+
}
209260
}
210261
], {
211262
concurrent: false,

src/core/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const HELM = 'helm'
3030
export const KEYTOOL = 'keytool'
3131
export const SOLO_CONFIG_FILE = `${SOLO_HOME_DIR}/solo.config`
3232
export const RESOURCES_DIR = normalize(CUR_FILE_DIR + '/../../resources')
33+
export const TEMP_DIR = normalize(CUR_FILE_DIR + '/../../temp')
3334

3435
export const ROOT_CONTAINER = 'root-container'
3536

src/core/helpers.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as semver from 'semver'
2525
import { Templates } from './templates.mjs'
2626
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.mjs'
2727
import { constants } from './index.mjs'
28+
import { FileContentsQuery, FileId } from '@hashgraph/sdk'
2829

2930
// cache current directory
3031
const CUR_FILE_DIR = paths.dirname(fileURLToPath(import.meta.url))
@@ -228,3 +229,16 @@ export function getNodeAccountMap (nodeIDs) {
228229
})
229230
return accountMap
230231
}
232+
233+
export async function getFileContents (accountManager, namespace, fileNum) {
234+
await accountManager.loadNodeClient(namespace)
235+
const client = accountManager._nodeClient
236+
const fileId = FileId.fromString(`0.0.${fileNum}`)
237+
const queryFees = new FileContentsQuery().setFileId(fileId)
238+
return Buffer.from(await queryFees.execute(client)).toString('hex')
239+
}
240+
241+
export function getEnvValue (envVarArray, name) {
242+
const kvPair = envVarArray.find(v => v.startsWith(`${name}=`))
243+
return kvPair ? kvPair.split('=')[1] : null
244+
}

0 commit comments

Comments
 (0)