Skip to content

Commit 25063c7

Browse files
committed
chore: fixed the SDK tests, minor tweaks
1 parent d2c8f9c commit 25063c7

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

kleros-sdk/test/dataMappings.test.ts

+42-8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ describe("full flow test", () => {
174174
{ title: "Yes", description: "User is responsible", id: "0x01" },
175175
{ title: "No", description: "User is not responsible", id: "0x02" },
176176
],
177+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
177178
details: {
178179
ruling: "{{ruling}}",
179180
tied: "{{tied}}",
@@ -182,6 +183,9 @@ describe("full flow test", () => {
182183
toAddress: "{{toAddress}}",
183184
transferValue: "{{transferValue}}",
184185
},
186+
arbitratorChainID: "421613",
187+
arbitratorAddress: "0x0987654321098765432109876543210987654321",
188+
version: "1.0",
185189
});
186190

187191
const initialContext = { alchemyApiKey: "mocked_api_key" };
@@ -199,6 +203,7 @@ describe("full flow test", () => {
199203
{ title: "Yes", description: "User is responsible", id: "0x01" },
200204
{ title: "No", description: "User is not responsible", id: "0x02" },
201205
],
206+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
202207
details: {
203208
ruling: "1",
204209
tied: "false",
@@ -207,6 +212,9 @@ describe("full flow test", () => {
207212
toAddress: "0x0987654321098765432109876543210987654321",
208213
transferValue: "100",
209214
},
215+
arbitratorChainID: "421613",
216+
arbitratorAddress: "0x0987654321098765432109876543210987654321",
217+
version: "1.0",
210218
});
211219
});
212220
});
@@ -345,10 +353,7 @@ describe("populateTemplate", () => {
345353
reserved: false,
346354
},
347355
],
348-
policyURI: "https://example.com/policy",
349-
frontendUrl: "https://example.com",
350-
arbitrableChainID: "100",
351-
arbitrableAddress: "0x1234567890123456789012345678901234567890",
356+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
352357
arbitratorChainID: "421613",
353358
arbitratorAddress: "0x0987654321098765432109876543210987654321",
354359
category: "General",
@@ -376,10 +381,7 @@ describe("populateTemplate", () => {
376381
reserved: false,
377382
},
378383
],
379-
policyURI: "https://example.com/policy",
380-
frontendUrl: "https://example.com",
381-
arbitrableChainID: "100",
382-
arbitrableAddress: "0x1234567890123456789012345678901234567890",
384+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
383385
arbitratorChainID: "421613",
384386
arbitratorAddress: "0x0987654321098765432109876543210987654321",
385387
category: "General",
@@ -394,6 +396,22 @@ describe("populateTemplate", () => {
394396
title: "Test Title",
395397
description: "Test Description",
396398
question: "{{missingQuestion}}",
399+
type: "single-select",
400+
answers: [
401+
{
402+
title: "Yes",
403+
description: "Affirmative",
404+
id: "0x01",
405+
reserved: false,
406+
},
407+
],
408+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
409+
arbitratorChainID: "421613",
410+
arbitratorAddress: "0x0987654321098765432109876543210987654321",
411+
category: "General",
412+
lang: "en_US",
413+
specification: "Spec",
414+
version: "1.0",
397415
});
398416

399417
const data = {
@@ -406,6 +424,22 @@ describe("populateTemplate", () => {
406424
title: "Test Title",
407425
description: "Test Description",
408426
question: "",
427+
type: "single-select",
428+
answers: [
429+
{
430+
title: "Yes",
431+
description: "Affirmative",
432+
id: "0x01",
433+
reserved: false,
434+
},
435+
],
436+
policyURI: "/ipfs/QmUnPyGi31RoF4DRR8vT3u13YsppxtsbBKbdQAbcP8be4M/file.json",
437+
arbitratorChainID: "421613",
438+
arbitratorAddress: "0x0987654321098765432109876543210987654321",
439+
category: "General",
440+
lang: "en_US",
441+
specification: "Spec",
442+
version: "1.0",
409443
});
410444
});
411445

subgraph/core/src/entities/Dispute.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,24 @@ export function createDisputeFromEvent(event: DisputeCreation): void {
3232
updateDisputeRequestData(event);
3333
}
3434

35+
// source: contracts/src/arbitration/interfaces/IArbitrableV2.sol
3536
const DisputeRequest = "DisputeRequest(address,uint256,uint256,uint256,string)";
36-
3737
const DisputeRequestSignature = crypto.keccak256(ByteArray.fromUTF8(DisputeRequest));
3838

3939
// note : we are using bytes32 in place of string as strings cannot be decoded and it breaks the function.
40-
// It is okay for us, as we are interested in the uint256 in front
41-
// _externalDisputeId,_templateId,_tenplateUri
42-
const DisputeRequestTypestring = "(uint256,uint256,bytes32)";
40+
// It is okay for us, as we are only interested in the uint256 in frontend.
41+
const DisputeRequestTypestring = "(uint256,uint256,bytes32)"; // _externalDisputeId,_templateId,_templateUri
4342

