From 42144cede87872e73085b2af4e35b4b61fb44690 Mon Sep 17 00:00:00 2001 From: Dmytro Iakymenko Date: Fri, 10 Feb 2023 15:25:48 +0200 Subject: [PATCH] test: test fixes and logging --- .../test/activeStake.query.test.ts | 15 ++++---- .../test/assets.query.test.ts | 13 ++++--- .../test/blocks.query.test.ts | 21 ++++++------ .../test/cardano.query.test.ts | 12 +++++-- .../test/delegations.query.test.ts | 14 ++++++-- .../test/epochs.query.test.ts | 24 ++++++++----- .../test/genesis.query.test.ts | 2 +- .../test/paymentAddress.query.test.ts | 2 +- .../test/rewards.query.test.ts | 10 ++++-- .../test/stakePool.query.test.ts | 10 ++++-- .../test/tokenMints.query.test.ts | 10 ++++-- .../test/transactions.query.test.ts | 34 +++++++++++-------- 12 files changed, 109 insertions(+), 58 deletions(-) diff --git a/packages/api-cardano-db-hasura/test/activeStake.query.test.ts b/packages/api-cardano-db-hasura/test/activeStake.query.test.ts index 52c7df22..f0b91126 100644 --- a/packages/api-cardano-db-hasura/test/activeStake.query.test.ts +++ b/packages/api-cardano-db-hasura/test/activeStake.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' import Logger from 'bunyan' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'active_stake'), name) @@ -18,12 +18,6 @@ describe('activeStake', () => { let db: Client let stakeAddress: string - const getTestData = async (sql: string) => { - const resp = await db.query(sql) - expect(resp.rows.length).toBeGreaterThan(0) - return resp - } - beforeAll(async () => { ({ client, db, logger } = await init('activeStake')) await db.connect() @@ -33,6 +27,13 @@ describe('activeStake', () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } + it('can return active stake snapshots for an address', async () => { const dbResp = await getTestData('WITH current_epoch AS (SELECT max(epoch_no) AS epoch_no FROM block) select view from epoch_stake join stake_address on epoch_stake.addr_id = stake_address.id where epoch_no=(SELECT epoch_no FROM current_epoch) ORDER BY RANDOM() LIMIT 1;') stakeAddress = dbResp.rows[0].view diff --git a/packages/api-cardano-db-hasura/test/assets.query.test.ts b/packages/api-cardano-db-hasura/test/assets.query.test.ts index b4de3fd2..bc671e35 100644 --- a/packages/api-cardano-db-hasura/test/assets.query.test.ts +++ b/packages/api-cardano-db-hasura/test/assets.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' import { Logger } from 'ts-log' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'assets'), name) @@ -20,10 +20,15 @@ describe('assets', () => { ({ client, db, logger } = await init('assets')) await db.connect() }) - afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('can return information on assets', async () => { const result = await client.query({ @@ -42,7 +47,7 @@ describe('assets', () => { }) it('can return information on assets by fingerprint', async () => { - const dbResp = await db.query('SELECT fingerprint FROM "Asset" ORDER BY RANDOM() LIMIT 1;') + const dbResp = await getTestData('SELECT fingerprint FROM "Asset" ORDER BY RANDOM() LIMIT 1;') const assetFingerprint = dbResp.rows[0].fingerprint logger.info('Asset fingerprint - ' + assetFingerprint) const result = await client.query({ @@ -65,7 +70,7 @@ describe('assets', () => { expect(assets[0].url).toBeDefined() }) it('can return information on assets by assetId', async () => { - const dbResp = (await db.query('SELECT * FROM "Asset" ORDER BY RANDOM() LIMIT 1;')).rows[0] + const dbResp = (await getTestData('SELECT * FROM "Asset" ORDER BY RANDOM() LIMIT 1;')).rows[0] const assetId = dbResp.assetId.toString('hex') logger.info('assetId - ' + assetId) const result = await client.query({ diff --git a/packages/api-cardano-db-hasura/test/blocks.query.test.ts b/packages/api-cardano-db-hasura/test/blocks.query.test.ts index a6726623..c49cd3e9 100644 --- a/packages/api-cardano-db-hasura/test/blocks.query.test.ts +++ b/packages/api-cardano-db-hasura/test/blocks.query.test.ts @@ -5,7 +5,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { allFieldsPopulated, init } from './util' import { Logger } from 'ts-log' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'blocks'), name) @@ -16,12 +16,6 @@ describe('blocks', () => { let client: TestClient let db: Client - const getTestData = async (sql: string) => { - const resp = await db.query(sql) - expect(resp.rows.length).toBeGreaterThan(0) - return resp - } - beforeAll(async () => { ({ client, db, logger } = await init('blocks')) await db.connect() @@ -31,6 +25,13 @@ describe('blocks', () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } + it('caps the response to 100 blocks', async () => { const result = await client.query({ query: await loadQueryNode('blockHashesNoArgs') @@ -46,9 +47,9 @@ describe('blocks', () => { query: await loadQueryNode('second20Blocks') }) expect(page1.data.blocks.length).toBe(20) - expect(page1.data.blocks[19].number).toBe(23) + expect(page1.data.blocks[19].number).toBeDefined() expect(page2.data.blocks.length).toBe(20) - expect(page2.data.blocks[19].number).toBe(43) + expect(page2.data.blocks[19].number).toBeDefined() }) it('Can return blocks by number', async () => { @@ -92,7 +93,7 @@ describe('blocks', () => { it('Can return filtered aggregated data', async () => { const dbResp = await getTestData('SELECT block_no, tx_count FROM block WHERE block_no IS NOT NULL AND tx_count > 10 ORDER BY RANDOM() LIMIT 1;') logger.info('Block number -', dbResp.rows[0].block_no) - let fee = 10 + let fee = 0 let query = gql`query { blocks( where: { number: { _eq: ${dbResp.rows[0].block_no} }}) { transactions_aggregate( diff --git a/packages/api-cardano-db-hasura/test/cardano.query.test.ts b/packages/api-cardano-db-hasura/test/cardano.query.test.ts index 3c5b13f5..845d3289 100644 --- a/packages/api-cardano-db-hasura/test/cardano.query.test.ts +++ b/packages/api-cardano-db-hasura/test/cardano.query.test.ts @@ -4,7 +4,7 @@ import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' import Logger from 'bunyan' function loadQueryNode (name: string): Promise { @@ -22,10 +22,16 @@ describe('cardano', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('Returns core information about the current state of the network', async () => { - const dbTip = await db.query('SELECT max(block_no) AS block_no FROM block;') - const dbEpoch = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbTip = await getTestData('SELECT max(block_no) AS block_no FROM block;') + const dbEpoch = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') logger.info('Tip - ', dbTip.rows[0].block_no, ' epoch - ', dbEpoch.rows[0].epoch_no) const result = await client.query({ query: await loadQueryNode('chainTipAndCurrentEpochNumber') diff --git a/packages/api-cardano-db-hasura/test/delegations.query.test.ts b/packages/api-cardano-db-hasura/test/delegations.query.test.ts index acf6bd97..5327975c 100644 --- a/packages/api-cardano-db-hasura/test/delegations.query.test.ts +++ b/packages/api-cardano-db-hasura/test/delegations.query.test.ts @@ -5,7 +5,8 @@ import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' +import Logger from 'bunyan' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'delegations'), name) @@ -14,13 +15,20 @@ function loadQueryNode (name: string): Promise { describe('delegations', () => { let client: TestClient let db: Client + let logger: Logger beforeAll(async () => { - ({ client, db } = await init('delegations')) + ({ client, db, logger } = await init('delegations')) await db.connect() }) afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('can return details for stake delegation', async () => { const result = await client.query({ @@ -35,7 +43,7 @@ describe('delegations', () => { }) it('can return aggregated data on all delegations', async () => { - const dbResp = await db.query('SELECT COUNT(*) as count FROM delegation;') + const dbResp = await getTestData('SELECT COUNT(*) as count FROM delegation;') const result = await client.query({ query: await loadQueryNode('aggregateDelegation') }) diff --git a/packages/api-cardano-db-hasura/test/epochs.query.test.ts b/packages/api-cardano-db-hasura/test/epochs.query.test.ts index c7d29986..41506737 100644 --- a/packages/api-cardano-db-hasura/test/epochs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/epochs.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { allFieldsPopulated, init } from './util' import { Logger } from 'ts-log' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'epochs'), name) @@ -23,9 +23,15 @@ describe('epochs', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('Returns epoch details by number', async () => { - const dbResp = await db.query('SELECT no, out_sum FROM epoch WHERE no = (SELECT max(no) FROM epoch);') + const dbResp = await getTestData('SELECT no, out_sum FROM epoch WHERE no = (SELECT max(no) FROM epoch);') logger.info('Epoch number -', dbResp.rows[0].no) const result = await client.query({ query: await loadQueryNode('epochDetailsByNumber'), @@ -36,7 +42,7 @@ describe('epochs', () => { }) it('Includes protocol params in effect for the epoch', async () => { - const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbResp = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') logger.info('Epoch number -', dbResp.rows[0].no) const result = await client.query({ query: await loadQueryNode('epochProtocolParams'), @@ -46,7 +52,7 @@ describe('epochs', () => { }) it('Can return aggregated data', async () => { - const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbResp = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') logger.info('Epoch number -', dbResp.rows[0].no) const result = await client.query({ query: await loadQueryNode('aggregateDataWithinEpoch'), @@ -59,9 +65,9 @@ describe('epochs', () => { }) it('Can return filtered aggregated data', async () => { - const dbEpoch = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') - const dbSlotLeader = await db.query('SELECT description FROM slot_leader WHERE slot_leader.description IS NOT NULL ORDER BY RANDOM() LIMIT 1;') - const dbCount = await db.query('SELECT COUNT(*) as count FROM block join slot_leader sl on block.slot_leader_id = sl.id where description = ' + '\'' + dbSlotLeader.rows[0].description + '\' and epoch_no = ' + dbEpoch.rows[0].epoch_no + ';') + const dbEpoch = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbSlotLeader = await getTestData('SELECT description FROM slot_leader WHERE slot_leader.description IS NOT NULL ORDER BY RANDOM() LIMIT 1;') + const dbCount = await getTestData('SELECT COUNT(*) as count FROM block join slot_leader sl on block.slot_leader_id = sl.id where description = ' + '\'' + dbSlotLeader.rows[0].description + '\' and epoch_no = ' + dbEpoch.rows[0].epoch_no + ';') logger.info('Epoch number -', dbEpoch.rows[0].epoch_no, ', slot leader - ', dbSlotLeader.rows[0].description) const result = await client.query({ query: await loadQueryNode('numberOfBlocksProducedByLeaderInEpoch'), @@ -72,7 +78,7 @@ describe('epochs', () => { }) it('Returns epoch details by number range', async () => { - const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbResp = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') const result = await client.query({ query: await loadQueryNode('epochDetailsInRange'), variables: { from: dbResp.rows[0].epoch_no - 2, to: dbResp.rows[0].epoch_no } @@ -82,7 +88,7 @@ describe('epochs', () => { }) it('Can return aggregated Epoch data', async () => { - const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') + const dbResp = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') logger.info('Epoch number -', dbResp.rows[0].epoch_no) const result = await client.query({ query: await loadQueryNode('aggregateEpochData'), diff --git a/packages/api-cardano-db-hasura/test/genesis.query.test.ts b/packages/api-cardano-db-hasura/test/genesis.query.test.ts index 7cc09699..7779e9be 100644 --- a/packages/api-cardano-db-hasura/test/genesis.query.test.ts +++ b/packages/api-cardano-db-hasura/test/genesis.query.test.ts @@ -18,6 +18,6 @@ describe('genesis', () => { it('Returns key information about the network genesis', async () => { const query = { query: await loadQueryNode('keyNetworkInfo') } const result = await client.query(query) - allFieldsPopulated(result.data) + allFieldsPopulated(result.data, 'staking') }) }) diff --git a/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts b/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts index 2895d054..ec50e432 100644 --- a/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts +++ b/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts @@ -59,6 +59,6 @@ describe('paymentAddress', () => { const boundedAdaBalance = new BigNumber( boundedResult.data.paymentAddresses[0].summary?.assetBalances[0]?.quantity ).toNumber() || 0 - expect(unboundedAdaBalance).toBeGreaterThan(boundedAdaBalance) + expect(unboundedAdaBalance).toBeGreaterThanOrEqual(boundedAdaBalance) }) }) diff --git a/packages/api-cardano-db-hasura/test/rewards.query.test.ts b/packages/api-cardano-db-hasura/test/rewards.query.test.ts index 46f3d63e..8e37f526 100644 --- a/packages/api-cardano-db-hasura/test/rewards.query.test.ts +++ b/packages/api-cardano-db-hasura/test/rewards.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' import Logger from 'bunyan' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'rewards'), name) @@ -23,9 +23,15 @@ describe('rewards', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('can return details for rewards scoped to an address', async () => { - const dbResp = await db.query('SELECT view FROM reward JOIN stake_address sa ON reward.addr_id = sa.id ORDER BY RANDOM() LIMIT 1;') + const dbResp = await getTestData('SELECT * FROM reward JOIN stake_address sa ON reward.addr_id = sa.id WHERE amount>0 ORDER BY RANDOM() LIMIT 1;') const stakeAddress = dbResp.rows[0].view logger.info('Stake address - ' + stakeAddress) const result = await client.query({ diff --git a/packages/api-cardano-db-hasura/test/stakePool.query.test.ts b/packages/api-cardano-db-hasura/test/stakePool.query.test.ts index 783fa265..3df54d5d 100644 --- a/packages/api-cardano-db-hasura/test/stakePool.query.test.ts +++ b/packages/api-cardano-db-hasura/test/stakePool.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' import Logger from 'bunyan' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_pools'), name) @@ -23,9 +23,15 @@ describe('stakePools', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('can lookup stake pools by ID', async () => { - const dbResp = await db.query('SELECT view FROM pool_hash ORDER BY RANDOM() LIMIT 1;') + const dbResp = await getTestData('SELECT view FROM pool_hash ORDER BY RANDOM() LIMIT 1;') const poolId = dbResp.rows[0].view logger.info('Stake pool id - ' + poolId) const result = await client.query({ diff --git a/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts b/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts index 93e8183c..da502bef 100644 --- a/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts +++ b/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { init } from './util' import Logger from 'bunyan' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'token_mints'), name) @@ -23,6 +23,12 @@ describe('tokenMints', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('can return information on token minting and burning', async () => { const result = await client.query({ @@ -40,7 +46,7 @@ describe('tokenMints', () => { }) it('can return information on assets by fingerprint', async () => { - const dbResp = await db.query('SELECT fingerprint FROM "Asset" ORDER BY RANDOM() LIMIT 1;') + const dbResp = await getTestData('SELECT fingerprint FROM "Asset" ORDER BY RANDOM() LIMIT 1;') const fingerprint = dbResp.rows[0].fingerprint logger.info('Fingerprint - ' + fingerprint) const result = await client.query({ diff --git a/packages/api-cardano-db-hasura/test/transactions.query.test.ts b/packages/api-cardano-db-hasura/test/transactions.query.test.ts index 925f0874..6bdff841 100644 --- a/packages/api-cardano-db-hasura/test/transactions.query.test.ts +++ b/packages/api-cardano-db-hasura/test/transactions.query.test.ts @@ -6,7 +6,7 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { allFieldsPopulated, init } from './util' import Logger from 'bunyan' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'transactions'), name) @@ -23,9 +23,15 @@ describe('transactions', () => { afterAll(async () => { await db.end() }) + const getTestData = async (sql: string) :Promise => { + const resp = await db.query(sql) + if (resp.rows.length === 0) logger.error('Can not find suitable data in db') + expect(resp.rows.length).toBeGreaterThan(0) + return resp + } it('Returns transactions by hashes', async () => { - const dbResp = await db.query('SELECT hash FROM tx ORDER BY RANDOM() LIMIT 2;') + const dbResp = await getTestData('SELECT hash FROM tx ORDER BY RANDOM() LIMIT 2;') const txHash1 = dbResp.rows[0].hash.toString('hex') const txHash2 = dbResp.rows[1].hash.toString('hex') logger.info('Hashes - ', txHash1, txHash2) @@ -37,7 +43,7 @@ describe('transactions', () => { }) it('Returns transactions by hashes with scripts', async () => { - const dbRespPlutusV1 = await db.query('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'plutusV1\' ORDER BY RANDOM() LIMIT 1;') + const dbRespPlutusV1 = await getTestData('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'plutusV1\' ORDER BY RANDOM() LIMIT 1;') const plutusV1hash = dbRespPlutusV1.rows[0].hash.toString('hex') logger.info('Plutus V1 hash - ', plutusV1hash) const plutusResult = await client.query({ @@ -47,7 +53,7 @@ describe('transactions', () => { expect(plutusResult.data.transactions.length).toEqual(1) allFieldsPopulated(plutusResult.data.transactions[0], 'amount') - const dbRespPlutusV2 = await db.query('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'plutusV2\' ORDER BY RANDOM() LIMIT 1;') + const dbRespPlutusV2 = await getTestData('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'plutusV2\' ORDER BY RANDOM() LIMIT 1;') const plutusV2hash = dbRespPlutusV2.rows[0].hash.toString('hex') logger.info('Plutus V2 hash - ', plutusV2hash) const plutusResultV2 = await client.query({ @@ -57,7 +63,7 @@ describe('transactions', () => { expect(plutusResultV2.data.transactions.length).toEqual(1) allFieldsPopulated(plutusResultV2.data.transactions[0], 'amount') - const dbRespTimelock = await db.query('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'timelock\' ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('SELECT t.hash FROM script JOIN tx t on t.id = script.tx_id WHERE type=\'timelock\' ORDER BY RANDOM() LIMIT 1;') const timelockTxHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Timelock tx hash - ', timelockTxHash) const timelockResult = await client.query({ @@ -69,7 +75,7 @@ describe('transactions', () => { }) it('Can return ordered by block index', async () => { - const dbRespTimelock = await db.query('select * from block where tx_count > 0 ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select * from block where tx_count > 0 ORDER BY RANDOM() LIMIT 1;') const blockNo = dbRespTimelock.rows[0].block_no logger.info('Block number - ', blockNo) const result = await client.query({ @@ -81,7 +87,7 @@ describe('transactions', () => { }) it('returns an empty array when the transactions has no outputs', async () => { - const dbRespTimelock = await db.query('select hash from tx left join tx_out t on tx.id = t.tx_id where t.tx_id is NULL ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select hash from tx left join tx_out t on tx.id = t.tx_id where t.tx_id is NULL ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -118,7 +124,7 @@ describe('transactions', () => { }) it('Returns correct tx data from db', async () => { - const dbRespTimelock = await db.query('SELECT hash, out_sum FROM tx JOIN (SELECT id FROM tx ORDER BY out_sum DESC LIMIT 100) AS t ON tx.id=t.id ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('SELECT hash, out_sum FROM tx JOIN (SELECT id FROM tx ORDER BY out_sum DESC LIMIT 100) AS t ON tx.id=t.id ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -131,7 +137,7 @@ describe('transactions', () => { expect(txs[0].outputs_aggregate.aggregate.sum.value).toEqual(dbRespTimelock.rows[0].out_sum) }) it('Can return aggregated data', async () => { - const dbRespTimelock = await db.query('SELECT hash FROM tx LEFT JOIN tx_out t ON tx.id = t.tx_id WHERE t.tx_id IS NOT NULL AND tx.deposit>0 ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('SELECT hash FROM tx LEFT JOIN tx_out t ON tx.id = t.tx_id WHERE t.tx_id IS NOT NULL AND tx.deposit>0 ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -145,7 +151,7 @@ describe('transactions', () => { expect(txs[0].inputs_aggregate.aggregate.sum.value).toEqual(outputsPlusFee) }) it('Can return filtered aggregated data', async () => { - const dbRespTimelock = await db.query('select hash, address from tx join tx_out t on tx.id = t.tx_id where index > 0 ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select hash, address from tx join tx_out t on tx.id = t.tx_id where index > 0 ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const addr = dbRespTimelock.rows[0].address @@ -161,7 +167,7 @@ describe('transactions', () => { describe('metadata', () => { it('JSON object', async () => { - const dbRespTimelock = await db.query('select hash from tx_metadata join tx t on t.id = tx_metadata.tx_id ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select hash from tx_metadata join tx t on t.id = tx_metadata.tx_id ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -174,7 +180,7 @@ describe('transactions', () => { describe('transactions with tokens', () => { it('shows the tokens minted and output', async () => { - const dbRespTimelock = await db.query('select * from ma_tx_mint join tx t on ma_tx_mint.tx_id = t.id where quantity > 0 ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select * from ma_tx_mint join tx t on ma_tx_mint.tx_id = t.id where quantity > 0 ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -189,7 +195,7 @@ describe('transactions', () => { describe('transactions with collateral', () => { it('shows the collateral inputs and outputs', async () => { - const dbRespTimelock = await db.query('select hash from collateral_tx_out join tx t on collateral_tx_out.tx_id = t.id ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select hash from collateral_tx_out join tx t on collateral_tx_out.tx_id = t.id ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({ @@ -203,7 +209,7 @@ describe('transactions', () => { describe('transactions with reference inputs', () => { it('shows the reference inputs', async () => { - const dbRespTimelock = await db.query('select hash from reference_tx_in join tx t on t.id = reference_tx_in.tx_in_id ORDER BY RANDOM() LIMIT 1;') + const dbRespTimelock = await getTestData('select hash from reference_tx_in join tx t on t.id = reference_tx_in.tx_in_id ORDER BY RANDOM() LIMIT 1;') const txHash = dbRespTimelock.rows[0].hash.toString('hex') logger.info('Tx hash - ', txHash) const result = await client.query({