Skip to content

Commit

Permalink
test: increase coverage of test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bslabiak committed Oct 31, 2024
1 parent 5455536 commit e922594
Show file tree
Hide file tree
Showing 21 changed files with 273 additions and 42 deletions.
8 changes: 8 additions & 0 deletions test/e2e/fixtures/mainnet/estimate-fee.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
{
testName: 'ESTIMATE_FEE success - mainnet',
result: {
lovelacePerByte: 44,
},
},
] as const;
33 changes: 33 additions & 0 deletions test/e2e/fixtures/mainnet/get-account-info.e2e.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions test/e2e/fixtures/mainnet/get-transaction.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default [
{
testName: 'GET_TRANSACTION success - mainnet',
txID: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33',
result: {
hash: '28172ea876c3d1e691284e5179fae2feb3e69d7d41e43f8023dc380115741026',
block: 'e6369fee087d31192016b1659f1c381e9fc4925339278a4eef6f340c96c1947f',
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/fixtures/mainnet/subscribe-block.e2e.ts
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions test/e2e/fixtures/preprod/estimate-fee.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
{
testName: 'ESTIMATE-fee success - preprod',
result: {
lovelacePerByte: 44,
},
},
] as const;
33 changes: 33 additions & 0 deletions test/e2e/fixtures/preprod/get-account-info.e2e.ts
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions test/e2e/fixtures/preprod/get-account-utxo.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default [
{
testName: 'GET_ACCOUNT_UTXO success - preprod',
descriptor: '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2',
result: [],
}//TODO more examples
] as const;
26 changes: 26 additions & 0 deletions test/e2e/fixtures/preprod/get-block.e2e.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions test/e2e/fixtures/preprod/get-transaction.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default [
{
testName: 'GET_TRANSACTION success - mainnet',
txID: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33',
result: {
hash: 'ed7e75df5a1d4925cc642ba6360d0dd031bfff54d0314757cfcbf2448a5e8c33',
block: 'c053f4bfbf7338b0c11a9a56302a4b51de9591f3366984660e9c9220009ad79f',
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/fixtures/preprod/push-transaction.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default [
{
testName: 'PUSH_TRANSACTION success - preprod',
},
] as const;
8 changes: 8 additions & 0 deletions test/e2e/fixtures/preprod/subscribe-block.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
{
testName: 'GET_SERVER success - preprod',
result: {
"subscribed": true,
},
},
] as const;
18 changes: 18 additions & 0 deletions test/e2e/tests/estimate-fee.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
});
24 changes: 24 additions & 0 deletions test/e2e/tests/get-account-info.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
});
21 changes: 21 additions & 0 deletions test/e2e/tests/get-account-utxo.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
});
18 changes: 18 additions & 0 deletions test/e2e/tests/get-block.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
});
2 changes: 1 addition & 1 deletion test/e2e/tests/get-tansaction.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 0 additions & 27 deletions test/e2e/tests/push-transaction-e2e.test.ts

This file was deleted.

26 changes: 26 additions & 0 deletions test/e2e/tests/push-transaction.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
});
25 changes: 15 additions & 10 deletions test/e2e/tests/subscribe-block.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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();
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/tx-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
4 changes: 2 additions & 2 deletions test/e2e/utils/fixtures-loader.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit e922594

Please sign in to comment.