43+
// source: contracts/src/gateway/interfaces/IHomeGateway.sol
4444
const CrossChainDisputeIncoming =
4545
"CrossChainDisputeIncoming(address,uint256,address,uint256,uint256,uint256,uint256,string)";
46-
4746
const CrossChainDisputeIncomingSignature = crypto.keccak256(ByteArray.fromUTF8(CrossChainDisputeIncoming));
4847

49-
// arbitrator, _arbitrableChainId, _externalDisputeId, _templateId, _templateUri
5048
// note : arbitrable is an indexed arg, so it will topic[1]
51-
const CrossChainDisputeIncomingTypestring = "(address,uint256,uint256,uint256,string)";
49+
const CrossChainDisputeIncomingTypestring = "(address,uint256,uint256,uint256,string)"; // arbitrator, _arbitrableChainId, _externalDisputeId, _templateId, _templateUri
5250

5351
export const updateDisputeRequestData = (event: DisputeCreation): void => {
5452
const dispute = Dispute.load(event.params._disputeID.toString());
55-
5653
if (!dispute) return;
5754

5855
const receipt = event.receipt;
@@ -62,16 +59,13 @@ export const updateDisputeRequestData = (event: DisputeCreation): void => {
6259

6360
// note that the topic at 0th index is always the event signature
6461
const disputeRequestEventIndex = logs.findIndex((log) => log.topics[0] == DisputeRequestSignature);
65-
6662
const crossChainDisputeEventIndex = logs.findIndex((log) => log.topics[0] == CrossChainDisputeIncomingSignature);
6763

6864
if (crossChainDisputeEventIndex !== -1) {
6965
const crossChainDisputeEvent = logs[crossChainDisputeEventIndex];
7066

7167
const decoded = ethereum.decode(CrossChainDisputeIncomingTypestring, crossChainDisputeEvent.data);
72-
7368
if (!decoded) return;
74-
7569
dispute.isCrossChain = true;
7670
dispute.arbitrableChainId = decoded.toTuple()[1].toBigInt();
7771
dispute.externalDisputeId = decoded.toTuple()[2].toBigInt();
@@ -84,16 +78,17 @@ export const updateDisputeRequestData = (event: DisputeCreation): void => {
8478
const decoded = ethereum.decode(DisputeRequestTypestring, disputeRequestEvent.data);
8579
if (!decoded) return;
8680
dispute.isCrossChain = false;
87-
dispute.arbitrableChainId = getChainId(dataSource.network());
81+
dispute.arbitrableChainId = getHomeChainId(dataSource.network());
8882
dispute.externalDisputeId = decoded.toTuple()[0].toBigInt();
8983
dispute.templateId = decoded.toTuple()[1].toBigInt();
9084
dispute.save();
9185
return;
9286
}
9387
};
9488

95-
// workaround, since hashmap don't work in subgraphs
96-
function getChainId(name: string): BigInt {
89+
// workaround, since hashmap don't work in subgraphs.
90+
// https://thegraph.com/docs/en/developing/supported-networks/
91+
function getHomeChainId(name: string): BigInt {
9792
if (name == "arbitrum-one") return BigInt.fromI32(42161);
9893
else if (name == "arbitrum-sepolia") return BigInt.fromI32(421614);
9994
else return BigInt.fromI32(1);

web/src/context/Web3Provider.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ export const getDefaultChainRpcUrl = (protocol: AlchemyProtocol) => {
3838
return getChainRpcUrl(protocol, DEFAULT_CHAIN);
3939
};
4040

41-
const alchemyTransport = (chain: Chain) =>
42-
fallback([http(alchemyURL("https", chain.id)), webSocket(alchemyURL("wss", chain.id))]);
43-
4441
export const getTransports = () => {
42+
const alchemyTransport = (chain: Chain) =>
43+
fallback([http(alchemyURL("https", chain.id)), webSocket(alchemyURL("wss", chain.id))]);
4544
const defaultTransport = (chain: Chain) =>
4645
fallback([http(chain.rpcUrls.default?.http?.[0]), webSocket(chain.rpcUrls.default?.webSocket?.[0])]);
4746

@@ -68,7 +67,7 @@ const wagmiConfig = createConfig({
6867
configureSDK({
6968
client: {
7069
chain: isProduction ? arbitrum : arbitrumSepolia,
71-
transport: isProduction ? alchemyTransport(arbitrum) : alchemyTransport(arbitrumSepolia),
70+
transport: transports[isProduction ? arbitrum.id : arbitrumSepolia.id],
7271
},
7372
});
7473

0 commit comments

Comments
 (0)