Skip to content

Commit e93a1cd

Browse files
authored
Merge pull request #255 from hack-a-chain-software/tests-refactor-2
Tests refactor 2
2 parents 7491620 + a8dda70 commit e93a1cd

File tree

56 files changed

+14013
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+14013
-7
lines changed

indexer/src/kadena-server/repository/application/transaction-repository.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface GetTransactionsByPublicKeyParams extends PaginationsParams {
88
publicKey: string;
99
}
1010

11+
export interface GetSignersParams {
12+
transactionId?: string;
13+
requestKey?: string;
14+
orderIndex?: string;
15+
}
16+
1117
export interface GetTransactionsCountParams {
1218
blockHash?: string | null;
1319
accountName?: string | null;
@@ -48,5 +54,5 @@ export default interface TransactionRepository {
4854
}>;
4955
getTransactionsByPublicKeyCount(publicKey: string): Promise<number>;
5056
getTransactionsByEventIds(eventIds: string[]): Promise<TransactionOutput[]>;
51-
getSigners(transactionId: string, orderIndex?: number): Promise<SignerOutput[]>;
57+
getSigners(params: GetSignersParams): Promise<SignerOutput[]>;
5258
}

indexer/src/kadena-server/repository/infra/repository/transaction-db-repository.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { rootPgPool } from '../../../../config/database';
22
import TransactionRepository, {
3+
GetSignersParams,
34
GetTransactionsByPublicKeyParams,
45
GetTransactionsByRequestKey,
56
GetTransactionsCountParams,
@@ -626,8 +627,9 @@ export default class TransactionDbRepository implements TransactionRepository {
626627
return eventIds.map(eventId => transactionMap[eventId]) as TransactionOutput[];
627628
}
628629

629-
async getSigners(transactionId: string, orderIndex?: number) {
630-
const queryParams: Array<string | number> = [transactionId];
630+
async getSigners(params: GetSignersParams) {
631+
const { transactionId, requestKey, orderIndex } = params;
632+
const queryParams: Array<string | number> = [];
631633
let query = `
632634
SELECT s.pubkey as "publicKey",
633635
s.address as "address",
@@ -636,12 +638,21 @@ export default class TransactionDbRepository implements TransactionRepository {
636638
t.requestkey as "requestKey"
637639
FROM "Signers" s
638640
JOIN "Transactions" t on s."transactionId" = t.id
639-
WHERE t.id = $1
640641
`;
641642

643+
if (transactionId) {
644+
queryParams.push(transactionId);
645+
query += `\nWHERE t.id = $1`;
646+
}
647+
648+
if (requestKey) {
649+
queryParams.push(requestKey);
650+
query += `\nWHERE t.requestkey = $1`;
651+
}
652+
642653
if (orderIndex) {
643-
query += `\nAND s."orderIndex" = $2`;
644654
queryParams.push(orderIndex);
655+
query += `\nAND s."orderIndex" = $2`;
645656
}
646657

647658
const { rows } = await rootPgPool.query(query, queryParams);

indexer/src/kadena-server/resolvers/fields/transaction-command/signers-transaction-command-resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const signersTransactionCommandResolver: TransactionCommandResolvers<Reso
88
async (parent, _args, context) => {
99
const parentArgs = schema.parse(parent);
1010

11-
const output = await context.transactionRepository.getSigners(parentArgs.databaseTransactionId);
11+
const output = await context.transactionRepository.getSigners({
12+
transactionId: parentArgs.databaseTransactionId,
13+
});
1214
return output;
1315
};

indexer/src/kadena-server/resolvers/node-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const getNode = async (context: ResolverContext, id: string) => {
7676

7777
if (type === 'Signer') {
7878
const [requestKey, orderIndex] = JSON.parse(params);
79-
const [output] = await context.transactionRepository.getSigners(requestKey, orderIndex);
79+
const [output] = await context.transactionRepository.getSigners({ requestKey, orderIndex });
8080
return output;
8181
}
8282

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { GraphQLClient } from 'graphql-request';
2+
import { getBlocksFromDepthQuery } from './builders/blocks-from-depth.builder';
3+
import { blocksFromDepthFixture001 } from './fixtures/blocks-from-depth/blocks-from-depth.fixture.001';
4+
import { blocksFromDepthFixture002 } from './fixtures/blocks-from-depth/blocks-from-depth.fixture.002';
5+
const client = new GraphQLClient(process.env.API_URL ?? 'http://localhost:3001/graphql');
6+
7+
describe('Blocks from depth', () => {
8+
it.skip('#001', async () => {
9+
const query = getBlocksFromDepthQuery({ minimumDepth: 10, after: 'OTE1OTgwMzY=' });
10+
const data = await client.request(query);
11+
expect(blocksFromDepthFixture001.data).toMatchObject(data);
12+
});
13+
14+
it.skip('#002', async () => {
15+
const query = getBlocksFromDepthQuery({
16+
minimumDepth: 10,
17+
chainIds: ['8', '9'],
18+
after: 'OTE1OTgwMzY=',
19+
});
20+
const data = await client.request(query);
21+
expect(blocksFromDepthFixture002.data).toMatchObject(data);
22+
});
23+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { GraphQLClient } from 'graphql-request';
2+
import { getBlocksFromHeightQuery } from './builders/blocks-from-height.builder';
3+
import { blocksFromHeightFixture001 } from './fixtures/blocks-from-height/blocks-from-height.fixture.001';
4+
import { blocksFromHeightFixture002 } from './fixtures/blocks-from-height/blocks-from-height.fixture.002';
5+
import { blocksFromHeightFixture003 } from './fixtures/blocks-from-height/blocks-from-height.fixture.003';
6+
import { blocksFromHeightFixture004 } from './fixtures/blocks-from-height/blocks-from-height.fixture.004';
7+
const client = new GraphQLClient(process.env.API_URL ?? 'http://localhost:3001/graphql');
8+
9+
describe('Blocks from height', () => {
10+
it('#001', async () => {
11+
const query = getBlocksFromHeightQuery({ startHeight: 3000000, endHeight: 5000000 });
12+
const data = await client.request(query);
13+
expect(blocksFromHeightFixture001.data).toMatchObject(data);
14+
});
15+
16+
it('#002', async () => {
17+
const query = getBlocksFromHeightQuery({
18+
startHeight: 3000000,
19+
endHeight: 5000000,
20+
chainIds: ['8'],
21+
});
22+
const data = await client.request(query);
23+
expect(blocksFromHeightFixture002.data).toMatchObject(data);
24+
});
25+
26+
//
27+
it('#003', async () => {
28+
const query = getBlocksFromHeightQuery({
29+
startHeight: 2000000,
30+
endHeight: 4000000,
31+
after: 'OTE1OTgwMzE=',
32+
});
33+
const data = await client.request(query);
34+
expect(blocksFromHeightFixture003.data).toMatchObject(data);
35+
});
36+
37+
it('#004', async () => {
38+
const query = getBlocksFromHeightQuery({
39+
startHeight: 2000000,
40+
endHeight: 4000000,
41+
last: 5,
42+
});
43+
const data = await client.request(query);
44+
expect(blocksFromHeightFixture004.data).toMatchObject(data);
45+
});
46+
47+
it.skip('#005', async () => {
48+
const query = getBlocksFromHeightQuery({
49+
startHeight: 2000000,
50+
endHeight: 4000000,
51+
chainIds: ['8'],
52+
after: 'OTE1OTgwMzE=',
53+
});
54+
const data = await client.request(query);
55+
expect(null).toMatchObject(data);
56+
});
57+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { gql } from 'graphql-request';
2+
3+
export const getBlocksFromDepthQuery = (params: any): string => {
4+
if (Object.keys(params).length === 0) {
5+
throw new Error('No parameters provided to getBlocksFromDepthQuery.');
6+
}
7+
8+
const query = Object.entries(params)
9+
.map(([key, value]) => {
10+
if (Array.isArray(value)) {
11+
return `${key}: [${value.map(v => `"${v}"`).join(', ')}]`;
12+
}
13+
return `${key}: ${typeof value === 'string' ? `"${value}"` : value}`;
14+
})
15+
.join(', ');
16+
17+
const queryGql = gql`
18+
query {
19+
blocksFromDepth(${query}) {
20+
edges {
21+
cursor
22+
node {
23+
chainId
24+
creationTime
25+
difficulty
26+
epoch
27+
events {
28+
totalCount
29+
pageInfo {
30+
endCursor
31+
hasNextPage
32+
hasPreviousPage
33+
startCursor
34+
}
35+
edges {
36+
cursor
37+
node {
38+
chainId
39+
height
40+
id
41+
moduleName
42+
name
43+
orderIndex
44+
parameters
45+
parameterText
46+
qualifiedName
47+
requestKey
48+
}
49+
}
50+
}
51+
flags
52+
hash
53+
height
54+
id
55+
minerAccount {
56+
accountName
57+
balance
58+
chainId
59+
fungibleName
60+
guard {
61+
... on KeysetGuard {
62+
keys
63+
predicate
64+
raw
65+
}
66+
}
67+
id
68+
}
69+
neighbors {
70+
chainId
71+
hash
72+
}
73+
nonce
74+
parent {
75+
chainId
76+
}
77+
payloadHash
78+
powHash
79+
target
80+
transactions {
81+
totalCount
82+
pageInfo {
83+
endCursor
84+
hasNextPage
85+
hasPreviousPage
86+
startCursor
87+
}
88+
edges {
89+
cursor
90+
node {
91+
id
92+
}
93+
}
94+
}
95+
weight
96+
}
97+
}
98+
}
99+
}
100+
`;
101+
102+
return queryGql;
103+
};
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { gql } from 'graphql-request';
2+
3+
export const getBlocksFromHeightQuery = (params: any): string => {
4+
if (Object.keys(params).length === 0) {
5+
throw new Error('No parameters provided to getBlocksFromHeightQuery.');
6+
}
7+
8+
const query = Object.entries(params)
9+
.map(([key, value]) => {
10+
if (Array.isArray(value)) {
11+
return `${key}: [${value.map(v => `"${v}"`).join(', ')}]`;
12+
}
13+
return `${key}: ${typeof value === 'string' ? `"${value}"` : value}`;
14+
})
15+
.join(', ');
16+
17+
const queryGql = gql`
18+
query {
19+
blocksFromHeight(${query}) {
20+
edges {
21+
cursor
22+
node {
23+
chainId
24+
creationTime
25+
difficulty
26+
epoch
27+
events {
28+
totalCount
29+
pageInfo {
30+
endCursor
31+
hasNextPage
32+
hasPreviousPage
33+
startCursor
34+
}
35+
edges {
36+
cursor
37+
node {
38+
chainId
39+
height
40+
id
41+
moduleName
42+
name
43+
orderIndex
44+
parameters
45+
parameterText
46+
qualifiedName
47+
requestKey
48+
}
49+
}
50+
}
51+
flags
52+
hash
53+
height
54+
id
55+
minerAccount {
56+
accountName
57+
balance
58+
chainId
59+
fungibleName
60+
guard {
61+
... on KeysetGuard {
62+
keys
63+
predicate
64+
raw
65+
}
66+
}
67+
id
68+
}
69+
neighbors {
70+
chainId
71+
hash
72+
}
73+
nonce
74+
parent {
75+
chainId
76+
}
77+
payloadHash
78+
powHash
79+
target
80+
transactions {
81+
totalCount
82+
pageInfo {
83+
endCursor
84+
hasNextPage
85+
hasPreviousPage
86+
startCursor
87+
}
88+
edges {
89+
cursor
90+
node {
91+
id
92+
}
93+
}
94+
}
95+
weight
96+
}
97+
}
98+
}
99+
}
100+
`;
101+
102+
return queryGql;
103+
};

0 commit comments

Comments
 (0)