Skip to content

Commit

Permalink
fixup! Add required signers
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 18, 2023
1 parent 3a0463e commit 43a958b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/routes/txs/hash/required-signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import { getDbSync } from '../../../utils/database.js';

async function route(fastify: FastifyInstance) {
fastify.route({
url: '/txs/:hash/required-signers',
url: '/txs/:hash/required_signers',
method: 'GET',
schema: getSchemaForEndpoint('/txs/:hash:/required-signers'),
schema: getSchemaForEndpoint('/txs/:hash:/required_signers'),
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => {
const clientDbSync = await getDbSync(fastify);

try {
const { rows } =
await clientDbSync.query<QueryTypes.TxWits>(
SQLQuery.get('txs_hash_wits'),
[request.params.hash],
);
const { rows } = await clientDbSync.query<QueryTypes.TxWits>(
SQLQuery.get('txs_hash_wits'),
[request.params.hash],
);

clientDbSync.release();

Expand All @@ -34,6 +33,7 @@ async function route(fastify: FastifyInstance) {
}

const unpaged = isUnpaged(request);

if (unpaged) {
// Use of Reply.raw functions is at your own risk as you are skipping all the Fastify logic of handling the HTTP response
// https://www.fastify.io/docs/latest/Reference/Reply/#raw
Expand Down
52 changes: 52 additions & 0 deletions test/unit/fixtures/txs.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,20 @@ const response_txs_redeemers = [
},
];

const query_txs_required_signers = [
{ hash: 'd52e11f3e48436dd42dbec6d88c239732e503b8b7a32af58e5f87625' },
{ hash: '41b32682c413535dbca5178f92f3cee5dede31b995400b8c371e2469' },
{ hash: 'd52e11f3e48436dd42dbec6d88c239732e503b8b7a32af58e5f87625' },
{ hash: '666414964a05b01cef36427b8a0fb0f621806c43e66e7a4d3cca3bfb' },
];

const response_txs_required_signers = [
'd52e11f3e48436dd42dbec6d88c239732e503b8b7a32af58e5f87625',
'41b32682c413535dbca5178f92f3cee5dede31b995400b8c371e2469',
'd52e11f3e48436dd42dbec6d88c239732e503b8b7a32af58e5f87625',
'666414964a05b01cef36427b8a0fb0f621806c43e66e7a4d3cca3bfb',
];

const response_404 = {
error: 'Not Found',
message: 'The requested component has not been found.',
Expand Down Expand Up @@ -1542,6 +1556,28 @@ export default [
},
response: [],
},
{
name: 'respond with success and data on /txs/:hash/required_signers',
endpoint: '/txs/6e6644e0f8aeec3437bec536408fc007a6147d94098f2dbaeb6ad80d0508631b/required_signers',
sqlQueryMock: {
rows: query_found,
},
sqlQueryMock2: {
rows: query_txs_required_signers,
},
response: response_txs_required_signers,
},
{
name: 'respond with success and data on /txs/:hash/required_signers',
endpoint: '/txs/6e6644e0f8aeec3437bec536408fc007a6147d94098f2dbaeb6ad80d0508631b/required_signers',
sqlQueryMock: {
rows: query_found,
},
sqlQueryMock2: {
rows: [],
},
response: [],
},
/*
404s
*/
Expand Down Expand Up @@ -1637,6 +1673,14 @@ export default [
},
response: response_404,
},
{
name: 'respond with 404 and empty data on /txs/:hash/required_signers',
endpoint: '/txs/stonks_tx/required_signers',
sqlQueryMock: {
rows: [],
},
response: response_404,
},

/*
500s
Expand Down Expand Up @@ -1778,4 +1822,12 @@ export default [
},
response: response_500,
},
{
name: 'respond with 500 and null on /txs/:hash/required_signers',
endpoint: '/txs/stonks_tx/required_signers',
sqlQueryMock: {
rows: null,
},
response: response_500,
},
]; //as const;

0 comments on commit 43a958b

Please sign in to comment.