From 80bcda179d534b8feeeb0bc50542201ebcc8a03e Mon Sep 17 00:00:00 2001 From: Rhys Bartels-Waller Date: Tue, 4 Aug 2020 01:14:03 +1000 Subject: [PATCH] test: remote data parity tests (for now) --- .../dataparitytests/blocks.parity.test.ts | 37 ---- .../dataparitytests/epochs.parity.test.ts | 126 -------------- .../test/dataparitytests/getDataFromApi.ts | 6 - .../transactions.parity.test.ts | 163 ------------------ 4 files changed, 332 deletions(-) delete mode 100644 packages/api-cardano-db-hasura/test/dataparitytests/blocks.parity.test.ts delete mode 100644 packages/api-cardano-db-hasura/test/dataparitytests/epochs.parity.test.ts delete mode 100644 packages/api-cardano-db-hasura/test/dataparitytests/getDataFromApi.ts delete mode 100644 packages/api-cardano-db-hasura/test/dataparitytests/transactions.parity.test.ts diff --git a/packages/api-cardano-db-hasura/test/dataparitytests/blocks.parity.test.ts b/packages/api-cardano-db-hasura/test/dataparitytests/blocks.parity.test.ts deleted file mode 100644 index 9dc3b6b6c..000000000 --- a/packages/api-cardano-db-hasura/test/dataparitytests/blocks.parity.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import gql from 'graphql-tag' -import utilDev, { TestClient } from '@cardano-graphql/util-dev' -import { buildSchema } from '@src/index' -import { getDataFromAPI } from './getDataFromApi' - -describe('blocks ', () => { - let client: TestClient - beforeAll(async () => { - if (process.env.TEST_MODE === 'e2e') { - client = await utilDev.createE2EClient() - } else { - const schema = await buildSchema('http://localhost:8090') - client = await utilDev.createIntegrationClient(schema) - } - }, 60000) - - it('return the same height', async () => { - const restResult = await getDataFromAPI('blocks/pages') - const graphQLResult = await client.query({ - query: gql`query Blockheight { - cardano { - tip { number } - } - }` - }) - - const restResultBlockHeight = restResult.Right[1][0].cbeBlkHeight - const graphQLBlockHeight = graphQLResult.data.cardano.tip.number - - // As we're calling an external API to check equality on something that changes every 20 seconds - // there is a small delta in the test condition to allow for this where the second API value can be - // equal to or one more than the first API value. - - expect(graphQLBlockHeight).toBeGreaterThan(restResultBlockHeight - 1) - expect(graphQLBlockHeight).toBeLessThanOrEqual(restResultBlockHeight + 1) - }) -}) diff --git a/packages/api-cardano-db-hasura/test/dataparitytests/epochs.parity.test.ts b/packages/api-cardano-db-hasura/test/dataparitytests/epochs.parity.test.ts deleted file mode 100644 index 171311b22..000000000 --- a/packages/api-cardano-db-hasura/test/dataparitytests/epochs.parity.test.ts +++ /dev/null @@ -1,126 +0,0 @@ -import gql from 'graphql-tag' -import utilDev, { TestClient } from '@cardano-graphql/util-dev' -import { getDataFromAPI } from './getDataFromApi' -import { buildSchema } from '@src/index' - -describe('epochs ', () => { - let client: TestClient - let restData: any - let graphQLData: any - const epoch = 111 - const slot = 3313 - - beforeAll(async () => { - if (process.env.TEST_MODE === 'e2e') { - client = await utilDev.createE2EClient() - } else { - const schema = await buildSchema('http://localhost:8090') - client = await utilDev.createIntegrationClient(schema) - } - const restResult = await getDataFromAPI(`epochs/${epoch}/${slot}`) - restData = restResult.Right[0] - const graphQLResult = await client.query({ - query: gql`query EpochDetails{ - epochs(where: {number:{_eq:${epoch}}}){ - number - startedAt - lastBlockTime - blocks (where: {slotInEpoch:{_eq:${slot}}}){ - slotNo - epochNo - slotInEpoch - number - hash - forgedAt - transactionsCount - transactions{ - totalOutput - } - size - createdBy - fees - } - output - } - }` - }) - graphQLData = graphQLResult.data.epochs[0].blocks[0] - }, 30000) - - it('return the same epoch number', async () => { - const restResultEpochNumber = restData.cbeEpoch - const graphQLEpochNumber = graphQLData.epochNo - - expect(restResultEpochNumber).toEqual(graphQLEpochNumber) - }) - - it('return the same slot number', async () => { - const restResultSlotNumber = restData.cbeSlot - const graphQLSlotNumber = graphQLData.slotInEpoch - - expect(restResultSlotNumber).toEqual(graphQLSlotNumber) - }) - - it('return the same block height', async () => { - const restResultBlockHeight = restData.cbeBlkHeight - const graphQLBlockHeight = graphQLData.number - - expect(restResultBlockHeight).toEqual(graphQLBlockHeight) - }) - - it('return the same block hash', async () => { - const restResultBlockHash = restData.cbeBlkHash - const graphQLBlockHash = graphQLData.id - - expect(restResultBlockHash).toEqual(graphQLBlockHash) - }) - - it('return the same block creation time', async () => { - const restResultBlockCreationUnixEpochTime = restData.cbeTimeIssued - const graphQLBlockCreationDateTime = graphQLData.forgedAt - const restResultBlockCreationDateTime = utilDev.timestampToIsoStringWithoutTimezone(restResultBlockCreationUnixEpochTime) - - expect(restResultBlockCreationDateTime).toEqual(graphQLBlockCreationDateTime) - }) - - it('return the same transactions count', async () => { - const restResultTxCount = restData.cbeTxNum - const graphQLTxCount = parseInt(graphQLData.transactionsCount) - - expect(restResultTxCount).toEqual(graphQLTxCount) - }) - - it('return the same total output', async () => { - const restResultTotalSent = parseInt(restData.cbeTotalSent.getCoin) - let graphQLTotalSent = 0 - - graphQLData.transactions.forEach( - (tx: any) => { - graphQLTotalSent += parseInt(tx.totalOutput) - } - ) - - expect(restResultTotalSent).toEqual(graphQLTotalSent) - }) - - it('return the same block size', async () => { - const restResultBlockSize = restData.cbeSize - const graphQLBlockSize = graphQLData.size - - expect(restResultBlockSize).toEqual(graphQLBlockSize) - }) - - it('return the same block leader', async () => { - const restResultBlockLeader = restData.cbeBlockLead - const graphQLBlockLeader = graphQLData.createdBy.split('-')[1] - - expect(restResultBlockLeader).toMatch(graphQLBlockLeader) - }) - - it('return the same fee', async () => { - const restResultFee = parseInt(restData.cbeFees.getCoin) - const graphQLFee = graphQLData.fees - - expect(restResultFee).toEqual(graphQLFee) - }) -}) diff --git a/packages/api-cardano-db-hasura/test/dataparitytests/getDataFromApi.ts b/packages/api-cardano-db-hasura/test/dataparitytests/getDataFromApi.ts deleted file mode 100644 index 97240fc1e..000000000 --- a/packages/api-cardano-db-hasura/test/dataparitytests/getDataFromApi.ts +++ /dev/null @@ -1,6 +0,0 @@ -import fetch from 'node-fetch' - -export async function getDataFromAPI (path: string) { - const response = await fetch(`https://explorer.cardano.org/api/${path}`) - return response.json() -} diff --git a/packages/api-cardano-db-hasura/test/dataparitytests/transactions.parity.test.ts b/packages/api-cardano-db-hasura/test/dataparitytests/transactions.parity.test.ts deleted file mode 100644 index fd636b958..000000000 --- a/packages/api-cardano-db-hasura/test/dataparitytests/transactions.parity.test.ts +++ /dev/null @@ -1,163 +0,0 @@ -import gql from 'graphql-tag' -import utilDev, { TestClient } from '@cardano-graphql/util-dev' -import { buildSchema } from '@src/index' -import { getDataFromAPI } from './getDataFromApi' - -describe('transactions', () => { - let client: TestClient - let restData: any - let graphQLData: any - - beforeAll(async () => { - if (process.env.TEST_MODE === 'e2e') { - client = await utilDev.createE2EClient() - } else { - const schema = await buildSchema('http://localhost:8090') - client = await utilDev.createIntegrationClient(schema) - } - const restResult = await getDataFromAPI('txs/summary/1ac36644733c367ee4c551413d799d2e395d6ddfe14bebf1c281e6e826901762') - restData = restResult.Right - const graphQLResult = await client.query({ - query: gql`query TxByHash{ - transactions (where: {hash: {_eq:"1ac36644733c367ee4c551413d799d2e395d6ddfe14bebf1c281e6e826901762"}}) - { - hash - fee - block{ - number - forgedAt - } - inputs(order_by: { sourceTxHash: asc }) { - address - value - sourceTxHash - sourceTxIndex - } - outputs(order_by: { index: asc }) { - address - index - value - } - - totalOutput - includedAt - } - }` - }) - graphQLData = graphQLResult.data.transactions[0] - }, 30000) - - it('return the correct hash', async () => { - const restResultId = restData.ctsId - const graphQLHash = graphQLData.hash - - expect(graphQLHash).toEqual(restResultId) - }) - - it('return the correct Result Fee', async () => { - const restResultFee = restData.ctsFees.getCoin - const graphQLFee = graphQLData.fee - - expect(graphQLFee).toEqual(parseInt(restResultFee)) - }) - - it('return the correct Total Output', async () => { - const restResultTotalOutput = restData.ctsTotalOutput.getCoin - const graphQLTotalOutput = graphQLData.totalOutput - - expect(graphQLTotalOutput).toEqual(restResultTotalOutput) - }) - - it('return the correct Block Height', async () => { - const restResultTotalOutput = restData.ctsBlockHeight - const graphQLTotalOutput = graphQLData.block.number - - expect(graphQLTotalOutput).toEqual(restResultTotalOutput) - }) - - it('return the correct Input Addresses', async () => { - const restResultInputs = restData.ctsInputs - const restResultAddresses = [] - - for (const input of restResultInputs) { - restResultAddresses.push(input[0]) - } - - const graphQLInputs = graphQLData.inputs - const graphQLAddresses = [] - - for (const input of graphQLInputs) { - graphQLAddresses.push(input.address) - } - - expect(graphQLAddresses).toEqual(restResultAddresses) - }) - - it('return the correct Input Values', async () => { - const restResultInputs = restData.ctsInputs - let restResultValues = 0 - - for (const input of restResultInputs) { - restResultValues += Number(input[1].getCoin) - } - - const graphQLInputs = graphQLData.inputs - let graphQLValues = 0 - - for (const input of graphQLInputs) { - graphQLValues += Number(input.value) - } - - expect(graphQLValues).toEqual(restResultValues) - }) - - it('return the correct Output Addresses', async () => { - const restResultOutputs = restData.ctsOutputs - const restResultAddresses = [] - - for (const output of restResultOutputs) { - restResultAddresses.push(output[0]) - } - - const graphQLOutputs = graphQLData.outputs - const graphQLAddresses = [] - - for (const output of graphQLOutputs) { - graphQLAddresses.push(output.address) - } - - expect(graphQLAddresses).toEqual(restResultAddresses) - }) - - it('return the correct Output Values', async () => { - const restResultOutputs = restData.ctsOutputs - let restResultValues = 0 - - for (const output of restResultOutputs) { - restResultValues += Number(output[1].getCoin) - } - - const graphQLOutputs = graphQLData.outputs - let graphQLValues = 0 - - for (const output of graphQLOutputs) { - graphQLValues += Number(output.value) - } - - expect(graphQLValues).toEqual(restResultValues) - }) - - it('have the same block creation time', async () => { - const restResultBlockTime = restData.ctsBlockTimeIssued - const graphQLBlockTime = graphQLData.block.forgedAt - - expect(graphQLBlockTime).toEqual(utilDev.timestampToIsoStringWithoutTimezone(restResultBlockTime)) - }) - - it('have the same transaction inclusion time', async () => { - const restResultTransactionTime = restData.ctsTxTimeIssued - const graphQLTransactionTime = graphQLData.includedAt - - expect(graphQLTransactionTime).toEqual(utilDev.timestampToIsoStringWithoutTimezone(restResultTransactionTime)) - }) -})