From a5bbb05b0dd8243e07859d9c24a07a3ac0f99d7b Mon Sep 17 00:00:00 2001 From: Dmytro Iakymenko Date: Wed, 18 Jan 2023 16:04:01 +0200 Subject: [PATCH 1/4] test: switch to network agnostic tests --- packages/api-cardano-db-hasura/test/.env | 7 + .../__snapshots__/blocks.query.test.ts.snap | 54 -- .../__snapshots__/epochs.query.test.ts.snap | 543 ------------------ .../__snapshots__/genesis.query.test.ts.snap | 119 ---- .../transactions.query.test.ts.snap | 497 ---------------- .../test/activeStake.query.test.ts | 34 +- .../test/ada.query.test.ts | 4 +- .../test/assets.query.test.ts | 41 +- .../test/blocks.query.test.ts | 138 +++-- .../test/cardano.query.test.ts | 19 +- .../test/collateralInputs.query.test.ts | 4 +- .../test/collateralOutputs.query.test.ts | 4 +- .../test/delegations.query.test.ts | 13 +- .../api-cardano-db-hasura/test/env.config.ts | 77 +++ .../test/epochs.query.test.ts | 52 +- .../test/genesis.query.test.ts | 6 +- .../api-cardano-db-hasura/test/jest-setup.ts | 4 + .../api-cardano-db-hasura/test/jest.config.js | 1 + .../test/paymentAddress.query.test.ts | 4 +- .../test/redeemers.query.test.ts | 4 +- .../test/rewards.query.test.ts | 21 +- .../test/scripts.query.test.ts | 4 +- .../test/stakeDeregistrations.query.test.ts | 10 +- .../test/stakePool.query.test.ts | 31 +- .../test/stakeRegistrations.query.test.ts | 10 +- .../test/tokenMints.query.test.ts | 17 +- .../test/transactions.query.test.ts | 148 +++-- packages/api-cardano-db-hasura/test/util.ts | 64 ++- .../test/utxos.query.test.ts | 4 +- .../test/withdrawals.query.test.ts | 10 +- 30 files changed, 524 insertions(+), 1420 deletions(-) create mode 100644 packages/api-cardano-db-hasura/test/.env delete mode 100644 packages/api-cardano-db-hasura/test/__snapshots__/blocks.query.test.ts.snap delete mode 100644 packages/api-cardano-db-hasura/test/__snapshots__/epochs.query.test.ts.snap delete mode 100644 packages/api-cardano-db-hasura/test/__snapshots__/genesis.query.test.ts.snap delete mode 100644 packages/api-cardano-db-hasura/test/__snapshots__/transactions.query.test.ts.snap create mode 100644 packages/api-cardano-db-hasura/test/env.config.ts create mode 100644 packages/api-cardano-db-hasura/test/jest-setup.ts diff --git a/packages/api-cardano-db-hasura/test/.env b/packages/api-cardano-db-hasura/test/.env new file mode 100644 index 00000000..c2fab738 --- /dev/null +++ b/packages/api-cardano-db-hasura/test/.env @@ -0,0 +1,7 @@ +URL='http://localhost:3102' +POSTGRES_DB_FILE='../../../placeholder-secrets/postgres_db' +POSTGRES_HOST='localhost' +POSTGRES_PASSWORD_FILE='../../../placeholder-secrets/postgres_password' +POSTGRES_PORT=5444 +POSTGRES_USER_FILE='../../../placeholder-secrets/postgres_user' + diff --git a/packages/api-cardano-db-hasura/test/__snapshots__/blocks.query.test.ts.snap b/packages/api-cardano-db-hasura/test/__snapshots__/blocks.query.test.ts.snap deleted file mode 100644 index df71d006..00000000 --- a/packages/api-cardano-db-hasura/test/__snapshots__/blocks.query.test.ts.snap +++ /dev/null @@ -1,54 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`blocks Can return filtered aggregated data 1`] = ` -Object { - "blocks": Array [ - Object { - "number": 283413, - "transactions_aggregate": Object { - "aggregate": Object { - "count": "456", - }, - }, - }, - ], -} -`; - -exports[`blocks are linked to their predecessor, and the chain can be traversed 1`] = ` -Object { - "blocks": Array [ - Object { - "hash": "fe1cf5316ec62103f20e327d121fcc3a5c39513444cb77223cb96c13ea9c83ad", - "previousBlock": Object { - "number": 29021, - "previousBlock": Object { - "number": 29020, - "previousBlock": Object { - "number": 29019, - }, - }, - }, - }, - ], -} -`; - -exports[`blocks are linked to their successor, and the chain can be traversed 1`] = ` -Object { - "blocks": Array [ - Object { - "hash": "fe1cf5316ec62103f20e327d121fcc3a5c39513444cb77223cb96c13ea9c83ad", - "nextBlock": Object { - "nextBlock": Object { - "nextBlock": Object { - "number": 29025, - }, - "number": 29024, - }, - "number": 29023, - }, - }, - ], -} -`; diff --git a/packages/api-cardano-db-hasura/test/__snapshots__/epochs.query.test.ts.snap b/packages/api-cardano-db-hasura/test/__snapshots__/epochs.query.test.ts.snap deleted file mode 100644 index 6c19845b..00000000 --- a/packages/api-cardano-db-hasura/test/__snapshots__/epochs.query.test.ts.snap +++ /dev/null @@ -1,543 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`epochs Can return aggregated Epoch data 1`] = ` -Object { - "epochs_aggregate": Object { - "aggregate": Object { - "count": "30", - "max": Object { - "number": 29, - "output": "17847453521738724661", - "transactionsCount": "14188", - }, - "min": Object { - "output": "0", - "transactionsCount": "0", - }, - "sum": Object { - "output": "18115468917597078469", - "transactionsCount": "18242", - }, - }, - }, -} -`; - -exports[`epochs Can return aggregated data 1`] = ` -Object { - "epochs": Array [ - Object { - "activeStake_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": null, - }, - }, - }, - "blocksCount": "10", - "blocks_aggregate": Object { - "aggregate": Object { - "count": "10", - "max": Object { - "fees": "0", - "size": 625, - }, - "min": Object { - "fees": "0", - "size": 623, - }, - "sum": Object { - "fees": "0", - "size": 6248, - }, - }, - }, - "fees": "0", - "number": 1, - }, - Object { - "activeStake_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": "437625649134702", - }, - }, - }, - "blocksCount": "20282", - "blocks_aggregate": Object { - "aggregate": Object { - "count": "20282", - "max": Object { - "fees": "5965850", - "size": 84865, - }, - "min": Object { - "fees": "0", - "size": 4, - }, - "sum": Object { - "fees": "1977055339", - "size": 11577711, - }, - }, - }, - "fees": "1977055339", - "number": 42, - }, - ], -} -`; - -exports[`epochs Can return filtered aggregated data 1`] = ` -Object { - "epochs": Array [ - Object { - "blocks_aggregate": Object { - "aggregate": Object { - "count": "0", - }, - }, - "fees": "1977055339", - "number": 42, - }, - ], -} -`; - -exports[`epochs Includes protocol params in effect for the epoch 1`] = ` -Object { - "epochs": Array [ - Object { - "protocolParams": Object { - "a0": 0.3, - "coinsPerUtxoByte": "4310", - "collateralPercent": 150, - "costModels": Object { - "PlutusV1": Object { - "addInteger-cpu-arguments-intercept": 205665, - "addInteger-cpu-arguments-slope": 812, - "addInteger-memory-arguments-intercept": 1, - "addInteger-memory-arguments-slope": 1, - "appendByteString-cpu-arguments-intercept": 1000, - "appendByteString-cpu-arguments-slope": 571, - "appendByteString-memory-arguments-intercept": 0, - "appendByteString-memory-arguments-slope": 1, - "appendString-cpu-arguments-intercept": 1000, - "appendString-cpu-arguments-slope": 24177, - "appendString-memory-arguments-intercept": 4, - "appendString-memory-arguments-slope": 1, - "bData-cpu-arguments": 1000, - "bData-memory-arguments": 32, - "blake2b_256-cpu-arguments-intercept": 117366, - "blake2b_256-cpu-arguments-slope": 10475, - "blake2b_256-memory-arguments": 4, - "cekApplyCost-exBudgetCPU": 23000, - "cekApplyCost-exBudgetMemory": 100, - "cekBuiltinCost-exBudgetCPU": 23000, - "cekBuiltinCost-exBudgetMemory": 100, - "cekConstCost-exBudgetCPU": 23000, - "cekConstCost-exBudgetMemory": 100, - "cekDelayCost-exBudgetCPU": 23000, - "cekDelayCost-exBudgetMemory": 100, - "cekForceCost-exBudgetCPU": 23000, - "cekForceCost-exBudgetMemory": 100, - "cekLamCost-exBudgetCPU": 23000, - "cekLamCost-exBudgetMemory": 100, - "cekStartupCost-exBudgetCPU": 100, - "cekStartupCost-exBudgetMemory": 100, - "cekVarCost-exBudgetCPU": 23000, - "cekVarCost-exBudgetMemory": 100, - "chooseData-cpu-arguments": 19537, - "chooseData-memory-arguments": 32, - "chooseList-cpu-arguments": 175354, - "chooseList-memory-arguments": 32, - "chooseUnit-cpu-arguments": 46417, - "chooseUnit-memory-arguments": 4, - "consByteString-cpu-arguments-intercept": 221973, - "consByteString-cpu-arguments-slope": 511, - "consByteString-memory-arguments-intercept": 0, - "consByteString-memory-arguments-slope": 1, - "constrData-cpu-arguments": 89141, - "constrData-memory-arguments": 32, - "decodeUtf8-cpu-arguments-intercept": 497525, - "decodeUtf8-cpu-arguments-slope": 14068, - "decodeUtf8-memory-arguments-intercept": 4, - "decodeUtf8-memory-arguments-slope": 2, - "divideInteger-cpu-arguments-constant": 196500, - "divideInteger-cpu-arguments-model-arguments-intercept": 453240, - "divideInteger-cpu-arguments-model-arguments-slope": 220, - "divideInteger-memory-arguments-intercept": 0, - "divideInteger-memory-arguments-minimum": 1, - "divideInteger-memory-arguments-slope": 1, - "encodeUtf8-cpu-arguments-intercept": 1000, - "encodeUtf8-cpu-arguments-slope": 28662, - "encodeUtf8-memory-arguments-intercept": 4, - "encodeUtf8-memory-arguments-slope": 2, - "equalsByteString-cpu-arguments-constant": 245000, - "equalsByteString-cpu-arguments-intercept": 216773, - "equalsByteString-cpu-arguments-slope": 62, - "equalsByteString-memory-arguments": 1, - "equalsData-cpu-arguments-intercept": 1060367, - "equalsData-cpu-arguments-slope": 12586, - "equalsData-memory-arguments": 1, - "equalsInteger-cpu-arguments-intercept": 208512, - "equalsInteger-cpu-arguments-slope": 421, - "equalsInteger-memory-arguments": 1, - "equalsString-cpu-arguments-constant": 187000, - "equalsString-cpu-arguments-intercept": 1000, - "equalsString-cpu-arguments-slope": 52998, - "equalsString-memory-arguments": 1, - "fstPair-cpu-arguments": 80436, - "fstPair-memory-arguments": 32, - "headList-cpu-arguments": 43249, - "headList-memory-arguments": 32, - "iData-cpu-arguments": 1000, - "iData-memory-arguments": 32, - "ifThenElse-cpu-arguments": 80556, - "ifThenElse-memory-arguments": 1, - "indexByteString-cpu-arguments": 57667, - "indexByteString-memory-arguments": 4, - "lengthOfByteString-cpu-arguments": 1000, - "lengthOfByteString-memory-arguments": 10, - "lessThanByteString-cpu-arguments-intercept": 197145, - "lessThanByteString-cpu-arguments-slope": 156, - "lessThanByteString-memory-arguments": 1, - "lessThanEqualsByteString-cpu-arguments-intercept": 197145, - "lessThanEqualsByteString-cpu-arguments-slope": 156, - "lessThanEqualsByteString-memory-arguments": 1, - "lessThanEqualsInteger-cpu-arguments-intercept": 204924, - "lessThanEqualsInteger-cpu-arguments-slope": 473, - "lessThanEqualsInteger-memory-arguments": 1, - "lessThanInteger-cpu-arguments-intercept": 208896, - "lessThanInteger-cpu-arguments-slope": 511, - "lessThanInteger-memory-arguments": 1, - "listData-cpu-arguments": 52467, - "listData-memory-arguments": 32, - "mapData-cpu-arguments": 64832, - "mapData-memory-arguments": 32, - "mkCons-cpu-arguments": 65493, - "mkCons-memory-arguments": 32, - "mkNilData-cpu-arguments": 22558, - "mkNilData-memory-arguments": 32, - "mkNilPairData-cpu-arguments": 16563, - "mkNilPairData-memory-arguments": 32, - "mkPairData-cpu-arguments": 76511, - "mkPairData-memory-arguments": 32, - "modInteger-cpu-arguments-constant": 196500, - "modInteger-cpu-arguments-model-arguments-intercept": 453240, - "modInteger-cpu-arguments-model-arguments-slope": 220, - "modInteger-memory-arguments-intercept": 0, - "modInteger-memory-arguments-minimum": 1, - "modInteger-memory-arguments-slope": 1, - "multiplyInteger-cpu-arguments-intercept": 69522, - "multiplyInteger-cpu-arguments-slope": 11687, - "multiplyInteger-memory-arguments-intercept": 0, - "multiplyInteger-memory-arguments-slope": 1, - "nullList-cpu-arguments": 60091, - "nullList-memory-arguments": 32, - "quotientInteger-cpu-arguments-constant": 196500, - "quotientInteger-cpu-arguments-model-arguments-intercept": 453240, - "quotientInteger-cpu-arguments-model-arguments-slope": 220, - "quotientInteger-memory-arguments-intercept": 0, - "quotientInteger-memory-arguments-minimum": 1, - "quotientInteger-memory-arguments-slope": 1, - "remainderInteger-cpu-arguments-constant": 196500, - "remainderInteger-cpu-arguments-model-arguments-intercept": 453240, - "remainderInteger-cpu-arguments-model-arguments-slope": 220, - "remainderInteger-memory-arguments-intercept": 0, - "remainderInteger-memory-arguments-minimum": 1, - "remainderInteger-memory-arguments-slope": 1, - "sha2_256-cpu-arguments-intercept": 806990, - "sha2_256-cpu-arguments-slope": 30482, - "sha2_256-memory-arguments": 4, - "sha3_256-cpu-arguments-intercept": 1927926, - "sha3_256-cpu-arguments-slope": 82523, - "sha3_256-memory-arguments": 4, - "sliceByteString-cpu-arguments-intercept": 265318, - "sliceByteString-cpu-arguments-slope": 0, - "sliceByteString-memory-arguments-intercept": 4, - "sliceByteString-memory-arguments-slope": 0, - "sndPair-cpu-arguments": 85931, - "sndPair-memory-arguments": 32, - "subtractInteger-cpu-arguments-intercept": 205665, - "subtractInteger-cpu-arguments-slope": 812, - "subtractInteger-memory-arguments-intercept": 1, - "subtractInteger-memory-arguments-slope": 1, - "tailList-cpu-arguments": 41182, - "tailList-memory-arguments": 32, - "trace-cpu-arguments": 212342, - "trace-memory-arguments": 32, - "unBData-cpu-arguments": 31220, - "unBData-memory-arguments": 32, - "unConstrData-cpu-arguments": 32696, - "unConstrData-memory-arguments": 32, - "unIData-cpu-arguments": 43357, - "unIData-memory-arguments": 32, - "unListData-cpu-arguments": 32247, - "unListData-memory-arguments": 32, - "unMapData-cpu-arguments": 38314, - "unMapData-memory-arguments": 32, - "verifyEd25519Signature-cpu-arguments-intercept": 9462713, - "verifyEd25519Signature-cpu-arguments-slope": 1021, - "verifyEd25519Signature-memory-arguments": 10, - }, - "PlutusV2": Object { - "addInteger-cpu-arguments-intercept": 205665, - "addInteger-cpu-arguments-slope": 812, - "addInteger-memory-arguments-intercept": 1, - "addInteger-memory-arguments-slope": 1, - "appendByteString-cpu-arguments-intercept": 1000, - "appendByteString-cpu-arguments-slope": 571, - "appendByteString-memory-arguments-intercept": 0, - "appendByteString-memory-arguments-slope": 1, - "appendString-cpu-arguments-intercept": 1000, - "appendString-cpu-arguments-slope": 24177, - "appendString-memory-arguments-intercept": 4, - "appendString-memory-arguments-slope": 1, - "bData-cpu-arguments": 1000, - "bData-memory-arguments": 32, - "blake2b_256-cpu-arguments-intercept": 117366, - "blake2b_256-cpu-arguments-slope": 10475, - "blake2b_256-memory-arguments": 4, - "cekApplyCost-exBudgetCPU": 23000, - "cekApplyCost-exBudgetMemory": 100, - "cekBuiltinCost-exBudgetCPU": 23000, - "cekBuiltinCost-exBudgetMemory": 100, - "cekConstCost-exBudgetCPU": 23000, - "cekConstCost-exBudgetMemory": 100, - "cekDelayCost-exBudgetCPU": 23000, - "cekDelayCost-exBudgetMemory": 100, - "cekForceCost-exBudgetCPU": 23000, - "cekForceCost-exBudgetMemory": 100, - "cekLamCost-exBudgetCPU": 23000, - "cekLamCost-exBudgetMemory": 100, - "cekStartupCost-exBudgetCPU": 100, - "cekStartupCost-exBudgetMemory": 100, - "cekVarCost-exBudgetCPU": 23000, - "cekVarCost-exBudgetMemory": 100, - "chooseData-cpu-arguments": 19537, - "chooseData-memory-arguments": 32, - "chooseList-cpu-arguments": 175354, - "chooseList-memory-arguments": 32, - "chooseUnit-cpu-arguments": 46417, - "chooseUnit-memory-arguments": 4, - "consByteString-cpu-arguments-intercept": 221973, - "consByteString-cpu-arguments-slope": 511, - "consByteString-memory-arguments-intercept": 0, - "consByteString-memory-arguments-slope": 1, - "constrData-cpu-arguments": 89141, - "constrData-memory-arguments": 32, - "decodeUtf8-cpu-arguments-intercept": 497525, - "decodeUtf8-cpu-arguments-slope": 14068, - "decodeUtf8-memory-arguments-intercept": 4, - "decodeUtf8-memory-arguments-slope": 2, - "divideInteger-cpu-arguments-constant": 196500, - "divideInteger-cpu-arguments-model-arguments-intercept": 453240, - "divideInteger-cpu-arguments-model-arguments-slope": 220, - "divideInteger-memory-arguments-intercept": 0, - "divideInteger-memory-arguments-minimum": 1, - "divideInteger-memory-arguments-slope": 1, - "encodeUtf8-cpu-arguments-intercept": 1000, - "encodeUtf8-cpu-arguments-slope": 28662, - "encodeUtf8-memory-arguments-intercept": 4, - "encodeUtf8-memory-arguments-slope": 2, - "equalsByteString-cpu-arguments-constant": 245000, - "equalsByteString-cpu-arguments-intercept": 216773, - "equalsByteString-cpu-arguments-slope": 62, - "equalsByteString-memory-arguments": 1, - "equalsData-cpu-arguments-intercept": 1060367, - "equalsData-cpu-arguments-slope": 12586, - "equalsData-memory-arguments": 1, - "equalsInteger-cpu-arguments-intercept": 208512, - "equalsInteger-cpu-arguments-slope": 421, - "equalsInteger-memory-arguments": 1, - "equalsString-cpu-arguments-constant": 187000, - "equalsString-cpu-arguments-intercept": 1000, - "equalsString-cpu-arguments-slope": 52998, - "equalsString-memory-arguments": 1, - "fstPair-cpu-arguments": 80436, - "fstPair-memory-arguments": 32, - "headList-cpu-arguments": 43249, - "headList-memory-arguments": 32, - "iData-cpu-arguments": 1000, - "iData-memory-arguments": 32, - "ifThenElse-cpu-arguments": 80556, - "ifThenElse-memory-arguments": 1, - "indexByteString-cpu-arguments": 57667, - "indexByteString-memory-arguments": 4, - "lengthOfByteString-cpu-arguments": 1000, - "lengthOfByteString-memory-arguments": 10, - "lessThanByteString-cpu-arguments-intercept": 197145, - "lessThanByteString-cpu-arguments-slope": 156, - "lessThanByteString-memory-arguments": 1, - "lessThanEqualsByteString-cpu-arguments-intercept": 197145, - "lessThanEqualsByteString-cpu-arguments-slope": 156, - "lessThanEqualsByteString-memory-arguments": 1, - "lessThanEqualsInteger-cpu-arguments-intercept": 204924, - "lessThanEqualsInteger-cpu-arguments-slope": 473, - "lessThanEqualsInteger-memory-arguments": 1, - "lessThanInteger-cpu-arguments-intercept": 208896, - "lessThanInteger-cpu-arguments-slope": 511, - "lessThanInteger-memory-arguments": 1, - "listData-cpu-arguments": 52467, - "listData-memory-arguments": 32, - "mapData-cpu-arguments": 64832, - "mapData-memory-arguments": 32, - "mkCons-cpu-arguments": 65493, - "mkCons-memory-arguments": 32, - "mkNilData-cpu-arguments": 22558, - "mkNilData-memory-arguments": 32, - "mkNilPairData-cpu-arguments": 16563, - "mkNilPairData-memory-arguments": 32, - "mkPairData-cpu-arguments": 76511, - "mkPairData-memory-arguments": 32, - "modInteger-cpu-arguments-constant": 196500, - "modInteger-cpu-arguments-model-arguments-intercept": 453240, - "modInteger-cpu-arguments-model-arguments-slope": 220, - "modInteger-memory-arguments-intercept": 0, - "modInteger-memory-arguments-minimum": 1, - "modInteger-memory-arguments-slope": 1, - "multiplyInteger-cpu-arguments-intercept": 69522, - "multiplyInteger-cpu-arguments-slope": 11687, - "multiplyInteger-memory-arguments-intercept": 0, - "multiplyInteger-memory-arguments-slope": 1, - "nullList-cpu-arguments": 60091, - "nullList-memory-arguments": 32, - "quotientInteger-cpu-arguments-constant": 196500, - "quotientInteger-cpu-arguments-model-arguments-intercept": 453240, - "quotientInteger-cpu-arguments-model-arguments-slope": 220, - "quotientInteger-memory-arguments-intercept": 0, - "quotientInteger-memory-arguments-minimum": 1, - "quotientInteger-memory-arguments-slope": 1, - "remainderInteger-cpu-arguments-constant": 196500, - "remainderInteger-cpu-arguments-model-arguments-intercept": 453240, - "remainderInteger-cpu-arguments-model-arguments-slope": 220, - "remainderInteger-memory-arguments-intercept": 0, - "remainderInteger-memory-arguments-minimum": 1, - "remainderInteger-memory-arguments-slope": 1, - "serialiseData-cpu-arguments-intercept": 1159724, - "serialiseData-cpu-arguments-slope": 392670, - "serialiseData-memory-arguments-intercept": 0, - "serialiseData-memory-arguments-slope": 2, - "sha2_256-cpu-arguments-intercept": 806990, - "sha2_256-cpu-arguments-slope": 30482, - "sha2_256-memory-arguments": 4, - "sha3_256-cpu-arguments-intercept": 1927926, - "sha3_256-cpu-arguments-slope": 82523, - "sha3_256-memory-arguments": 4, - "sliceByteString-cpu-arguments-intercept": 265318, - "sliceByteString-cpu-arguments-slope": 0, - "sliceByteString-memory-arguments-intercept": 4, - "sliceByteString-memory-arguments-slope": 0, - "sndPair-cpu-arguments": 85931, - "sndPair-memory-arguments": 32, - "subtractInteger-cpu-arguments-intercept": 205665, - "subtractInteger-cpu-arguments-slope": 812, - "subtractInteger-memory-arguments-intercept": 1, - "subtractInteger-memory-arguments-slope": 1, - "tailList-cpu-arguments": 41182, - "tailList-memory-arguments": 32, - "trace-cpu-arguments": 212342, - "trace-memory-arguments": 32, - "unBData-cpu-arguments": 31220, - "unBData-memory-arguments": 32, - "unConstrData-cpu-arguments": 32696, - "unConstrData-memory-arguments": 32, - "unIData-cpu-arguments": 43357, - "unIData-memory-arguments": 32, - "unListData-cpu-arguments": 32247, - "unListData-memory-arguments": 32, - "unMapData-cpu-arguments": 38314, - "unMapData-memory-arguments": 32, - "verifyEcdsaSecp256k1Signature-cpu-arguments": 20000000000, - "verifyEcdsaSecp256k1Signature-memory-arguments": 20000000000, - "verifyEd25519Signature-cpu-arguments-intercept": 9462713, - "verifyEd25519Signature-cpu-arguments-slope": 1021, - "verifyEd25519Signature-memory-arguments": 10, - "verifySchnorrSecp256k1Signature-cpu-arguments-intercept": 20000000000, - "verifySchnorrSecp256k1Signature-cpu-arguments-slope": 0, - "verifySchnorrSecp256k1Signature-memory-arguments": 20000000000, - }, - }, - "decentralisationParam": 0, - "eMax": 18, - "extraEntropy": null, - "keyDeposit": "2000000", - "maxBlockBodySize": 90112, - "maxBlockExMem": "62000000", - "maxBlockExSteps": "40000000000", - "maxBlockHeaderSize": 1100, - "maxCollateralInputs": 3, - "maxTxExMem": "14000000", - "maxTxExSteps": "10000000000", - "maxTxSize": 16384, - "maxValSize": "5000", - "minFeeA": 44, - "minFeeB": 155381, - "minPoolCost": "340000000", - "minUTxOValue": "4310", - "nOpt": 500, - "poolDeposit": "500000000", - "priceMem": 0.0577, - "priceStep": 0.0000721, - "protocolVersion": Object { - "major": 7, - "minor": 7, - }, - "rho": 0.003, - "tau": 0.2, - }, - }, - ], -} -`; - -exports[`epochs Returns epoch details by number 1`] = ` -Object { - "epochs": Array [ - Object { - "adaPots": Object { - "deposits": "82582000000", - "fees": "2033934733", - "reserves": "14809461163109861", - "rewards": "658670556880", - "slotNo": "16502442", - "treasury": "189886602312461", - "utxo": "29999908948086065", - }, - "blocksCount": "20282", - "fees": "1977055339", - "lastBlockTime": "2023-01-01T23:59:38Z", - "number": 42, - "output": "487684785231030", - "startedAt": "2022-12-28T00:00:42Z", - "transactionsCount": "7077", - }, - ], -} -`; - -exports[`epochs Returns epoch details by number range 1`] = ` -Object { - "epochs": Array [ - Object { - "adaPots": Object { - "deposits": "82582000000", - "fees": "2033934733", - "reserves": "14809461163109861", - "rewards": "658670556880", - "slotNo": "16502442", - "treasury": "189886602312461", - "utxo": "29999908948086065", - }, - "blocksCount": "20282", - "fees": "1977055339", - "lastBlockTime": "2023-01-01T23:59:38Z", - "number": 42, - "output": "487684785231030", - "startedAt": "2022-12-28T00:00:42Z", - "transactionsCount": "7077", - }, - ], -} -`; diff --git a/packages/api-cardano-db-hasura/test/__snapshots__/genesis.query.test.ts.snap b/packages/api-cardano-db-hasura/test/__snapshots__/genesis.query.test.ts.snap deleted file mode 100644 index c223226b..00000000 --- a/packages/api-cardano-db-hasura/test/__snapshots__/genesis.query.test.ts.snap +++ /dev/null @@ -1,119 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`genesis Returns key information about the network genesis 1`] = ` -Object { - "genesis": Object { - "alonzo": Object { - "collateralPercentage": 150, - "executionPrices": Object { - "prMem": Object { - "denominator": 10000, - "numerator": 577, - }, - "prSteps": Object { - "denominator": 10000000, - "numerator": 721, - }, - }, - "lovelacePerUTxOWord": 34482, - "maxBlockExUnits": Object { - "exUnitsMem": "50000000", - "exUnitsSteps": "40000000000", - }, - "maxCollateralInputs": 3, - "maxTxExUnits": Object { - "exUnitsMem": "10000000", - "exUnitsSteps": "10000000000", - }, - "maxValueSize": 5000, - }, - "byron": Object { - "blockVersionData": Object { - "maxBlockSize": 2000000, - "maxHeaderSize": 2000000, - "maxProposalSize": 700, - "maxTxSize": 4096, - "scriptVersion": 0, - "slotDuration": 20000, - }, - "protocolConsts": Object { - "k": 2160, - "protocolMagic": 1, - }, - "startTime": 1654041600, - }, - "shelley": Object { - "activeSlotsCoeff": 0.05, - "epochLength": 432000, - "genDelegs": Object { - "637f2e950b0fd8f8e3e811c5fbeb19e411e7a2bf37272b84b29c1a0b": Object { - "delegate": "aae9293510344ddd636364c2673e34e03e79e3eefa8dbaa70e326f7d", - "vrf": "227116365af2ed943f1a8b5e6557bfaa34996f1578eec667a5e2b361c51e4ce7", - }, - "8a4b77c4f534f8b8cc6f269e5ebb7ba77fa63a476e50e05e66d7051c": Object { - "delegate": "d15422b2e8b60e500a82a8f4ceaa98b04e55a0171d1125f6c58f8758", - "vrf": "0ada6c25d62db5e1e35d3df727635afa943b9e8a123ab83785e2281605b09ce2", - }, - "b00470cd193d67aac47c373602fccd4195aad3002c169b5570de1126": Object { - "delegate": "b3b539e9e7ed1b32fbf778bf2ebf0a6b9f980eac90ac86623d11881a", - "vrf": "0ff0ce9b820376e51c03b27877cd08f8ba40318f1a9f85a3db0b60dd03f71a7a", - }, - "b260ffdb6eba541fcf18601923457307647dce807851b9d19da133ab": Object { - "delegate": "7c64eb868b4ef566391a321c85323f41d2b95480d7ce56ad2abcb022", - "vrf": "7fb22abd39d550c9a022ec8104648a26240a9ff9c88b8b89a6e20d393c03098e", - }, - "ced1599fd821a39593e00592e5292bdc1437ae0f7af388ef5257344a": Object { - "delegate": "de7ca985023cf892f4de7f5f1d0a7181668884752d9ebb9e96c95059", - "vrf": "c301b7fc4d1b57fb60841bcec5e3d2db89602e5285801e522fce3790987b1124", - }, - "dd2a7d71a05bed11db61555ba4c658cb1ce06c8024193d064f2a66ae": Object { - "delegate": "1e113c218899ee7807f4028071d0e108fc790dade9fd1a0d0b0701ee", - "vrf": "faf2702aa4893c877c622ab22dfeaf1d0c8aab98b837fe2bf667314f0d043822", - }, - "f3b9e74f7d0f24d2314ea5dfbca94b65b2059d1ff94d97436b82d5b4": Object { - "delegate": "fd637b08cc379ef7b99c83b416458fcda8a01a606041779331008fb9", - "vrf": "37f2ea7c843a688159ddc2c38a2f997ab465150164a9136dca69564714b73268", - }, - }, - "initialFunds": Object {}, - "maxKESEvolutions": 62, - "maxLovelaceSupply": 45000000000000000, - "networkId": "Testnet", - "networkMagic": 1, - "protocolParams": Object { - "a0": 0.3, - "decentralisationParam": 1, - "eMax": 18, - "extraEntropy": Object { - "tag": "NeutralNonce", - }, - "keyDeposit": 2000000, - "maxBlockBodySize": 65536, - "maxBlockHeaderSize": 1100, - "maxTxSize": 16384, - "minFeeA": 44, - "minFeeB": 155381, - "minPoolCost": 340000000, - "minUTxOValue": 1000000, - "nOpt": 150, - "poolDeposit": 500000000, - "protocolVersion": Object { - "major": 2, - "minor": 0, - }, - "rho": 0.003, - "tau": 0.2, - }, - "securityParam": 2160, - "slotLength": 1, - "slotsPerKESPeriod": 129600, - "staking": Object { - "pools": Object {}, - "stake": Object {}, - }, - "systemStart": "2022-06-01T00:00:00Z", - "updateQuorum": 5, - }, - }, -} -`; diff --git a/packages/api-cardano-db-hasura/test/__snapshots__/transactions.query.test.ts.snap b/packages/api-cardano-db-hasura/test/__snapshots__/transactions.query.test.ts.snap deleted file mode 100644 index 962a59e8..00000000 --- a/packages/api-cardano-db-hasura/test/__snapshots__/transactions.query.test.ts.snap +++ /dev/null @@ -1,497 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`transactions Can return aggregated data 1`] = ` -Object { - "transactions": Array [ - Object { - "deposit": "0", - "fee": "207829", - "hash": "59f68ea73b95940d443dc516702d5e5deccac2429e4d974f464cc9b26292fd9c", - "inputs_aggregate": Object { - "aggregate": Object { - "count": "1", - "max": Object { - "value": "29699998493355698", - }, - "min": Object { - "value": "29699998493355698", - }, - "sum": Object { - "value": "29699998493355698", - }, - }, - }, - "outputs_aggregate": Object { - "aggregate": Object { - "count": "1", - "max": Object { - "value": "29699998493147869", - }, - "min": Object { - "value": "29699998493147869", - }, - "sum": Object { - "value": "29699998493147869", - }, - }, - }, - }, - ], -} -`; - -exports[`transactions Can return filtered aggregated data 1`] = ` -Object { - "transactions": Array [ - Object { - "hash": "a3d6f2627a56fe7921eeda546abfe164321881d41549b7f2fbf09ea0b718d758", - "outputs_aggregate": Object { - "aggregate": Object { - "count": "1", - }, - }, - }, - ], -} -`; - -exports[`transactions Returns transactions by hashes 1`] = ` -Object { - "transactions": Array [ - Object { - "block": Object { - "number": 48, - }, - "blockIndex": 0, - "collateralInputs": Array [], - "deposit": "1506000000", - "fee": "238057", - "hash": "a3d6f2627a56fe7921eeda546abfe164321881d41549b7f2fbf09ea0b718d758", - "inputs": Array [ - Object { - "address": "addr_test1vz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclgmzkket", - "sourceTxHash": "b75ec46c406113372efeb1e57d9880856c240c9b531e3c680c1c4d8bf2253625", - "sourceTxIndex": 0, - "value": "29999999999800000", - }, - ], - "inputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "29999999999800000", - }, - }, - }, - "outputs": Array [ - Object { - "address": "addr_test1vz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclgmzkket", - "addressHasScript": false, - "index": 0, - "paymentCredential": "9e5614893238cf85e284c61ec56d5efd9f9cdc4863ba7e1bf00c2c7d", - "value": "29699998493561943", - }, - Object { - "address": "addr_test1qz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclvk35gzr67hz78plv88jemfs2p9e2780xm98cfrf4vvu0rq83pdz2", - "addressHasScript": false, - "index": 1, - "paymentCredential": "9e5614893238cf85e284c61ec56d5efd9f9cdc4863ba7e1bf00c2c7d", - "value": "100000000000000", - }, - Object { - "address": "addr_test1qz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzcl03xqsyk5v0wrqen92yncmn0m0d8k0lcvwt2rkqu3gppw3sdexkvh", - "addressHasScript": false, - "index": 2, - "paymentCredential": "9e5614893238cf85e284c61ec56d5efd9f9cdc4863ba7e1bf00c2c7d", - "value": "100000000000000", - }, - Object { - "address": "addr_test1qz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclfe9t57q689t694cfavck9sh2uw545vp2hz7m7yn03r57kslz5rjf", - "addressHasScript": false, - "index": 3, - "paymentCredential": "9e5614893238cf85e284c61ec56d5efd9f9cdc4863ba7e1bf00c2c7d", - "value": "100000000000000", - }, - ], - "outputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "29999998493561943", - }, - }, - }, - "redeemers": Array [], - "scriptSize": 0, - "scripts": Array [], - "size": 1879, - "totalOutput": "29999998493561943", - "validContract": true, - "withdrawals_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": null, - }, - }, - }, - }, - Object { - "block": Object { - "number": 50, - }, - "blockIndex": 0, - "collateralInputs": Array [], - "deposit": "0", - "fee": "206245", - "hash": "a00696a0c2d70c381a265a845e43c55e1d00f96b27c06defc015dc92eb206240", - "inputs": Array [ - Object { - "address": "addr_test1vz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclgmzkket", - "sourceTxHash": "a3d6f2627a56fe7921eeda546abfe164321881d41549b7f2fbf09ea0b718d758", - "sourceTxIndex": 0, - "value": "29699998493561943", - }, - ], - "inputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "29699998493561943", - }, - }, - }, - "outputs": Array [ - Object { - "address": "addr_test1vz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclgmzkket", - "addressHasScript": false, - "index": 0, - "paymentCredential": "9e5614893238cf85e284c61ec56d5efd9f9cdc4863ba7e1bf00c2c7d", - "value": "29699998493355698", - }, - ], - "outputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "29699998493355698", - }, - }, - }, - "redeemers": Array [], - "scriptSize": 0, - "scripts": Array [], - "size": 1156, - "totalOutput": "29699998493355698", - "validContract": true, - "withdrawals_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": null, - }, - }, - }, - }, - ], -} -`; - -exports[`transactions Returns transactions by hashes with scripts 1`] = ` -Object { - "plutusResult": Object { - "data": Object { - "transactions": Array [ - Object { - "block": Object { - "number": 212294, - }, - "blockIndex": 0, - "collateralInputs": Array [ - Object { - "value": "9993865987", - }, - ], - "deposit": "0", - "fee": "922864", - "hash": "750eed6d314f64d8d5b5fe10a4bc34fe21bbf9c657660e061b26f091dac21717", - "inputs": Array [ - Object { - "address": "addr_test1wrp082rs5aa6a2pp55heu56gtmashrwx373230exgjm09vcygvy48", - "sourceTxHash": "1ac7c37eda5e446a10066fddaae5a1bdbedbc828cfc1ecf21f8308d4714b192a", - "sourceTxIndex": 0, - "value": "1387820", - }, - Object { - "address": "addr_test1qzmh55q6yrdvy52jyze9amqm28v26svjqstwgyhyfm9936z8cxm47kgqa3pgqvxhtfec076jmhfzj5v8pav5eewqxymqqpatlt", - "sourceTxHash": "b1d3ace8421a7d1549577054d1e7f437cbcf9fd91a54361fd7ab940a90778b92", - "sourceTxIndex": 0, - "value": "9993865987", - }, - ], - "inputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "9995253807", - }, - }, - }, - "outputs": Array [ - Object { - "address": "addr_test1qzmh55q6yrdvy52jyze9amqm28v26svjqstwgyhyfm9936z8cxm47kgqa3pgqvxhtfec076jmhfzj5v8pav5eewqxymqqpatlt", - "addressHasScript": false, - "index": 0, - "paymentCredential": "b77a501a20dac2515220b25eec1b51d8ad41920416e412e44eca58e8", - "value": "9994330943", - }, - ], - "outputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "9994330943", - }, - }, - }, - "redeemers": Array [ - Object { - "scriptHash": "c2f3a870a77baea821a52f9e53485efb0b8dc68fa2a8bf2644b6f2b3", - }, - Object { - "scriptHash": "7348135a9aa87bff1beba4e7fe72e66dd4cf785fcb2f221002b90ede", - }, - ], - "scriptSize": 15677, - "scripts": Array [], - "size": 16313, - "totalOutput": "9994330943", - "validContract": true, - "withdrawals_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": null, - }, - }, - }, - }, - ], - }, - "loading": false, - "networkStatus": 7, - "stale": false, - }, - "timelockResult": Object { - "data": Object { - "transactions": Array [], - }, - "loading": false, - "networkStatus": 7, - "stale": false, - }, -} -`; - -exports[`transactions metadata JSON object 1`] = ` -Object { - "transactions": Array [ - Object { - "metadata": Array [ - Object { - "key": "1", - "value": Object { - "cardano": "First Metadata from cardanocli-js", - }, - }, - ], - }, - ], -} -`; - -exports[`transactions transactions with collateral shows the collateral inputs and outputs 1`] = ` -Object { - "transactions": Array [ - Object { - "collateralInputs": Array [ - Object { - "address": "addr_test1qzu4zx26m7067am9g3zpkt3mh86j33vd6vtv5r35rxdcxwsye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqpwmzcx", - "sourceTransaction": Object { - "hash": "5b7e7789b5a71101d12c7d8070b74bb4576c361529a089176bf6c073650b9b5e", - }, - "sourceTxHash": "5b7e7789b5a71101d12c7d8070b74bb4576c361529a089176bf6c073650b9b5e", - "sourceTxIndex": 0, - "tokens": Array [], - "tokens_aggregate": Object { - "aggregate": Object { - "sum": Object { - "quantity": null, - }, - }, - }, - "value": "7413772505", - }, - ], - "collateralInputs_aggregate": Object { - "aggregate": Object { - "count": "1", - "max": Object { - "value": "7413772505", - }, - "min": Object { - "value": "7413772505", - }, - "sum": Object { - "value": "7413772505", - }, - }, - }, - "collateralOutputs": Array [ - Object { - "address": "addr_test1qzu4zx26m7067am9g3zpkt3mh86j33vd6vtv5r35rxdcxwsye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqpwmzcx", - "addressHasScript": false, - "datum": null, - "index": 2, - "paymentCredential": "b951195adf9faf776544441b2e3bb9f528c58dd316ca0e34199b833a", - "script": null, - "value": "7408772505", - }, - ], - "collateralOutputs_aggregate": Object { - "aggregate": Object { - "count": "1", - "max": Object { - "value": "7408772505", - }, - "min": Object { - "value": "7408772505", - }, - "sum": Object { - "value": "7408772505", - }, - }, - }, - "hash": "c1bb6a765ac42c5bb80e531d1feaa5bd4a4f0d55c331baffa9b014b942995947", - }, - ], -} -`; - -exports[`transactions transactions with reference inputs shows the reference inputs 1`] = ` -Object { - "transactions": Array [ - Object { - "hash": "93818dc2e98d924c7379e9a65a44e4890981e675d7e0d23601194c7dff01b0b3", - "referenceInputs": Array [ - Object { - "address": "addr_test1wr8h9xuednt82rmw7ptcdzqw7d65chtqr0e5mnkju09c0mqjz722h", - "sourceTransaction": Object { - "hash": "03d2fdb6407dc21bda7037a88c65da250766acd02327727dcf4d12fe7268833c", - }, - "sourceTxHash": "03d2fdb6407dc21bda7037a88c65da250766acd02327727dcf4d12fe7268833c", - "sourceTxIndex": 1, - }, - Object { - "address": "addr_test1wp63gyh62h77wfaa35c8u5zynulzp2afkl7yrpcr2zkk34gkwah0z", - "sourceTransaction": Object { - "hash": "5fb81bcabefefdb725a26fc9825d517ba79a05f86f845fda42b3f0f54b7ab90b", - }, - "sourceTxHash": "5fb81bcabefefdb725a26fc9825d517ba79a05f86f845fda42b3f0f54b7ab90b", - "sourceTxIndex": 1, - }, - Object { - "address": "addr_test1wp63gyh62h77wfaa35c8u5zynulzp2afkl7yrpcr2zkk34gkwah0z", - "sourceTransaction": Object { - "hash": "c3e9dcc6c638b78c2591f74cfca27fba728e56c18e0b5a61a2a0cc900592c59f", - }, - "sourceTxHash": "c3e9dcc6c638b78c2591f74cfca27fba728e56c18e0b5a61a2a0cc900592c59f", - "sourceTxIndex": 1, - }, - ], - "referenceInputs_aggregate": Object { - "aggregate": Object { - "count": "3", - "max": Object { - "value": "27989140", - }, - "min": Object { - "value": "27704680", - }, - "sum": Object { - "value": "83398500", - }, - }, - }, - }, - ], -} -`; - -exports[`transactions transactions with tokens shows the tokens minted and output 1`] = ` -Object { - "transactions": Array [ - Object { - "block": Object { - "number": 234850, - }, - "blockIndex": 1, - "deposit": "0", - "fee": "451312", - "hash": "c1bb6a765ac42c5bb80e531d1feaa5bd4a4f0d55c331baffa9b014b942995947", - "inputs": Array [ - Object { - "address": "addr_test1zrrryp45pgzvkha6hkxhsann0wcntvgjmznr6uwz2v0uvfcye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqnghs3t", - "sourceTxHash": "5b7e7789b5a71101d12c7d8070b74bb4576c361529a089176bf6c073650b9b5e", - "sourceTxIndex": 1, - "value": "1006657521", - }, - Object { - "address": "addr_test1qzu4zx26m7067am9g3zpkt3mh86j33vd6vtv5r35rxdcxwsye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqpwmzcx", - "sourceTxHash": "5b7e7789b5a71101d12c7d8070b74bb4576c361529a089176bf6c073650b9b5e", - "sourceTxIndex": 0, - "value": "7413772505", - }, - ], - "inputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "8420430026", - }, - }, - }, - "mint": Array [], - "outputs": Array [ - Object { - "address": "addr_test1qzu4zx26m7067am9g3zpkt3mh86j33vd6vtv5r35rxdcxwsye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqpwmzcx", - "index": 0, - "tokens": Array [], - "value": "7412988317", - }, - Object { - "address": "addr_test1zrrryp45pgzvkha6hkxhsann0wcntvgjmznr6uwz2v0uvfcye5pj8aafutn263fps7hk9vgkyfx7r7gfnmxfpn2v8zrqnghs3t", - "index": 1, - "tokens": Array [ - Object { - "asset": Object { - "assetId": "87aa0c11bb8f94d523a74fe7badded9c4908d1a65c8a6443e9f98db4b5966c13f108a088b3866cf685862f78817291c413ccbb4e4f47a630a2fb653a", - "assetName": "b5966c13f108a088b3866cf685862f78817291c413ccbb4e4f47a630a2fb653a", - "policyId": "87aa0c11bb8f94d523a74fe7badded9c4908d1a65c8a6443e9f98db4", - }, - "quantity": "1", - }, - ], - "value": "1006990397", - }, - ], - "outputs_aggregate": Object { - "aggregate": Object { - "sum": Object { - "value": "8419978714", - }, - }, - }, - "size": 5639, - "totalOutput": "8419978714", - "withdrawals_aggregate": Object { - "aggregate": Object { - "sum": Object { - "amount": null, - }, - }, - }, - }, - ], -} -`; 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 5126c782..52c7df22 100644 --- a/packages/api-cardano-db-hasura/test/activeStake.query.test.ts +++ b/packages/api-cardano-db-hasura/test/activeStake.query.test.ts @@ -4,25 +4,46 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'active_stake'), name) } describe('activeStake', () => { + let logger: Logger let client: TestClient + 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 = await testClient.preprod() + ({ client, db, logger } = await init('activeStake')) + await db.connect() + }) + + afterAll(async () => { + await db.end() }) 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 + + logger.info('Stake address - ' + stakeAddress) const result = await client.query({ query: await loadQueryNode('activeStakeForAddress'), - variables: { limit: 5, where: { address: { _eq: 'stake_test1upxue2rk4tp0e3tp7l0nmfmj6ar7y9yvngzu0vn7fxs9ags2apttt' } } } + variables: { limit: 5, where: { address: { _eq: stakeAddress } } } }) const { activeStake } = result.data - expect(activeStake.length).toBe(5) + expect(activeStake.length).toBeLessThanOrEqual(5) expect(activeStake[0].amount).toBeDefined() expect(activeStake[0].epochNo).toBeDefined() expect(activeStake[0].registeredWith.hash).toBeDefined() @@ -31,9 +52,12 @@ describe('activeStake', () => { }) it('can return aggregated active stake information for an address', async () => { + const dbResp = await getTestData('SELECT view FROM stake_address ORDER BY RANDOM() LIMIT 1;') + stakeAddress = dbResp.rows[0].view + logger.info('stake address - ' + stakeAddress) const result = await client.query({ query: await loadQueryNode('averageActiveStakeForAddress'), - variables: { address: 'stake_test1uq4l6kqvvhxywxxae04u4g6uv9sa0yymscuql5an693p53g4qz4rk' } + variables: { address: stakeAddress } }) const { activeStake_aggregate } = result.data expect(activeStake_aggregate.aggregate.count).toBeDefined() diff --git a/packages/api-cardano-db-hasura/test/ada.query.test.ts b/packages/api-cardano-db-hasura/test/ada.query.test.ts index 7ec501b3..323406a9 100644 --- a/packages/api-cardano-db-hasura/test/ada.query.test.ts +++ b/packages/api-cardano-db-hasura/test/ada.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' import { Genesis } from '@src/graphql_types' import BigNumber from 'bignumber.js' @@ -19,7 +19,7 @@ function loadQueryNode (name: string): Promise { describe('ada', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('ada')) }) it('returns ada supply information', async () => { 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 a6b28bd2..b4de3fd2 100644 --- a/packages/api-cardano-db-hasura/test/assets.query.test.ts +++ b/packages/api-cardano-db-hasura/test/assets.query.test.ts @@ -4,16 +4,25 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import { Logger } from 'ts-log' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'assets'), name) } describe('assets', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('assets')) + await db.connect() + }) + + afterAll(async () => { + await db.end() }) it('can return information on assets', async () => { @@ -33,11 +42,14 @@ 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 assetFingerprint = dbResp.rows[0].fingerprint + logger.info('Asset fingerprint - ' + assetFingerprint) const result = await client.query({ query: await loadQueryNode('assets'), variables: { where: { - fingerprint: { _eq: 'asset132r28qxkhg0wddjjpt2qffzd9m7g37arndlxsv' } + fingerprint: { _eq: assetFingerprint } } } }) @@ -53,25 +65,28 @@ 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 assetId = dbResp.assetId.toString('hex') + logger.info('assetId - ' + assetId) const result = await client.query({ query: await loadQueryNode('assets'), variables: { where: { _and: [{ - assetId: { _eq: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc3552085184154414441636f696e' } + assetId: { _eq: assetId } }] } } }) const { assets } = result.data - expect(assets[0].assetName).toBe('4154414441636f696e') - expect(assets[0].decimals).toBe(2) - expect(assets[0].description).toBe('This is a Test for the StakePoolOperator Script 12') - expect(assets[0].fingerprint).toBe('asset1ee0u29k4xwauf0r7w8g30klgraxw0y4rz2t7xs') - expect(assets[0].logo).toBe('iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAB1MAAAdTAB3TNyzQAAHppJREFUaN5tm3uwXddd3z/rtfc+574lXV1Z8kuyZEuy7NjxOzEFTEjqVxLiJFDHSUgoUEoHpsOUGSh0MjRMoTClnf5Bm0JLaICSlECdQB4eEjtx/JIT27JlybZsy5Kt99V9nOfee6316x9rn3OvDGfm6uics88+67d+7+/vu9SLh14RUIgI6SEopVBKIQJaKwCUUvxjDxFp/mBYloQQADBa45xDa02MEYAY4/h3YvO90X2VUmil0vUi1N6PX4cYqeuA954YI1prnLPNvQUQtFJkzmJtet8Y/Y+u2Y6+EGNcW6wxaxdYg1IakH8guIgQQhKirCuqqiZGcNYgzaLVuu/EdcIm4UEBqHSNgvEGCYDWKEBi87lWaJKwRZ4RYiDpQ6N1UpLWavz/0SMpT0YCpwXXdU2MEaXU+FlrTQgKpYTR90faRymQtc1K91PEGIii0KKR5j7SaFgA3fx4CAGRdIt0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b8X9cXCj3KzbZVFOnkSPBpRBl0A7+q8UENGrCsAZ5AUiS3Npl0VVVJCGOpqpLJyUnKqqK9TmsjC3HOkeV5mnaIMD0zS11X5EWBryq0MRhr0wYYg153Si42Gowi47MMY2S1mZ7QBC9nLF7Wrh/Fk/8P2vZySxWtuiYAAAAqdEVYdENyZWF0aW9uIFRpbWUARG8gNiBGZWIgMjAyMCAxMzoxMzo0NyArMDEwMDa/oAYAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjAtMDItMDZUMTI6Mjg6MzgrMDA6MDAgMe1rAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIwLTAyLTA2VDEyOjI4OjM4KzAwOjAwUWxV1wAAAEZ0RVh0c29mdHdhcmUASW1hZ2VNYWdpY2sgNi43LjgtOSAyMDE0LTA1LTEyIFExNiBodHRwOi8vd3d3LmltYWdlbWFnaWNrLm9yZ9yG7QAAAAAYdEVYdFRodW1iOjpEb2N1bWVudDo6UGFnZXMAMaf/uy8AAAAYdEVYdFRodW1iOjpJbWFnZTo6aGVpZ2h0ADE5Mg8AcoUAAAAXdEVYdFRodW1iOjpJbWFnZTo6V2lkdGgAMTky06whCAAAABl0RVh0VGh1bWI6Ok1pbWV0eXBlAGltYWdlL3BuZz+yVk4AAAAXdEVYdFRodW1iOjpNVGltZQAxNTgwOTkyMTE4fnNwZQAAAA90RVh0VGh1bWI6OlNpemUAMEJClKI+7AAAAFZ0RVh0VGh1bWI6OlVSSQBmaWxlOi8vL21udGxvZy9mYXZpY29ucy8yMDIwLTAyLTA2LzAwNjI1MDU4MDg5YWMwY2IwMTQ4NWIxYTAyMTk2N2Y4Lmljby5wbmdQyKrWAAAAAElFTkSuQmCC') - expect(assets[0].name).toBe('ATADA Coin') - expect(assets[0].policyId).toBe('34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518') - expect(assets[0].ticker).toBe('ATADA') - expect(assets[0].url).toBe('https://www.stakepool.at') + expect(assets[0].assetName).toBe(dbResp.assetName.toString('hex')) + expect(assets[0].decimals).toBe(dbResp.decimals) + expect(assets[0].description).toBe(dbResp.description) + expect(assets[0].fingerprint).toBe(dbResp.fingerprint) + expect(assets[0].logo).toBe(dbResp.logo) + expect(assets[0].name).toBe(dbResp.name) + expect(assets[0].policyId).toBe(dbResp.policyId.toString('hex')) + expect(assets[0].ticker).toBe(dbResp.ticker) + expect(assets[0].url).toBe(dbResp.url) }) }) 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 6e97fd07..a6726623 100644 --- a/packages/api-cardano-db-hasura/test/blocks.query.test.ts +++ b/packages/api-cardano-db-hasura/test/blocks.query.test.ts @@ -3,28 +3,32 @@ import { DocumentNode } from 'graphql' import gql from 'graphql-tag' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { allFieldsPopulated, init } from './util' +import { Logger } from 'ts-log' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'blocks'), name) } -const allFieldsPopulated = (obj: any) => { - let k: keyof typeof obj - for (k in obj) { - if ( - typeof k === 'object' - ) { - allFieldsPopulated(k) - } - expect(k).not.toBeNull() - } -} - describe('blocks', () => { + let logger: Logger 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 = await testClient.preprod() + ({ client, db, logger } = await init('blocks')) + await db.connect() + }) + + afterAll(async () => { + await db.end() }) it('caps the response to 100 blocks', async () => { @@ -48,76 +52,100 @@ describe('blocks', () => { }) it('Can return blocks by number', async () => { + const dbResp = await getTestData('SELECT block_no FROM block WHERE block_no IS NOT NULL ORDER BY RANDOM() LIMIT 2;') + logger.info('Block numbers -', dbResp.rows[0].block_no, dbResp.rows[1].block_no) const result = await client.query({ query: await loadQueryNode('blockByNumbers'), - variables: { numbers: [100, 200] } + variables: { numbers: [dbResp.rows[0].block_no, dbResp.rows[1].block_no] } }) expect(result.data.blocks.length).toBe(2) expect(result.data.blocks[0].hash).not.toBeNull() expect(result.data.blocks[1].hash).not.toBeNull() }) - // Todo: Restore. Assertion is valid, but matcher seems to have 'ArrayContaining [ObjectContaining' appended - // it('Can return blocks by an array of hashes', async () => { - // const result = await client.query({ - // query: await loadQueryNode('blocksByHashes'), - // variables: { hashes: [block29021.basic.hash, block29022.basic.hash] } - // }) - // expect(result.data.blocks.length).toBe(2) - // console.log() - // expect(result.data.blocks).toEqual( - // expect.arrayContaining([ - // expect.objectContaining(block29021.basic), - // expect.objectContaining(block29022.basic) - // ]) - // ) - // }) + it('Can return blocks by an array of hashes', async () => { + const dbResp = await getTestData('SELECT hash FROM block WHERE block_no IS NOT NULL ORDER BY RANDOM() LIMIT 2;') + logger.info('Hashes -', dbResp.rows[0].hash.toString('hex'), dbResp.rows[1].hash.toString('hex')) + const result = await client.query({ + query: await loadQueryNode('blocksByHashes'), + variables: { + hashes: [ + dbResp.rows[0].hash.toString('hex'), + dbResp.rows[1].hash.toString('hex')] + } + }) + expect(result.data.blocks.length).toBe(2) + allFieldsPopulated(result.data.blocks[0]) + }) it('Can return aggregated data', async () => { + const dbResp = await getTestData('SELECT block_no FROM block WHERE block_no IS NOT NULL AND tx_count>0 ORDER BY RANDOM() LIMIT 1;') + const epochResp = await getTestData('SELECT max(epoch_no) AS epoch_no FROM block;') + logger.info('Block number -', dbResp.rows[0].block_no, ',epoch number -', epochResp.rows[0].epoch_no) const result = await client.query({ query: await loadQueryNode('aggregateDataWithinBlock'), - variables: { number: 283413, epochLessThan: 50 } + variables: { number: dbResp.rows[0].block_no, epochLessThan: epochResp.rows[0].epoch_no } }) allFieldsPopulated(result.data.blocks[0]) }) it('Can return filtered aggregated data', async () => { - const result = await client.query({ - query: gql`query { - blocks( where: { number: { _eq: 283413 }}) { - transactions_aggregate( - where: { - _and: [ - { fee: { _gt: "10" }}, - { totalOutput: { _lt: "4924799478670" } } - ] - }) { - aggregate { - count - } - } - number + 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 query = gql`query { + blocks( where: { number: { _eq: ${dbResp.rows[0].block_no} }}) { + transactions_aggregate( + where: { + _and: [ + { fee: { _gt: "${fee}" }}, + { totalOutput: { _lt: "4924799478670" } } + ] + }) { + aggregate { + count } - }` - }) - expect(result.data).toMatchSnapshot() + } + number + } + }` + let result = await client.query({ query }) + expect(result.data.blocks[0].transactions_aggregate.aggregate.count).toEqual(dbResp.rows[0].tx_count) + + fee = 1000000000 + query = gql`query { + blocks( where: { number: { _eq: ${dbResp.rows[0].block_no} }}) { + transactions_aggregate( + where: { + _and: [ + { fee: { _gt: "${fee}" }}, + { totalOutput: { _lt: "4924799478670" } } + ] + }) { + aggregate { + count + } + } + number + } + }` + result = await client.query({ query }) + expect(result.data.blocks[0].transactions_aggregate.aggregate.count).toEqual('0') }) it('are linked to their predecessor, and the chain can be traversed', async () => { const result = await client.query({ query: await loadQueryNode('selectGreatGrandparentBlock'), - variables: { number: 29022 } + variables: { number: 10 } }) - expect(result.data.blocks[0].previousBlock.previousBlock.previousBlock.number).toBe(29019) - expect(result.data).toMatchSnapshot() + expect(result.data.blocks[0].previousBlock.previousBlock.previousBlock.number).toBe(7) }) it('are linked to their successor, and the chain can be traversed', async () => { const result = await client.query({ query: await loadQueryNode('selectGreatGrandchildBlock'), - variables: { number: 29022 } + variables: { number: 9 } }) - expect(result.data.blocks[0].nextBlock.nextBlock.nextBlock.number).toBe(29025) - expect(result.data).toMatchSnapshot() + expect(result.data.blocks[0].nextBlock.nextBlock.nextBlock.number).toBe(12) }) }) 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 e88a3480..3c5b13f5 100644 --- a/packages/api-cardano-db-hasura/test/cardano.query.test.ts +++ b/packages/api-cardano-db-hasura/test/cardano.query.test.ts @@ -3,7 +3,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import { Client } from 'pg' +import Logger from 'bunyan' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'cardano'), name) @@ -11,15 +13,24 @@ function loadQueryNode (name: string): Promise { describe('cardano', () => { let client: TestClient + let db: Client + let logger: Logger beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('cardano')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) 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;') + logger.info('Tip - ', dbTip.rows[0].block_no, ' epoch - ', dbEpoch.rows[0].epoch_no) const result = await client.query({ query: await loadQueryNode('chainTipAndCurrentEpochNumber') }) - expect(result.data.cardano.tip.number).toBeGreaterThan(478480) - expect(result.data.cardano.currentEpoch.number).toBeGreaterThan(42) + expect(result.data.cardano.tip.number).toBeGreaterThanOrEqual(dbTip.rows[0].block_no) + expect(result.data.cardano.currentEpoch.number).toBeGreaterThanOrEqual(dbEpoch.rows[0].epoch_no) }) }) diff --git a/packages/api-cardano-db-hasura/test/collateralInputs.query.test.ts b/packages/api-cardano-db-hasura/test/collateralInputs.query.test.ts index 16702f4a..a64ce044 100644 --- a/packages/api-cardano-db-hasura/test/collateralInputs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/collateralInputs.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'collateral_inputs'), name) @@ -12,7 +12,7 @@ function loadQueryNode (name: string): Promise { describe('collateralInputs', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('collateralInputs')) }) it('can return an array of collateral inputs', async () => { diff --git a/packages/api-cardano-db-hasura/test/collateralOutputs.query.test.ts b/packages/api-cardano-db-hasura/test/collateralOutputs.query.test.ts index 8bc1735d..e6f1f7d4 100644 --- a/packages/api-cardano-db-hasura/test/collateralOutputs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/collateralOutputs.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'collateral_outputs'), name) @@ -12,7 +12,7 @@ function loadQueryNode (name: string): Promise { describe('collateralOutputs', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('collateralOutputs')) }) it('can return an array of collateral outputs', async () => { 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 b6d6c92e..acf6bd97 100644 --- a/packages/api-cardano-db-hasura/test/delegations.query.test.ts +++ b/packages/api-cardano-db-hasura/test/delegations.query.test.ts @@ -4,7 +4,8 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'delegations'), name) @@ -12,8 +13,13 @@ function loadQueryNode (name: string): Promise { describe('delegations', () => { let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db } = await init('delegations')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) it('can return details for stake delegation', async () => { @@ -29,10 +35,11 @@ describe('delegations', () => { }) it('can return aggregated data on all delegations', async () => { + const dbResp = await db.query('SELECT COUNT(*) as count FROM delegation;') const result = await client.query({ query: await loadQueryNode('aggregateDelegation') }) const { delegations_aggregate } = result.data - expect(parseInt(delegations_aggregate.aggregate.count)).toBeGreaterThan(900) + expect(delegations_aggregate.aggregate.count).toEqual(dbResp.rows[0].count) }) }) diff --git a/packages/api-cardano-db-hasura/test/env.config.ts b/packages/api-cardano-db-hasura/test/env.config.ts new file mode 100644 index 00000000..ea3873b9 --- /dev/null +++ b/packages/api-cardano-db-hasura/test/env.config.ts @@ -0,0 +1,77 @@ +import { DbConfig } from '@src/typeAliases' +import { LogLevelString } from 'bunyan' +import { MissingConfig } from '@cardano-graphql/server/dist/errors' +import fs from 'fs-extra' + +export type EnvConfig = { + url: string, + db: DbConfig, + loggerMinSeverity: LogLevelString +}; +export async function getTestConfig (): Promise { + const env = filterAndTypecastEnvs(process.env) + if (!env.url) { + throw new MissingConfig('URL env not set') + } + if (!env.postgres.dbFile && !env.postgres.db) { + throw new MissingConfig('POSTGRES_DB_FILE or POSTGRES_DB env not set') + } + if (!env.postgres.host) { + throw new MissingConfig('POSTGRES_HOST env not set') + } + if (!env.postgres.passwordFile && !env.postgres.password) { + throw new MissingConfig('POSTGRES_PASSWORD_FILE or POSTGRES_PASSWORD env not set') + } + if (!env.postgres.port) { + throw new MissingConfig('POSTGRES_PORT env not set') + } + if (!env.postgres.userFile && !env.postgres.user) { + throw new MissingConfig('POSTGRES_USER_FILE or POSTGRES_USER env not set') + } + let db: any + try { + db = { + database: env.postgres.db || (await fs.readFile(env.postgres.dbFile, 'utf8')).toString().trim(), + host: env.postgres.host, + password: env.postgres.password || (await fs.readFile(env.postgres.passwordFile, 'utf8')).toString().trim(), + port: env.postgres.port, + user: env.postgres.user || (await fs.readFile(env.postgres.userFile, 'utf8')).toString().trim() + } + } catch (error) { + throw new MissingConfig('Database configuration cannot be read') + } + return { + url: env.url, + db, + loggerMinSeverity: env.loggerMinSeverity as LogLevelString || 'info' as LogLevelString + } +} + +function filterAndTypecastEnvs (env: any) { + const { + URL, + POSTGRES_DB, + POSTGRES_DB_FILE, + POSTGRES_HOST, + POSTGRES_PASSWORD, + POSTGRES_PASSWORD_FILE, + POSTGRES_PORT, + POSTGRES_USER, + POSTGRES_USER_FILE, + LOGGER_MIN_SEVERITY + } = env as NodeJS.ProcessEnv + return { + url: URL, + postgres: { + db: POSTGRES_DB, + dbFile: POSTGRES_DB_FILE, + host: POSTGRES_HOST, + password: POSTGRES_PASSWORD, + passwordFile: POSTGRES_PASSWORD_FILE, + port: POSTGRES_PORT ? Number(POSTGRES_PORT) : undefined, + user: POSTGRES_USER, + userFile: POSTGRES_USER_FILE + }, + loggerMinSeverity: LOGGER_MIN_SEVERITY + } +} 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 ad87441a..a0363f94 100644 --- a/packages/api-cardano-db-hasura/test/epochs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/epochs.query.test.ts @@ -4,68 +4,92 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { allFieldsPopulated, init } from './util' +import { Logger } from 'ts-log' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'epochs'), name) } describe('epochs', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('epochs')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) 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);') + logger.info('Epoch number -', dbResp.rows[0].no) const result = await client.query({ query: await loadQueryNode('epochDetailsByNumber'), - variables: { number: 42 } + variables: { number: dbResp.rows[0].no } }) - expect(result.data).toMatchSnapshot() + expect(result.data.epochs[0].output).toEqual(dbResp.rows[0].out_sum) + allFieldsPopulated(result.data.epochs[0]) }) it('Includes protocol params in effect for the epoch', async () => { + const dbResp = await db.query('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'), - variables: { where: { number: { _eq: 42 } } } + variables: { where: { number: { _eq: dbResp.rows[0].epoch_no } } } }) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data.epochs[0].protocolParams, 'extraEntropy') }) it('Can return aggregated data', async () => { + const dbResp = await db.query('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'), variables: { orderBy: { number: 'asc' }, - where: { number: { _in: [1, 42] } } + where: { number: { _in: [1, dbResp.rows[0].epoch_no] } } } }) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data.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 + ';') + logger.info('Epoch number -', dbEpoch.rows[0].epoch_no, ', slot leader - ', dbSlotLeader.rows[0].description) const result = await client.query({ query: await loadQueryNode('numberOfBlocksProducedByLeaderInEpoch'), - variables: { number: 42, slotLeader: 'ByronGenesis-0df4205606dcb8ad' } + variables: { number: dbEpoch.rows[0].epoch_no, slotLeader: dbSlotLeader.rows[0].description } }) - expect(result.data).toMatchSnapshot() + expect(result.data.epochs[0].number).toEqual(dbEpoch.rows[0].epoch_no) + expect(result.data.epochs[0].blocks_aggregate.aggregate.count).toEqual(dbCount.rows[0].count) }) it('Returns epoch details by number range', async () => { // Todo: Convert this into an actual ranged query now the performance issue is resolved. + // TODO: how to convert ??? + const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') const result = await client.query({ query: await loadQueryNode('epochDetailsInRange'), - variables: { numbers: [42] } + variables: { numbers: [dbResp.rows[0].epoch_no] } }) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data.epochs[0]) }) it('Can return aggregated Epoch data', async () => { + const dbResp = await db.query('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'), - variables: { epochNumberLessThan: 30 } + variables: { epochNumberLessThan: dbResp.rows[0].epoch_no } }) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data) }) it('Returns blocks scoped to epoch', async () => { 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 28d7cad9..7cc09699 100644 --- a/packages/api-cardano-db-hasura/test/genesis.query.test.ts +++ b/packages/api-cardano-db-hasura/test/genesis.query.test.ts @@ -2,7 +2,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { allFieldsPopulated, init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'genesis'), name) @@ -12,12 +12,12 @@ describe('genesis', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('genesis')) }) it('Returns key information about the network genesis', async () => { const query = { query: await loadQueryNode('keyNetworkInfo') } const result = await client.query(query) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data) }) }) diff --git a/packages/api-cardano-db-hasura/test/jest-setup.ts b/packages/api-cardano-db-hasura/test/jest-setup.ts new file mode 100644 index 00000000..8703dff8 --- /dev/null +++ b/packages/api-cardano-db-hasura/test/jest-setup.ts @@ -0,0 +1,4 @@ + +require('dotenv').config() + +module.exports = async () => {} diff --git a/packages/api-cardano-db-hasura/test/jest.config.js b/packages/api-cardano-db-hasura/test/jest.config.js index a9e7fbf4..97ee7330 100644 --- a/packages/api-cardano-db-hasura/test/jest.config.js +++ b/packages/api-cardano-db-hasura/test/jest.config.js @@ -2,6 +2,7 @@ const { pathsToModuleNameMapper } = require('ts-jest/utils'); const { compilerOptions } = require('./tsconfig'); module.exports = { + globalSetup: './jest-setup.ts', moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths), preset: 'ts-jest', transform: { 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 0c415138..2895d054 100644 --- a/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts +++ b/packages/api-cardano-db-hasura/test/paymentAddress.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' import BigNumber from 'bignumber.js' function loadQueryNode (name: string): Promise { @@ -17,7 +17,7 @@ function loadTestOperationDocument (name: string): Promise { describe('paymentAddress', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('paymentAddress')) }) it('returns payment address summary for the provided addresses', async () => { diff --git a/packages/api-cardano-db-hasura/test/redeemers.query.test.ts b/packages/api-cardano-db-hasura/test/redeemers.query.test.ts index 3d72ce76..f9a56d90 100644 --- a/packages/api-cardano-db-hasura/test/redeemers.query.test.ts +++ b/packages/api-cardano-db-hasura/test/redeemers.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'redeemers'), name) @@ -12,7 +12,7 @@ function loadQueryNode (name: string): Promise { describe('redeemers', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('redeemers')) }) it('can return an array of redeemers', async () => { 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 22c4baed..46f3d63e 100644 --- a/packages/api-cardano-db-hasura/test/rewards.query.test.ts +++ b/packages/api-cardano-db-hasura/test/rewards.query.test.ts @@ -4,25 +4,36 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'rewards'), name) } describe('rewards', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('rewards')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) 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 stakeAddress = dbResp.rows[0].view + logger.info('Stake address - ' + stakeAddress) const result = await client.query({ query: await loadQueryNode('rewardsForAddress'), - variables: { limit: 5, offset: 4, where: { address: { _eq: 'stake_test1uqvvzkxjzdu62l4nmcth7j0za6hragkyx8hgs6ywpk9mx0ggzmtey' } } } + variables: { limit: 5, offset: 4, where: { address: { _eq: stakeAddress } } } }) const { rewards } = result.data - expect(rewards.length).toBeGreaterThan(4) + expect(rewards.length).toBeGreaterThan(0) expect(rewards[0].stakePool.hash).toBeDefined() expect(rewards[0].earnedIn.number).toBeDefined() expect(rewards[0].receivedIn.number).toBeDefined() @@ -37,6 +48,6 @@ describe('rewards', () => { expect(parseInt(rewards_aggregate.aggregate.max.amount)).toBeDefined() expect(parseInt(rewards_aggregate.aggregate.min.amount)).toBeDefined() expect(parseInt(rewards_aggregate.aggregate.sum.amount)).toBeDefined() - expect(parseInt(rewards_aggregate.aggregate.count)).toBeGreaterThan(6000) + expect(parseInt(rewards_aggregate.aggregate.count)).toBeGreaterThan(1) }) }) diff --git a/packages/api-cardano-db-hasura/test/scripts.query.test.ts b/packages/api-cardano-db-hasura/test/scripts.query.test.ts index 0069d6f5..5d102d47 100644 --- a/packages/api-cardano-db-hasura/test/scripts.query.test.ts +++ b/packages/api-cardano-db-hasura/test/scripts.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'scripts'), name) @@ -12,7 +12,7 @@ function loadQueryNode (name: string): Promise { describe('scripts', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('scripts')) }) it('can return an array of timelock scripts', async () => { diff --git a/packages/api-cardano-db-hasura/test/stakeDeregistrations.query.test.ts b/packages/api-cardano-db-hasura/test/stakeDeregistrations.query.test.ts index 4da0c4a8..73570dda 100644 --- a/packages/api-cardano-db-hasura/test/stakeDeregistrations.query.test.ts +++ b/packages/api-cardano-db-hasura/test/stakeDeregistrations.query.test.ts @@ -4,7 +4,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_deregistrations'), name) @@ -13,16 +13,16 @@ function loadQueryNode (name: string): Promise { describe('stakeDeregistrations', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('stakeDeregistrations')) }) it('can return details for stake registrations', async () => { const result = await client.query({ query: await loadQueryNode('stakeDeregistrationsSample'), - variables: { limit: 5 } + variables: { limit: 1 } }) const { stakeDeregistrations } = result.data - expect(stakeDeregistrations.length).toBe(5) + expect(stakeDeregistrations.length).toBe(1) expect(stakeDeregistrations[0].transaction.hash).toBeDefined() }) @@ -31,6 +31,6 @@ describe('stakeDeregistrations', () => { query: await loadQueryNode('aggregateStakeDeregistrations') }) const { stakeDeregistrations_aggregate } = result.data - expect(parseInt(stakeDeregistrations_aggregate.aggregate.count)).toBeGreaterThan(10) + expect(parseInt(stakeDeregistrations_aggregate.aggregate.count)).toBeGreaterThan(0) }) }) 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 92bb214e..783fa265 100644 --- a/packages/api-cardano-db-hasura/test/stakePool.query.test.ts +++ b/packages/api-cardano-db-hasura/test/stakePool.query.test.ts @@ -4,22 +4,33 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_pools'), name) } describe('stakePools', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('stakePools')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) it('can lookup stake pools by ID', async () => { + const dbResp = await db.query('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({ query: await loadQueryNode('stakePoolById'), - variables: { id: 'pool1547tew8vmuj0g6vj3k5jfddudextcw6hsk2hwgg6pkhk7lwphe6' } + variables: { id: poolId } }) const { stakePools } = result.data expect(stakePools.length).toBe(1) @@ -30,14 +41,14 @@ describe('stakePools', () => { const result = await client.query({ query: await loadQueryNode('allStakePoolFields'), variables: { - limit: 5, - blocksLimit: 5, - delegatorsLimit: 5, - activeStakeLimit: 5 + limit: 3, + blocksLimit: 3, + delegatorsLimit: 3, + activeStakeLimit: 3 } }) const { stakePools } = result.data - expect(stakePools.length).toBe(5) + expect(stakePools.length).toBe(3) expect(stakePools[0].activeStake).toBeDefined() expect(stakePools[0].activeStake_aggregate).toBeDefined() expect(stakePools[0].blocks).toBeDefined() @@ -66,7 +77,7 @@ describe('stakePools', () => { query: await loadQueryNode('aggregateStakePoolSummary') }) const { stakePools_aggregate } = result.data - expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(150) + expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(2) }) it('can return aggregated data on active stake pools', async () => { @@ -75,7 +86,7 @@ describe('stakePools', () => { variables: { where: { _not: { retirements: {} } } } }) const { stakePools_aggregate } = result.data - expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(150) + expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(2) }) it('can return aggregated data on retiring stake pools', async () => { diff --git a/packages/api-cardano-db-hasura/test/stakeRegistrations.query.test.ts b/packages/api-cardano-db-hasura/test/stakeRegistrations.query.test.ts index e056bc81..9c3bb184 100644 --- a/packages/api-cardano-db-hasura/test/stakeRegistrations.query.test.ts +++ b/packages/api-cardano-db-hasura/test/stakeRegistrations.query.test.ts @@ -4,7 +4,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_registrations'), name) @@ -13,16 +13,16 @@ function loadQueryNode (name: string): Promise { describe('stakeRegistrations', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('stakeRegistrations')) }) it('can return details for stake registrations', async () => { const result = await client.query({ query: await loadQueryNode('stakeRegistrationsSample'), - variables: { limit: 5 } + variables: { limit: 3 } }) const { stakeRegistrations } = result.data - expect(stakeRegistrations.length).toBe(5) + expect(stakeRegistrations.length).toBe(3) expect(stakeRegistrations[0].transaction.hash).toBeDefined() }) @@ -31,6 +31,6 @@ describe('stakeRegistrations', () => { query: await loadQueryNode('aggregateStakeRegistrations') }) const { stakeRegistrations_aggregate } = result.data - expect(parseInt(stakeRegistrations_aggregate.aggregate.count)).toBeGreaterThan(1000) + expect(parseInt(stakeRegistrations_aggregate.aggregate.count)).toBeGreaterThan(1) }) }) 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 b1cac293..93e8183c 100644 --- a/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts +++ b/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts @@ -4,16 +4,24 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'token_mints'), name) } describe('tokenMints', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('tokenMints')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) it('can return information on token minting and burning', async () => { @@ -32,11 +40,14 @@ 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 fingerprint = dbResp.rows[0].fingerprint + logger.info('Fingerprint - ' + fingerprint) const result = await client.query({ query: await loadQueryNode('tokenMints'), variables: { where: { - asset: { fingerprint: { _eq: 'asset132r28qxkhg0wddjjpt2qffzd9m7g37arndlxsv' } } + asset: { fingerprint: { _eq: fingerprint } } }, limit: 10, offset: 0 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 f33edbb9..925f0874 100644 --- a/packages/api-cardano-db-hasura/test/transactions.query.test.ts +++ b/packages/api-cardano-db-hasura/test/transactions.query.test.ts @@ -4,64 +4,86 @@ import { gql } from 'apollo-boost' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { allFieldsPopulated, init } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'transactions'), name) } describe('transactions', () => { + let logger: Logger let client: TestClient + let db: Client beforeAll(async () => { - client = await testClient.preprod() + ({ client, db, logger } = await init('transactions')) + await db.connect() + }) + afterAll(async () => { + await db.end() }) it('Returns transactions by hashes', async () => { + const dbResp = await db.query('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) const result = await client.query({ query: await loadQueryNode('transactionsByHashesOrderByFee'), - variables: { - hashes: [ - 'a3d6f2627a56fe7921eeda546abfe164321881d41549b7f2fbf09ea0b718d758', - 'a00696a0c2d70c381a265a845e43c55e1d00f96b27c06defc015dc92eb206240' - ] - } + variables: { hashes: [txHash1, txHash2] } }) - expect(result.data).toMatchSnapshot() + expect(result.data.transactions.length).toEqual(2) }) 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 plutusV1hash = dbRespPlutusV1.rows[0].hash.toString('hex') + logger.info('Plutus V1 hash - ', plutusV1hash) const plutusResult = await client.query({ query: await loadQueryNode('transactionsByHashesOrderByFee'), - variables: { - hashes: [ - '750eed6d314f64d8d5b5fe10a4bc34fe21bbf9c657660e061b26f091dac21717' - ] - } + variables: { hashes: [plutusV1hash] } + }) + 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 plutusV2hash = dbRespPlutusV2.rows[0].hash.toString('hex') + logger.info('Plutus V2 hash - ', plutusV2hash) + const plutusResultV2 = await client.query({ + query: await loadQueryNode('transactionsByHashesOrderByFee'), + variables: { hashes: [plutusV2hash] } }) + 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 timelockTxHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Timelock tx hash - ', timelockTxHash) const timelockResult = await client.query({ query: await loadQueryNode('transactionsByHashesOrderByFee'), - variables: { - hashes: [ - 'c4f2f4ec91d2afe932c022b9f671cdf44ab62c35e9b6e582335ed01c82d167b0' - ] - } + variables: { hashes: [timelockTxHash] } }) - expect({ plutusResult, timelockResult }).toMatchSnapshot() + expect(timelockResult.data.transactions.length).toEqual(1) + allFieldsPopulated(plutusResult.data.transactions[0], 'amount') }) 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 blockNo = dbRespTimelock.rows[0].block_no + logger.info('Block number - ', blockNo) const result = await client.query({ query: await loadQueryNode('orderedTransactionsInBlock'), - variables: { blockNumber: 283413 } + variables: { blockNumber: blockNo } }) - expect(result.data.transactions.length).toBe(456) - expect(result.data.transactions[0].blockIndex).toBe(0) - expect(result.data.transactions[1].blockIndex).toBe(1) - expect(result.data.transactions[2].blockIndex).toBe(2) - expect(result.data.transactions[7].blockIndex).toBe(7) + expect(result.data.transactions.length.toString()).toBe(dbRespTimelock.rows[0].tx_count) + expect(result.data.transactions[0].hash).toBeDefined() }) 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: gql`query transactionWithNoOutputs( $hash: Hash32Hex! @@ -86,7 +108,7 @@ describe('transactions', () => { totalOutput } }`, - variables: { hash: '8f2def6a111c745a92fc93ee8a713974dfcd381d16b47feedef56311d16be90d' } + variables: { hash: txHash } }) expect(result.data.transactions.length).toBe(1) expect(result.data.transactions[0].outputs_aggregate.aggregate.count).toBe('0') @@ -95,76 +117,100 @@ describe('transactions', () => { expect(result.data.transactions[0].inputs_aggregate.aggregate.count).toBe('1') }) + 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) + const result = await client.query({ + query: await loadQueryNode('aggregateDataWithinTransaction'), + variables: { + hashes: [txHash] + } + }) + const { transactions: txs } = result.data + 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: await loadQueryNode('aggregateDataWithinTransaction'), variables: { - hashes: [ - '59f68ea73b95940d443dc516702d5e5deccac2429e4d974f464cc9b26292fd9c' - ] + hashes: [txHash] } }) const { transactions: txs } = result.data - const outputsPlusFee = new BigNumber(txs[0].outputs_aggregate.aggregate.sum.value).plus(txs[0].fee).toString() + const outputsPlusFee = new BigNumber(txs[0].outputs_aggregate.aggregate.sum.value).plus(txs[0].fee).plus(txs[0].deposit).toString() expect(txs[0].inputs_aggregate.aggregate.sum.value).toEqual(outputsPlusFee) - expect(result.data).toMatchSnapshot() }) 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) + const addr = dbRespTimelock.rows[0].address const result = await client.query({ query: await loadQueryNode('filteredAggregateDataWithinTransaction'), variables: { - hash: 'a3d6f2627a56fe7921eeda546abfe164321881d41549b7f2fbf09ea0b718d758', - outputsAddress: 'addr_test1vz09v9yfxguvlp0zsnrpa3tdtm7el8xufp3m5lsm7qxzclgmzkket' + hash: txHash, + outputsAddress: addr } }) - expect(result.data).toMatchSnapshot() + allFieldsPopulated(result.data.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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: await loadQueryNode('transactionByIdWithMetadataIfPresent'), - variables: { hash: '77cb8608db0a84f512e277ba923341775013241401c768ba5214ad2ac004b153' } - }) - expect(result.data).toMatchSnapshot() - }) - - it('JSON string', async () => { - const result = await client.query({ - query: await loadQueryNode('transactionByIdWithMetadataIfPresent'), - variables: { hash: '23ae1816db236baa5e231166040ae5458b25f34bb33812b2754429f122f85a0d' } + variables: { hash: txHash } }) - expect(result.data).toBeDefined() + expect(result.data.transactions[0].metadata).toBeDefined() }) }) 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: await loadQueryNode('transactionsByHashesWithTokens'), - variables: { hashes: ['c1bb6a765ac42c5bb80e531d1feaa5bd4a4f0d55c331baffa9b014b942995947'] } + variables: { hashes: [txHash] } }) - expect(result.data).toMatchSnapshot() + expect(result.data.transactions[0].mint[0].asset.assetId).toBeDefined() + expect(result.data.transactions[0].mint[0].asset.policyId).toBeDefined() + expect(result.data.transactions[0].outputs[0].address).toBeDefined() }) }) 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: await loadQueryNode('transactionsByHashesWithCollateral'), - variables: { hashes: ['c1bb6a765ac42c5bb80e531d1feaa5bd4a4f0d55c331baffa9b014b942995947'] } + variables: { hashes: [txHash] } }) - expect(result.data).toMatchSnapshot() + expect(result.data.transactions[0].collateralInputs.length).toBeGreaterThan(0) + expect(result.data.transactions[0].collateralOutputs.length).toBeGreaterThan(0) }) }) 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 txHash = dbRespTimelock.rows[0].hash.toString('hex') + logger.info('Tx hash - ', txHash) const result = await client.query({ query: await loadQueryNode('transactionsByHashesWithReferenceInputs'), - variables: { hashes: ['93818dc2e98d924c7379e9a65a44e4890981e675d7e0d23601194c7dff01b0b3'] } + variables: { hashes: [txHash] } }) - expect(result.data).toMatchSnapshot() + expect(result.data.transactions[0].referenceInputs.length).toBeGreaterThan(0) }) }) }) diff --git a/packages/api-cardano-db-hasura/test/util.ts b/packages/api-cardano-db-hasura/test/util.ts index 29780e76..59bb0335 100644 --- a/packages/api-cardano-db-hasura/test/util.ts +++ b/packages/api-cardano-db-hasura/test/util.ts @@ -2,15 +2,9 @@ import utilDev from '@cardano-graphql/util-dev' import pRetry from 'p-retry' import { gql } from 'apollo-boost' import util from '@cardano-graphql/util' - -export const testClient = { - mainnet: buildClient.bind(this, - 'http://localhost:3100' - ), - preprod: buildClient.bind(this, - 'http://localhost:3102' - ) -} +import { Client } from 'pg' +import { getTestConfig } from './env.config' +import { createLogger } from 'bunyan' export async function buildClient ( apiUri: string @@ -19,9 +13,9 @@ export async function buildClient ( await pRetry(async () => { const result = await client.query({ query: gql`query { - cardanoDbMeta { - initialized - }}` + cardanoDbMeta { + initialized + }}` }) if (result.data?.cardanoDbMeta.initialized === false) { throw new Error(`Cardano DB is not initialized: ${JSON.stringify(result.data)}`) @@ -33,3 +27,49 @@ export async function buildClient ( }) return client } + +export async function init (name: string) { + const config = await getTestConfig() + const gqlClient = await buildClient(config.url) + const dbClient: Client = new Client({ + user: config.db.user, + password: config.db.password, + database: config.db.database, + port: config.db.port + }) + const logger = createLogger({ + name, + level: config.loggerMinSeverity + }) + return { + client: gqlClient, + db: dbClient, + logger + } +} + +export const allFieldsPopulated = (obj: any, except : any = []) => { + expect(obj).toBeDefined() + if (Array.isArray(obj)) { + obj.map(allFieldsPopulated) + } else { + let k: keyof typeof obj + for (k in obj) { + if ( + typeof obj[k] === 'object' + ) { + allFieldsPopulated(obj[k], except) + } + if (except.length > 0 && !except.includes(k)) { + if (obj[k] === null) { + throw new Error('field ' + k + ' is null') + } + } + if (except.length === 0) { + if (obj[k] === null) { + throw new Error('field ' + k + ' is null') + } + } + } + } +} diff --git a/packages/api-cardano-db-hasura/test/utxos.query.test.ts b/packages/api-cardano-db-hasura/test/utxos.query.test.ts index bb9a8acc..4b42aba5 100644 --- a/packages/api-cardano-db-hasura/test/utxos.query.test.ts +++ b/packages/api-cardano-db-hasura/test/utxos.query.test.ts @@ -3,7 +3,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'utxos'), name) @@ -16,7 +16,7 @@ function loadTestOperationDocument (name: string): Promise { describe('utxos', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('utxos')) }) it('Can be scoped by address', async () => { diff --git a/packages/api-cardano-db-hasura/test/withdrawals.query.test.ts b/packages/api-cardano-db-hasura/test/withdrawals.query.test.ts index c706f68d..bf8e951f 100644 --- a/packages/api-cardano-db-hasura/test/withdrawals.query.test.ts +++ b/packages/api-cardano-db-hasura/test/withdrawals.query.test.ts @@ -4,7 +4,7 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { testClient } from './util' +import { init } from './util' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'withdrawals'), name) @@ -13,16 +13,16 @@ function loadQueryNode (name: string): Promise { describe('withdrawals', () => { let client: TestClient beforeAll(async () => { - client = await testClient.preprod() + ({ client } = await init('withdrawals')) }) it('can return details for withdrawals', async () => { const result = await client.query({ query: await loadQueryNode('withdrawalsSample'), - variables: { limit: 5 } + variables: { limit: 1 } }) const { withdrawals } = result.data - expect(withdrawals.length).toBe(5) + expect(withdrawals.length).toBe(1) expect(withdrawals[0].address.slice(0, 5)).toBe('stake') expect(withdrawals[0].amount).toBeDefined() expect(withdrawals[0].transaction.hash).toBeDefined() @@ -33,6 +33,6 @@ describe('withdrawals', () => { query: await loadQueryNode('aggregateWithdrawals') }) const { withdrawals_aggregate } = result.data - expect(parseInt(withdrawals_aggregate.aggregate.count)).toBeGreaterThan(400) + expect(parseInt(withdrawals_aggregate.aggregate.count)).toBeGreaterThan(1) }) }) From 94ace9b0eb36a2b22aa78e57c6fa4f2edf3e22a3 Mon Sep 17 00:00:00 2001 From: Dmytro Iakymenko Date: Thu, 9 Feb 2023 19:25:36 +0200 Subject: [PATCH 2/4] test: updated epochDetailsInRange query --- .../src/example_queries/epochs/epochDetailsInRange.graphql | 5 +++-- packages/api-cardano-db-hasura/test/epochs.query.test.ts | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/api-cardano-db-hasura/src/example_queries/epochs/epochDetailsInRange.graphql b/packages/api-cardano-db-hasura/src/example_queries/epochs/epochDetailsInRange.graphql index 1685e206..3d4f45d2 100644 --- a/packages/api-cardano-db-hasura/src/example_queries/epochs/epochDetailsInRange.graphql +++ b/packages/api-cardano-db-hasura/src/example_queries/epochs/epochDetailsInRange.graphql @@ -1,7 +1,8 @@ query epochDetailsInRange ( - $numbers: [Int!] + $from: Int!, + $to: Int! ) { - epochs( where: { number: { _in: $numbers }}) { + epochs( where: { number: {_gte: $from, _lte: $to } } ) { adaPots { deposits, fees, 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 a0363f94..c7d29986 100644 --- a/packages/api-cardano-db-hasura/test/epochs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/epochs.query.test.ts @@ -72,13 +72,12 @@ describe('epochs', () => { }) it('Returns epoch details by number range', async () => { - // Todo: Convert this into an actual ranged query now the performance issue is resolved. - // TODO: how to convert ??? const dbResp = await db.query('SELECT max(epoch_no) AS epoch_no FROM block;') const result = await client.query({ query: await loadQueryNode('epochDetailsInRange'), - variables: { numbers: [dbResp.rows[0].epoch_no] } + variables: { from: dbResp.rows[0].epoch_no - 2, to: dbResp.rows[0].epoch_no } }) + expect(result.data.epochs.length).toEqual(3) allFieldsPopulated(result.data.epochs[0]) }) From d246ff64a510939c9ea3444674bbdac89cf9f99d Mon Sep 17 00:00:00 2001 From: Dmytro Iakymenko Date: Fri, 10 Feb 2023 15:25:48 +0200 Subject: [PATCH 3/4] 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({ From f73e66cc5800331e1d3d397792d8e3f0f8026c1d Mon Sep 17 00:00:00 2001 From: Dmytro Iakymenko Date: Tue, 14 Feb 2023 14:45:45 +0200 Subject: [PATCH 4/4] test: hoisted logic from getTestData --- .../test/activeStake.query.test.ts | 13 +++---------- .../test/assets.query.test.ts | 13 ++++--------- .../test/blocks.query.test.ts | 17 +++++------------ .../test/cardano.query.test.ts | 11 +++-------- .../test/delegations.query.test.ts | 11 +++-------- .../test/epochs.query.test.ts | 13 ++++--------- .../test/rewards.query.test.ts | 11 +++-------- .../test/stakePool.query.test.ts | 11 +++-------- .../test/tokenMints.query.test.ts | 11 +++-------- .../test/transactions.query.test.ts | 11 +++-------- packages/api-cardano-db-hasura/test/util.ts | 11 +++++++++-- 11 files changed, 43 insertions(+), 90 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 f0b91126..4372e1aa 100644 --- a/packages/api-cardano-db-hasura/test/activeStake.query.test.ts +++ b/packages/api-cardano-db-hasura/test/activeStake.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' +import { init, queryDB } from './util' import Logger from 'bunyan' -import { Client, QueryResult } from 'pg' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'active_stake'), name) @@ -22,17 +22,10 @@ describe('activeStake', () => { ({ client, db, logger } = await init('activeStake')) 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) 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;') 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 bc671e35..e00d83c1 100644 --- a/packages/api-cardano-db-hasura/test/assets.query.test.ts +++ b/packages/api-cardano-db-hasura/test/assets.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' -import { Logger } from 'ts-log' -import { Client, QueryResult } from 'pg' +import { init, queryDB } from './util' +import { Client } from 'pg' +import Logger from 'bunyan' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'assets'), name) @@ -23,12 +23,7 @@ describe('assets', () => { 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('can return information on assets', async () => { 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 c49cd3e9..2f15f150 100644 --- a/packages/api-cardano-db-hasura/test/blocks.query.test.ts +++ b/packages/api-cardano-db-hasura/test/blocks.query.test.ts @@ -3,9 +3,9 @@ import { DocumentNode } from 'graphql' import gql from 'graphql-tag' 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, QueryResult } from 'pg' +import { allFieldsPopulated, init, queryDB } from './util' +import { Client } from 'pg' +import Logger from 'bunyan' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'blocks'), name) @@ -20,17 +20,10 @@ describe('blocks', () => { ({ client, db, logger } = await init('blocks')) 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('caps the response to 100 blocks', async () => { const result = await client.query({ @@ -91,7 +84,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;') + const dbResp = await getTestData('SELECT block_id, block_no, tx_count, fee FROM block JOIN tx t ON block.id = t.block_id WHERE block_no IS NOT NULL AND tx_count>0 GROUP BY block_id, block_no, tx_count, fee HAVING sum(fee)>0 ORDER BY RANDOM() LIMIT 1;') logger.info('Block number -', dbResp.rows[0].block_no) let fee = 0 let query = gql`query { 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 845d3289..919fce56 100644 --- a/packages/api-cardano-db-hasura/test/cardano.query.test.ts +++ b/packages/api-cardano-db-hasura/test/cardano.query.test.ts @@ -3,8 +3,8 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' -import { Client, QueryResult } from 'pg' +import { init, queryDB } from './util' +import { Client } from 'pg' import Logger from 'bunyan' function loadQueryNode (name: string): Promise { @@ -22,12 +22,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('Returns core information about the current state of the network', async () => { const dbTip = await getTestData('SELECT max(block_no) AS block_no FROM block;') 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 5327975c..d1ab03c8 100644 --- a/packages/api-cardano-db-hasura/test/delegations.query.test.ts +++ b/packages/api-cardano-db-hasura/test/delegations.query.test.ts @@ -4,8 +4,8 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' -import { Client, QueryResult } from 'pg' +import { init, queryDB } from './util' +import { Client } from 'pg' import Logger from 'bunyan' function loadQueryNode (name: string): Promise { @@ -23,12 +23,7 @@ describe('delegations', () => { 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('can return details for stake delegation', async () => { const result = await client.query({ 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 41506737..7c9a457d 100644 --- a/packages/api-cardano-db-hasura/test/epochs.query.test.ts +++ b/packages/api-cardano-db-hasura/test/epochs.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' 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, QueryResult } from 'pg' +import { allFieldsPopulated, init, queryDB } from './util' +import Logger from 'bunyan' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'epochs'), name) @@ -23,12 +23,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('Returns epoch details by number', async () => { const dbResp = await getTestData('SELECT no, out_sum FROM epoch WHERE no = (SELECT max(no) FROM epoch);') 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 8e37f526..d7dfab76 100644 --- a/packages/api-cardano-db-hasura/test/rewards.query.test.ts +++ b/packages/api-cardano-db-hasura/test/rewards.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' +import { init, queryDB } from './util' import Logger from 'bunyan' -import { Client, QueryResult } from 'pg' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'rewards'), name) @@ -23,12 +23,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('can return details for rewards scoped to an address', async () => { 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;') 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 3df54d5d..52389626 100644 --- a/packages/api-cardano-db-hasura/test/stakePool.query.test.ts +++ b/packages/api-cardano-db-hasura/test/stakePool.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' +import { init, queryDB } from './util' import Logger from 'bunyan' -import { Client, QueryResult } from 'pg' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_pools'), name) @@ -23,12 +23,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('can lookup stake pools by ID', async () => { const dbResp = await getTestData('SELECT view FROM pool_hash ORDER BY RANDOM() LIMIT 1;') 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 da502bef..7e7c917d 100644 --- a/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts +++ b/packages/api-cardano-db-hasura/test/tokenMints.query.test.ts @@ -4,9 +4,9 @@ import path from 'path' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { init } from './util' +import { init, queryDB } from './util' import Logger from 'bunyan' -import { Client, QueryResult } from 'pg' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'token_mints'), name) @@ -23,12 +23,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('can return information on token minting and burning', async () => { 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 6bdff841..fd968f57 100644 --- a/packages/api-cardano-db-hasura/test/transactions.query.test.ts +++ b/packages/api-cardano-db-hasura/test/transactions.query.test.ts @@ -4,9 +4,9 @@ import { gql } from 'apollo-boost' import { DocumentNode } from 'graphql' import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' -import { allFieldsPopulated, init } from './util' +import { allFieldsPopulated, init, queryDB } from './util' import Logger from 'bunyan' -import { Client, QueryResult } from 'pg' +import { Client } from 'pg' function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'transactions'), name) @@ -23,12 +23,7 @@ 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 - } + const getTestData = async (sql: string) => queryDB(db, logger, sql) it('Returns transactions by hashes', async () => { const dbResp = await getTestData('SELECT hash FROM tx ORDER BY RANDOM() LIMIT 2;') diff --git a/packages/api-cardano-db-hasura/test/util.ts b/packages/api-cardano-db-hasura/test/util.ts index 59bb0335..9058c0c5 100644 --- a/packages/api-cardano-db-hasura/test/util.ts +++ b/packages/api-cardano-db-hasura/test/util.ts @@ -2,9 +2,9 @@ import utilDev from '@cardano-graphql/util-dev' import pRetry from 'p-retry' import { gql } from 'apollo-boost' import util from '@cardano-graphql/util' -import { Client } from 'pg' +import { Client, QueryResult } from 'pg' import { getTestConfig } from './env.config' -import { createLogger } from 'bunyan' +import Logger, { createLogger } from 'bunyan' export async function buildClient ( apiUri: string @@ -48,6 +48,13 @@ export async function init (name: string) { } } +export const queryDB = async (db: Client, logger: Logger, 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 +} + export const allFieldsPopulated = (obj: any, except : any = []) => { expect(obj).toBeDefined() if (Array.isArray(obj)) {