Skip to content

Commit f4de411

Browse files
committed
fix: data mappings test, refactor alchemy api key parameter passing, remove dotenv from sdk
1 parent db762de commit f4de411

File tree

11 files changed

+30
-24
lines changed

11 files changed

+30
-24
lines changed

kleros-sdk/.env.example

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

kleros-sdk/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
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.
65
To run the data mappings tests:
76

7+
1. Go into the `dataMappings.test.ts` file and pass the "alchemyApiKey" variable as second parameter when calling both the callAction() and eventAction() functions, at lines 89 and 119 of the file, respectively.
8+
2. At the root folder level, do:
9+
810
```bash
9-
yarn run test-data-mappings
11+
yarn test
1012
```
1113

1214
🚧 ⚖️ 🚧

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/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);

kleros-sdk/test/dataMappings.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("jsonAction", () => {
3333

3434
describe("subgraphAction with variables", () => {
3535
it("should fetch GraphQL data with variables and return in expected format", async () => {
36-
const endpoint = "https://api.thegraph.com/subgraphs/name/kemuru/escrow-v2-devnet";
36+
const endpoint = "https://api.studio.thegraph.com/query/61738/escrow-v2-devnet/version/latest";
3737
const query = `
3838
query GetEscrows($buyer: Bytes!) {
3939
escrows(where: {buyer: $buyer}) {
@@ -72,23 +72,28 @@ describe("subgraphAction with variables", () => {
7272

7373
describe("callAction", () => {
7474
it("should call the contract and return token balance", async () => {
75-
const abi = "function balanceOf(address account) public view returns (uint256)";
76-
const contractAddress = "0xa8e4235129258404A2ed3D36DAd20708CcB2d0b7";
77-
const knownAddress = "0x0000000000000000000000000000000000000000";
75+
const abi =
76+
"function currentRuling(uint256 _disputeID) public view returns (uint256 ruling, bool tied, bool overridden)";
77+
const contractAddress = "0xA54e7A16d7460e38a8F324eF46782FB520d58CE8";
78+
const disputeId = "0";
7879

7980
const mapping = {
8081
type: "abi/call",
8182
abi,
8283
address: contractAddress,
83-
args: [knownAddress],
84-
seek: [""],
85-
populate: ["tokenBalance"],
84+
args: [disputeId],
85+
seek: ["0", "1", "2"],
86+
populate: ["ruling", "tied", "overriden"],
8687
};
8788

88-
const result = await callAction(mapping);
89+
const result = await callAction(mapping, "insertAlchemyApiKeyHere");
8990

90-
expect(result).to.have.property("tokenBalance");
91-
expect(result.tokenBalance).to.be.a("bigint");
91+
expect(result).to.have.property("ruling");
92+
expect(result.ruling).to.be.a("bigint");
93+
expect(result).to.have.property("tied");
94+
expect(result.tied).to.be.a("boolean");
95+
expect(result).to.have.property("overriden");
96+
expect(result.overriden).to.be.a("boolean");
9297
});
9398
});
9499

@@ -111,7 +116,7 @@ describe("eventAction", () => {
111116
populate: ["fromAddress", "toAddress", "transferValue"],
112117
};
113118

114-
const result = await eventAction(mapping);
119+
const result = await eventAction(mapping, "insertAlchemyApiKeyHere");
115120

116121
expect(result).to.have.property("fromAddress");
117122
expect(result).to.have.property("toAddress");

web/src/hooks/queries/usePopulatedDisputeData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const usePopulatedDisputeData = (disputeID?: string, arbitrableAddress?:
6666
disputeID: disputeID,
6767
arbitrable: arbitrableAddress,
6868
graphApiKey: import.meta.env.REACT_APP_GRAPH_API_KEY,
69+
alchemyApiKey: import.meta.env.ALCHEMY_API_KEY,
6970
externalDisputeID: externalDisputeID,
7071
};
7172

web/src/pages/DisputeTemplateView/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const DisputeTemplateView = () => {
172172
externalDisputeID: debouncedParams._externalDisputeID,
173173
templateID: debouncedParams._templateId,
174174
templateUri: debouncedParams._templateUri,
175+
alchemyApiKey: import.meta.env.ALCHEMY_API_KEY,
175176
};
176177

177178
const fetchData = async () => {

0 commit comments

Comments
 (0)