Skip to content

Commit 08104eb

Browse files
authored
Merge pull request #1663 from kleros/fix(sdk)/data-mappings-tests
fix(sdk): mocked data mappings tests, refactor alchemy api key parameter passing
2 parents c68fbc2 + 4c17ea8 commit 08104eb

File tree

12 files changed

+303
-98
lines changed

12 files changed

+303
-98
lines changed

kleros-sdk/.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

kleros-sdk/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
_Archon's successor_
44

5-
Make sure to set the environment variables first by copying the file `.env.example`, pasting it, renaming it to `.env`, and then setting the variables.
6-
To run the data mappings tests:
5+
To run the data mappings tests, at the root folder level, do:
76

87
```bash
9-
yarn run test-data-mappings
8+
yarn test
109
```
1110

1211
🚧 ⚖️ 🚧

kleros-sdk/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"devDependencies": {
2828
"@types/mustache": "^4.2.5",
2929
"@vitest/ui": "^1.1.3",
30-
"dotenv": "^16.3.1",
3130
"mocha": "^10.2.0",
3231
"ts-node": "^10.9.2",
3332
"typescript": "^5.3.3",

kleros-sdk/src/dataMappings/actions/callAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
33
import { createResultObject } from "src/dataMappings/utils/createResultObject";
44
import { configureSDK, getPublicClient } from "src/sdk";
55

6-
export const callAction = async (mapping: AbiCallMapping) => {
7-
configureSDK({ apiKey: process.env.ALCHEMY_API_KEY });
6+
export const callAction = async (mapping: AbiCallMapping, alchemyApiKey: string) => {
7+
configureSDK({ apiKey: alchemyApiKey });
88
const publicClient = getPublicClient();
99

1010
const { abi: source, address, args, seek, populate } = mapping;

kleros-sdk/src/dataMappings/actions/eventAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
33
import { createResultObject } from "src/dataMappings/utils/createResultObject";
44
import { configureSDK, getPublicClient } from "src/sdk";
55

6-
export const eventAction = async (mapping: AbiEventMapping) => {
7-
configureSDK({ apiKey: process.env.ALCHEMY_API_KEY });
6+
export const eventAction = async (mapping: AbiEventMapping, alchemyApiKey: string) => {
7+
configureSDK({ apiKey: alchemyApiKey });
88
const publicClient = getPublicClient();
99

1010
const { abi: source, address, eventFilter, seek, populate } = mapping;

kleros-sdk/src/dataMappings/executeActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { ActionMapping } from "./utils/actionTypes";
1616
import { replacePlaceholdersWithValues } from "./utils/replacePlaceholdersWithValues";
1717

18-
export const executeAction = async (mapping: ActionMapping, context = {}) => {
18+
export const executeAction = async (mapping: ActionMapping, context: Record<string, unknown> = {}) => {
1919
mapping = replacePlaceholdersWithValues(mapping, context);
2020

2121
switch (mapping.type) {
@@ -24,9 +24,9 @@ export const executeAction = async (mapping: ActionMapping, context = {}) => {
2424
case "json":
2525
return jsonAction(validateJsonMapping(mapping));
2626
case "abi/call":
27-
return await callAction(validateAbiCallMapping(mapping));
27+
return await callAction(validateAbiCallMapping(mapping), context.alchemyApiKey);
2828
case "abi/event":
29-
return await eventAction(validateAbiEventMapping(mapping));
29+
return await eventAction(validateAbiEventMapping(mapping), context.alchemyApiKey);
3030
case "fetch/ipfs/json":
3131
return await fetchIpfsJsonAction(validateFetchIpfsJsonMapping(mapping));
3232
case "reality":

kleros-sdk/src/dataMappings/utils/actionTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export type JsonMapping = {
55
populate: string[];
66
};
77

8-
export type SubgraphMapping = {
8+
export interface SubgraphMapping {
99
type: string;
1010
endpoint: string;
1111
query: string;
12-
variables?: string[];
12+
variables: { [key: string]: unknown };
1313
seek: string[];
1414
populate: string[];
15-
};
15+
}
1616

1717
export type AbiCallMapping = {
1818
type: string;

kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mustache from "mustache";
22

3-
export const replacePlaceholdersWithValues = (mapping: any, context: any) => {
3+
export const replacePlaceholdersWithValues = (mapping: any, context: Record<string, unknown>) => {
44
const replace = (obj) => {
55
if (typeof obj === "string") {
66
return mustache.render(obj, context);

0 commit comments

Comments
 (0)