From e922594a51a1e1e20400d2df6ffb93ebb79c0557 Mon Sep 17 00:00:00 2001 From: Bartlomiej Slabiak Date: Thu, 31 Oct 2024 15:39:15 +0100 Subject: [PATCH] test: increase coverage of test cases --- test/e2e/fixtures/mainnet/estimate-fee.e2e.ts | 8 +++++ .../fixtures/mainnet/get-account-info.e2e.ts | 33 +++++++++++++++++++ .../fixtures/mainnet/get-transaction.e2e.ts | 1 + .../fixtures/mainnet/subscribe-block.e2e.ts | 16 +++++++++ test/e2e/fixtures/preprod/estimate-fee.e2e.ts | 8 +++++ .../fixtures/preprod/get-account-info.e2e.ts | 33 +++++++++++++++++++ .../fixtures/preprod/get-account-utxo.e2e.ts | 7 ++++ test/e2e/fixtures/preprod/get-block.e2e.ts | 26 +++++++++++++++ .../fixtures/preprod/get-transaction.e2e.ts | 1 + .../fixtures/preprod/push-transaction.e2e.ts | 5 +++ .../fixtures/preprod/subscribe-block.e2e.ts | 8 +++++ test/e2e/tests/estimate-fee.e2e.test.ts | 18 ++++++++++ test/e2e/tests/get-account-info.e2e.test.ts | 24 ++++++++++++++ test/e2e/tests/get-account-utxo.e2e.test.ts | 21 ++++++++++++ test/e2e/tests/get-block.e2e.test.ts | 18 ++++++++++ test/e2e/tests/get-tansaction.e2e.test.ts | 2 +- test/e2e/tests/push-transaction-e2e.test.ts | 27 --------------- test/e2e/tests/push-transaction.e2e.test.ts | 26 +++++++++++++++ test/e2e/tests/subscribe-block.e2e.test.ts | 25 ++++++++------ test/e2e/tx-builder/index.ts | 4 +-- test/e2e/utils/fixtures-loader.ts | 4 +-- 21 files changed, 273 insertions(+), 42 deletions(-) create mode 100644 test/e2e/fixtures/mainnet/estimate-fee.e2e.ts create mode 100644 test/e2e/fixtures/mainnet/get-account-info.e2e.ts create mode 100644 test/e2e/fixtures/mainnet/subscribe-block.e2e.ts create mode 100644 test/e2e/fixtures/preprod/estimate-fee.e2e.ts create mode 100644 test/e2e/fixtures/preprod/get-account-info.e2e.ts create mode 100644 test/e2e/fixtures/preprod/get-account-utxo.e2e.ts create mode 100644 test/e2e/fixtures/preprod/get-block.e2e.ts create mode 100644 test/e2e/fixtures/preprod/push-transaction.e2e.ts create mode 100644 test/e2e/fixtures/preprod/subscribe-block.e2e.ts create mode 100644 test/e2e/tests/estimate-fee.e2e.test.ts create mode 100644 test/e2e/tests/get-account-info.e2e.test.ts create mode 100644 test/e2e/tests/get-account-utxo.e2e.test.ts create mode 100644 test/e2e/tests/get-block.e2e.test.ts delete mode 100644 test/e2e/tests/push-transaction-e2e.test.ts create mode 100644 test/e2e/tests/push-transaction.e2e.test.ts diff --git a/test/e2e/fixtures/mainnet/estimate-fee.e2e.ts b/test/e2e/fixtures/mainnet/estimate-fee.e2e.ts new file mode 100644 index 0000000..f18bd4f --- /dev/null +++ b/test/e2e/fixtures/mainnet/estimate-fee.e2e.ts @@ -0,0 +1,8 @@ +export default [ + { + testName: 'ESTIMATE_FEE success - mainnet', + result: { + lovelacePerByte: 44, + }, + }, +] as const; diff --git a/test/e2e/fixtures/mainnet/get-account-info.e2e.ts b/test/e2e/fixtures/mainnet/get-account-info.e2e.ts new file mode 100644 index 0000000..6f0f39d --- /dev/null +++ b/test/e2e/fixtures/mainnet/get-account-info.e2e.ts @@ -0,0 +1,33 @@ +export default [ + { + testName: 'GET_ACCOUNT_INFO success - mainnet', + descriptor: '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + details: 'basic', + page: 1, + pageSize: 25, + result: { + "descriptor": "6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2", + "empty": true, + "balance": "0", + "availableBalance": "0", + "tokens": [], + "history": { + "total": 0, + "unconfirmed": 0 + }, + "page": { + "index": 1, + "size": 25, + "total": 0 + }, + "misc": { + "staking": { + "address": "stake_test1uzzutrtmxwv2rf2j3hdpps66ch0jydmkr58vwgnetddcdwgkqkh89", + "rewards": "0", + "isActive": false, + "poolId": null + } + } + }, + }, +] as const; diff --git a/test/e2e/fixtures/mainnet/get-transaction.e2e.ts b/test/e2e/fixtures/mainnet/get-transaction.e2e.ts index d66a143..663b540 100644 --- a/test/e2e/fixtures/mainnet/get-transaction.e2e.ts +++ b/test/e2e/fixtures/mainnet/get-transaction.e2e.ts @@ -1,6 +1,7 @@ export default [ { testName: 'GET_TRANSACTION success - mainnet', + txID: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33', result: { hash: '28172ea876c3d1e691284e5179fae2feb3e69d7d41e43f8023dc380115741026', block: 'e6369fee087d31192016b1659f1c381e9fc4925339278a4eef6f340c96c1947f', diff --git a/test/e2e/fixtures/mainnet/subscribe-block.e2e.ts b/test/e2e/fixtures/mainnet/subscribe-block.e2e.ts new file mode 100644 index 0000000..c9ab6a1 --- /dev/null +++ b/test/e2e/fixtures/mainnet/subscribe-block.e2e.ts @@ -0,0 +1,16 @@ +import { expect } from 'vitest'; + +export default [ + { + testName: 'GET_SERVER success - preprod', + result: { + name: 'Cardano', + shortcut: 'tada', + testnet: true, + version: '2.2.3', + decimals: 6, + blockHeight: expect.any(Number), + blockHash: expect.stringMatching(/^[a-f0-9]{64}$/), + }, + }, +] as const; diff --git a/test/e2e/fixtures/preprod/estimate-fee.e2e.ts b/test/e2e/fixtures/preprod/estimate-fee.e2e.ts new file mode 100644 index 0000000..4c1d155 --- /dev/null +++ b/test/e2e/fixtures/preprod/estimate-fee.e2e.ts @@ -0,0 +1,8 @@ +export default [ + { + testName: 'ESTIMATE-fee success - preprod', + result: { + lovelacePerByte: 44, + }, + }, +] as const; diff --git a/test/e2e/fixtures/preprod/get-account-info.e2e.ts b/test/e2e/fixtures/preprod/get-account-info.e2e.ts new file mode 100644 index 0000000..949e0fe --- /dev/null +++ b/test/e2e/fixtures/preprod/get-account-info.e2e.ts @@ -0,0 +1,33 @@ +export default [ + { + testName: 'GET_ACCOUNT_INFO success - preprod', + descriptor: '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + details: 'basic', + page: 1, + pageSize: 25, + result: { + "descriptor": "6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2", + "empty": true, + "balance": "0", + "availableBalance": "0", + "tokens": [], + "history": { + "total": 0, + "unconfirmed": 0 + }, + "page": { + "index": 1, + "size": 25, + "total": 0 + }, + "misc": { + "staking": { + "address": "stake_test1uzzutrtmxwv2rf2j3hdpps66ch0jydmkr58vwgnetddcdwgkqkh89", + "rewards": "0", + "isActive": false, + "poolId": null + } + } + }, + }, +] as const; diff --git a/test/e2e/fixtures/preprod/get-account-utxo.e2e.ts b/test/e2e/fixtures/preprod/get-account-utxo.e2e.ts new file mode 100644 index 0000000..c352727 --- /dev/null +++ b/test/e2e/fixtures/preprod/get-account-utxo.e2e.ts @@ -0,0 +1,7 @@ +export default [ + { + testName: 'GET_ACCOUNT_UTXO success - preprod', + descriptor: '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + result: [], + }//TODO more examples +] as const; diff --git a/test/e2e/fixtures/preprod/get-block.e2e.ts b/test/e2e/fixtures/preprod/get-block.e2e.ts new file mode 100644 index 0000000..77952b4 --- /dev/null +++ b/test/e2e/fixtures/preprod/get-block.e2e.ts @@ -0,0 +1,26 @@ +import { expect } from 'vitest'; + +export default [ + { + testName: 'GET_BLOCK success - preprod', + result: { + "block_vrf": "vrf_vk1suxu5crrj7u96tjwu8jxhkum0p9qj2s7cfwts9rv7szxg4hlscwqg9ljpt", + "confirmations": expect.any(Number), + "epoch": 176, + "epoch_slot": 307781, + "fees": "4449834", + "hash": "8b41ba36539ce5f72ec5e6792dfa125ba60126443c7d2d6452f71e5f7d410cfc", + "height": 2839412, + "next_block": "83139f88a06c4ff66c395b3603f98c69f2f3732189cc5e187d6ce19bb778eb0d", + "op_cert": "a3727c534ed0bef79c124d6754c528f162e012c37069b7f6b4473e2d1262daed", + "op_cert_counter": "12", + "output": "48648336745", + "previous_block": "e72a3d503fbe6a7abaf68ab1093a03a244912fd6fa921f4e62f0661f7f239256", + "size": 29246, + "slot": 74698181, + "slot_leader": "pool1upqfyzqpk6wkpsvw90qqrpr9tjyemh484wk4em69anwpu586ehq", + "time": 1730381381, + "tx_count": 9 + }, + }, +] as const; diff --git a/test/e2e/fixtures/preprod/get-transaction.e2e.ts b/test/e2e/fixtures/preprod/get-transaction.e2e.ts index c60ee27..c2097dd 100644 --- a/test/e2e/fixtures/preprod/get-transaction.e2e.ts +++ b/test/e2e/fixtures/preprod/get-transaction.e2e.ts @@ -1,6 +1,7 @@ export default [ { testName: 'GET_TRANSACTION success - mainnet', + txID: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33', result: { hash: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33', block: 'c053f4bfbf7338b0c11a9a56302a4b51de9591f3366984660e9c9220009ad79f', diff --git a/test/e2e/fixtures/preprod/push-transaction.e2e.ts b/test/e2e/fixtures/preprod/push-transaction.e2e.ts new file mode 100644 index 0000000..14299e2 --- /dev/null +++ b/test/e2e/fixtures/preprod/push-transaction.e2e.ts @@ -0,0 +1,5 @@ +export default [ + { + testName: 'PUSH_TRANSACTION success - preprod', + }, +] as const; diff --git a/test/e2e/fixtures/preprod/subscribe-block.e2e.ts b/test/e2e/fixtures/preprod/subscribe-block.e2e.ts new file mode 100644 index 0000000..86ff160 --- /dev/null +++ b/test/e2e/fixtures/preprod/subscribe-block.e2e.ts @@ -0,0 +1,8 @@ +export default [ + { + testName: 'GET_SERVER success - preprod', + result: { + "subscribed": true, + }, + }, +] as const; diff --git a/test/e2e/tests/estimate-fee.e2e.test.ts b/test/e2e/tests/estimate-fee.e2e.test.ts new file mode 100644 index 0000000..5708e0e --- /dev/null +++ b/test/e2e/tests/estimate-fee.e2e.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, test } from 'vitest'; +import { getFixtures } from '../utils/fixtures-loader'; +import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; + +const fixtures = await getFixtures('estimate-fee'); + +describe('estimate-fee', () => { + const ws = new WebsocketClientE2e('ws://localhost:3005'); + + for (const fixture of fixtures) { + test(fixture.testName, async () => { + await ws.waitForConnection(); + const { data } = await ws.sendAndWait('ESTIMATE_FEE'); + expect(data).toMatchObject(fixture.result); + await ws.close(); + }); + } +}); diff --git a/test/e2e/tests/get-account-info.e2e.test.ts b/test/e2e/tests/get-account-info.e2e.test.ts new file mode 100644 index 0000000..e0c533d --- /dev/null +++ b/test/e2e/tests/get-account-info.e2e.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, test } from 'vitest'; +import { getFixtures } from '../utils/fixtures-loader'; +import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; + +const fixtures = await getFixtures('get-account-info'); + +describe('get-account-info', () => { + const ws = new WebsocketClientE2e('ws://localhost:3005'); + + for (const fixture of fixtures) { + test(fixture.testName, async () => { + await ws.waitForConnection(); + const { data } = await ws.sendAndWait('GET_ACCOUNT_INFO', { + descriptor: fixture.descriptor, + details: fixture.details, + page: fixture.page, + pageSize: fixture.pageSize, + }); + + expect(data).toMatchObject(fixture.result); + await ws.close(); + }); + } +}); diff --git a/test/e2e/tests/get-account-utxo.e2e.test.ts b/test/e2e/tests/get-account-utxo.e2e.test.ts new file mode 100644 index 0000000..5db374a --- /dev/null +++ b/test/e2e/tests/get-account-utxo.e2e.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, test } from 'vitest'; +import { getFixtures } from '../utils/fixtures-loader'; +import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; + +const fixtures = await getFixtures('get-account-utxo'); + +describe('get-account-utxo', () => { + const ws = new WebsocketClientE2e('ws://localhost:3005'); + + for (const fixture of fixtures) { + test(fixture.testName, async () => { + await ws.waitForConnection(); + const { data } = await ws.sendAndWait('GET_ACCOUNT_UTXO', { + descriptor: fixture.descriptor, + }); + + expect(data).toMatchObject(fixture.result); + await ws.close(); + }); + } +}); diff --git a/test/e2e/tests/get-block.e2e.test.ts b/test/e2e/tests/get-block.e2e.test.ts new file mode 100644 index 0000000..b4b8008 --- /dev/null +++ b/test/e2e/tests/get-block.e2e.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, test } from 'vitest'; +import { getFixtures } from '../utils/fixtures-loader'; +import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; + +const fixtures = await getFixtures('get-block'); + +describe('get-block', () => { + const ws = new WebsocketClientE2e('ws://localhost:3005'); + + for (const fixture of fixtures) { + test(fixture.testName, async () => { + await ws.waitForConnection(); + const { data } = await ws.sendAndWait('GET_BLOCK', { hashOrNumber: '8b41ba36539ce5f72ec5e6792dfa125ba60126443c7d2d6452f71e5f7d410cfc' }); + expect(data).toMatchObject(fixture.result); + await ws.close(); + }); + } +}); diff --git a/test/e2e/tests/get-tansaction.e2e.test.ts b/test/e2e/tests/get-tansaction.e2e.test.ts index b8c7232..336322d 100644 --- a/test/e2e/tests/get-tansaction.e2e.test.ts +++ b/test/e2e/tests/get-tansaction.e2e.test.ts @@ -11,7 +11,7 @@ describe('getLatestBlock', () => { test(fixture.testName, async () => { await ws.waitForConnection(); const response = await ws.sendAndWait('GET_TRANSACTION', { - txId: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33', + txId: fixture.txID, }); expect(response.data).toMatchObject(fixture.result); diff --git a/test/e2e/tests/push-transaction-e2e.test.ts b/test/e2e/tests/push-transaction-e2e.test.ts deleted file mode 100644 index 1b6aab2..0000000 --- a/test/e2e/tests/push-transaction-e2e.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { describe, test } from 'vitest'; -import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; -import { buildTx } from '../tx-builder'; - -describe('pushTransactionE2e', () => { - const ws = new WebsocketClientE2e('ws://localhost:3005', true); - - test('PUSH_TRANSACTION', async () => { - await ws.waitForConnection(); - const receivingAddress = - 'addr_test1qq4wgdp3xw29d6ewuv9cvx83h9v0d5sy8lntd8vrdtrsfykwfnd2ewysca99vdwkvpp6a8w9nv5u4srvw5k0ywtl3v8qrl4qwp'; - const signedTx = await buildTx('1000000', receivingAddress); - - ws.setSubscriptionCallback(message => { - console.log('Received subscription message:', message); - }); - - await ws.sendAndWait('SUBSCRIBE_ADDRESS', { - addresses: receivingAddress, - }); - - await ws.sendAndWait('PUSH_TRANSACTION', { - txData: signedTx.to_hex(), - }); - await ws.close(); - }); -}); diff --git a/test/e2e/tests/push-transaction.e2e.test.ts b/test/e2e/tests/push-transaction.e2e.test.ts new file mode 100644 index 0000000..e639bd3 --- /dev/null +++ b/test/e2e/tests/push-transaction.e2e.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from 'vitest'; +import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; +import { buildTx } from '../tx-builder'; +import { getFixtures } from '../utils/fixtures-loader'; + + +const fixtures = await getFixtures('push-transaction'); + +describe('push-transaction', () => { + const ws = new WebsocketClientE2e('ws://localhost:3005', true); + + for (const fixture of fixtures) { + test('PUSH_TRANSACTION', async () => { + await ws.waitForConnection(); + const receivingAddress = + 'addr_test1qq4wgdp3xw29d6ewuv9cvx83h9v0d5sy8lntd8vrdtrsfykwfnd2ewysca99vdwkvpp6a8w9nv5u4srvw5k0ywtl3v8qrl4qwp'; + const { transaction, txHash } = await buildTx('1000000', receivingAddress); + const resposne = await ws.sendAndWait('PUSH_TRANSACTION', { + txData: transaction.to_hex(), + }); + + expect(resposne.data).toMatchObject(txHash); + await ws.close(); + }); + } +}); diff --git a/test/e2e/tests/subscribe-block.e2e.test.ts b/test/e2e/tests/subscribe-block.e2e.test.ts index ebb9518..3517f6f 100644 --- a/test/e2e/tests/subscribe-block.e2e.test.ts +++ b/test/e2e/tests/subscribe-block.e2e.test.ts @@ -1,6 +1,10 @@ import { describe, test } from 'vitest'; -import fixtures from '../fixtures/mainnet/get-transaction.e2e'; import { WebsocketClientE2e } from '../utils/websocket-client-e2e'; +import { getFixtures } from '../utils/fixtures-loader'; +import { expect } from 'vitest'; +import { sleep } from '../utils/sleep'; + +const fixtures = await getFixtures('subscribe-block'); describe('subscribe-block', () => { const ws = new WebsocketClientE2e('ws://localhost:3005', true); @@ -9,15 +13,16 @@ describe('subscribe-block', () => { test(fixture.testName, async () => { await ws.waitForConnection(); - // ws.setSubscriptionCallback(message => { - // console.log('Received subscription message:', message); - // expect(message).toHaveProperty('type', 'update'); - // expect(message).toHaveProperty('data'); - // }); - // - // const response = await ws.sendAndWait('SUBSCRIBE_ADDRESS'); - // - // expect(response.data).toMatchObject(fixture.result); + ws.setSubscriptionCallback(message => { + //TODO + console.log('Received subscription message:', message); + }); + + const response = await ws.sendAndWait('SUBSCRIBE_BLOCK'); + expect(response.data).toMatchObject({ + 'subscribed': true, + }); + await sleep(15_000) await ws.close(); }); } diff --git a/test/e2e/tx-builder/index.ts b/test/e2e/tx-builder/index.ts index 1eb037d..21d9feb 100644 --- a/test/e2e/tx-builder/index.ts +++ b/test/e2e/tx-builder/index.ts @@ -48,11 +48,11 @@ export const buildTx = async (amountInLovelace: string, receivingAddress: string throw new Error(`You should send ADA to ${address} to have enough funds to sent a transaction`); } - const { txBody } = composeTransaction(address, receivingAddress, amountInLovelace, utxo, { + const { txBody, txHash } = composeTransaction(address, receivingAddress, amountInLovelace, utxo, { protocolParams: protocolParameters, }); const transaction = signTransaction(txBody, signKey); - return transaction; + return { transaction, txHash }; }; diff --git a/test/e2e/utils/fixtures-loader.ts b/test/e2e/utils/fixtures-loader.ts index fb8e308..abe118f 100644 --- a/test/e2e/utils/fixtures-loader.ts +++ b/test/e2e/utils/fixtures-loader.ts @@ -1,7 +1,7 @@ -export const getFixtures = async (testType: string) => { +export const getFixtures = async (fixtureTestName: string) => { try { const fixtures = await import( - `../fixtures/${process.env.BLOCKFROST_NETWORK}/${testType}.e2e.ts` + `../fixtures/${process.env.BLOCKFROST_NETWORK}/${fixtureTestName}.e2e.ts` ); return fixtures.default;