Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ generated/

.env

subgraph.yaml
subgraph.yaml

# tests
.docker
.latest.json
.bin
2 changes: 2 additions & 0 deletions matchstick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testsFolder: ./tests
manifestPath: ./subgraph.yaml
20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gtcr-subgraph",
"version": "1.1.4",
"version": "1.1.8",
"description": "Subgraph for Generalized TCR contracts",
"scripts": {
"clean": "graph clean",
Expand All @@ -23,7 +23,8 @@
"lint:eslint": "eslint . --ext .ts,.tsx",
"lint:prettier": "prettier --config .prettierrc 'src/**/*.ts' --check",
"lint": "yarn lint:eslint && yarn lint:prettier && yarn lint:secrets",
"format": "prettier --config .prettierrc 'src/**/*.ts' --write && eslint . --ext .ts,.tsx --fix"
"format": "prettier --config .prettierrc 'src/**/*.ts' --write && eslint . --ext .ts,.tsx --fix",
"test": "graph test"
},
"repository": {
"type": "git",
Expand All @@ -39,33 +40,22 @@
"@graphprotocol/graph-ts": "^0.35.1"
},
"devDependencies": {
"@assemblyscript/loader": "^0.14.11",
"@assemblyscript/node": "github:AssemblyScript/node",
"@gnosis.pm/truffle-nice-tools": "^1.3.1",
"@goldskycom/cli": "^11.3.0",
"@graphprotocol/graph-cli": "^0.71.0",
"@kleros/erc-792": "3.0.0",
"@kleros/gtcr-encoder": "^1.1.3",
"@kleros/tcr": "^2.0.0",
"@truffle/contract": "^4.2.22",
"@truffle/hdwallet-provider": "^1.1.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"assemblyscript": "^0.14.11",
"delay": "^4.4.0",
"dotenv-safe": "^8.2.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"ethers": "^5.0.14",
"fs-extra": "^9.0.1",
"matchstick-as": "^0.6.0",
"mocha": "^8.1.3",
"mocha-steps": "^1.3.0",
"mustache": "^4.0.1",
"replace-in-file": "^6.1.0",
"should": "^13.2.3",
"typescript": "^4.3.5",
"wait-on": "^5.2.0"
"typescript": "^4.3.5"
},
"resolutions": {
"ejs": "^3.1.10"
Expand Down
16 changes: 8 additions & 8 deletions src/LightGTCRFactoryMapping.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable prefer-const */
import { BigInt } from '@graphprotocol/graph-ts';
import { NewGTCR } from '../generated/LightGTCRFactory/LightGTCRFactory';
import { MetaEvidence, LRegistry } from '../generated/schema';
import { LightGeneralizedTCR as LightGeneralizedTCRDataSource } from '../generated/templates';
import { ZERO } from './utils';

export function handleNewGTCR(event: NewGTCR): void {
LightGeneralizedTCRDataSource.create(event.params._address);
Expand All @@ -17,14 +17,14 @@ export function handleNewGTCR(event: NewGTCR): void {
clearingMetaEvidence.URI = '';
clearingMetaEvidence.save();

registry.metaEvidenceCount = BigInt.fromI32(0);
registry.metaEvidenceCount = ZERO;
registry.registrationMetaEvidence = registrationMetaEvidence.id;
registry.clearingMetaEvidence = clearingMetaEvidence.id;
registry.numberOfAbsent = BigInt.fromI32(0);
registry.numberOfRegistered = BigInt.fromI32(0);
registry.numberOfRegistrationRequested = BigInt.fromI32(0);
registry.numberOfClearingRequested = BigInt.fromI32(0);
registry.numberOfChallengedRegistrations = BigInt.fromI32(0);
registry.numberOfChallengedClearing = BigInt.fromI32(0);
registry.numberOfAbsent = ZERO;
registry.numberOfRegistered = ZERO;
registry.numberOfRegistrationRequested = ZERO;
registry.numberOfClearingRequested = ZERO;
registry.numberOfChallengedRegistrations = ZERO;
registry.numberOfChallengedClearing = ZERO;
registry.save();
}
47 changes: 38 additions & 9 deletions src/LightGeneralizedTCRMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ export function handleNewItem(event: NewItem): void {
const ipfsHash = extractPath(event.params._data);
item.metadata = `${ipfsHash}-${graphItemID}`;

log.debug('Creating datasource for ipfs hash : {}', [ipfsHash]);
log.debug('Creating datasource for ipfs hash : {}, graphItemID: {}', [
ipfsHash,
graphItemID,
]);

const context = new DataSourceContext();
context.setString('graphItemID', graphItemID);
Expand Down Expand Up @@ -301,15 +304,24 @@ export function handleRequestSubmitted(event: RequestSubmitted): void {
let newStatus = getExtendedStatus(item.disputed, item.status);

let requestIndex = item.numberOfRequests.minus(BigInt.fromI32(1));
let requestInfo = tcr.getRequestInfo(event.params._itemID, requestIndex);
let requestInfo = tcr.try_getRequestInfo(event.params._itemID, requestIndex);
if (requestInfo.reverted) {
log.error(
`getRequestInfo reverted for LItem : {}, requestIndex : {}`,
[graphItemID, requestIndex.toString()],
);
item.save();
return;
}

let requestID = graphItemID + '-' + requestIndex.toString();

let request = new LRequest(requestID);
request.disputed = false;
request.arbitrator = tcr.arbitrator();
request.arbitratorExtraData = tcr.arbitratorExtraData();
request.challenger = ZERO_ADDRESS;
request.requester = requestInfo.value4[1];
request.requester = requestInfo.value.value4[1];
request.item = item.id;
request.registry = registry.id;
request.registryAddress = event.address;
Expand Down Expand Up @@ -450,7 +462,16 @@ export function handleRequestChallenged(event: Dispute): void {
let newStatus = getExtendedStatus(item.disputed, item.status);

let requestIndex = item.numberOfRequests.minus(BigInt.fromI32(1));
let requestInfo = tcr.getRequestInfo(itemID, requestIndex);
let requestInfo = tcr.try_getRequestInfo(itemID, requestIndex);
if (requestInfo.reverted) {
log.error(
`Failed to fetch request info for LItem : {}, requestIndex : {}`,
[graphItemID, requestIndex.toString()],
);
item.save();
return;
}

let requestID = graphItemID + '-' + requestIndex.toString();
let request = LRequest.load(requestID);
if (!request) {
Expand All @@ -459,7 +480,7 @@ export function handleRequestChallenged(event: Dispute): void {
}

request.disputed = true;
request.challenger = requestInfo.value4[2];
request.challenger = requestInfo.value.value4[2];
request.numberOfRounds = BigInt.fromI32(2);
request.disputeID = event.params._disputeID;

Expand Down Expand Up @@ -638,7 +659,15 @@ export function handleStatusUpdated(event: ItemStatusChange): void {
item.latestRequestResolutionTime = event.block.timestamp;

let requestIndex = item.numberOfRequests.minus(BigInt.fromI32(1));
let requestInfo = tcr.getRequestInfo(event.params._itemID, requestIndex);
let requestInfo = tcr.try_getRequestInfo(event.params._itemID, requestIndex);
if (requestInfo.reverted) {
log.error(
`Failed to fetch request info for LItem : {}, requestIndex : {}`,
[graphItemID, requestIndex.toString()],
);
item.save();
return;
}

let requestID = graphItemID + '-' + requestIndex.toString();
let request = LRequest.load(requestID);
Expand All @@ -651,7 +680,7 @@ export function handleStatusUpdated(event: ItemStatusChange): void {
request.resolutionTime = event.block.timestamp;
request.resolutionTx = event.transaction.hash;
// requestInfo.value6 is request.ruling.
request.disputeOutcome = getFinalRuling(requestInfo.value6);
request.disputeOutcome = getFinalRuling(requestInfo.value.value6);

// Iterate over every contribution and mark it as withdrawable if it is.
// Start from the second round as the first is automatically withdrawn
Expand Down Expand Up @@ -682,11 +711,11 @@ export function handleStatusUpdated(event: ItemStatusChange): void {
return;
}

if (requestInfo.value6 == NO_RULING_CODE) {
if (requestInfo.value.value6 == NO_RULING_CODE) {
// The final ruling is refuse to rule. There is no winner
// or loser so every contribution is withdrawable.
contribution.withdrawable = true;
} else if (requestInfo.value6 == REQUESTER_CODE) {
} else if (requestInfo.value.value6 == REQUESTER_CODE) {
// The requester won so only contributions to the requester
// are withdrawable.
// The only exception is in the case the last round the loser
Expand Down
2 changes: 1 addition & 1 deletion src/fileHandlers/EvidenceMetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function handleGTCREvidenceMetadata(content: Bytes): void {
log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]);

if (!parsedResult.isOk || parsedResult.isError) {
log.warning(`Error converting object for evidence {}`, [id]);
log.warning(`Error converting object for GTCR evidence {}`, [id]);
evidence.save();
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ export function JSONValueToBool(
return _default;
}
}
export const ZERO = BigInt.fromI32(0);
48 changes: 48 additions & 0 deletions tests/ipfs/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"columns": [
{
"label": "Github Repository URL",
"description": "The URL of the repository containing the function that returns the Contract Tags. The repository name must be in the kebab case (hyphen-case). ",
"type": "link",
"isIdentifier": true
},
{
"label": "Commit hash",
"description": "The hash of the specific commit for this repository to be referenced.",
"type": "text",
"isIdentifier": true
},
{
"label": "Chain ID",
"description": "The EVM integer Chain ID of the chain that the contracts being retrieved by the function in this module are on. This is informational only and not used as input for the functions.",
"type": "number",
"isIdentifier": true
},
{
"label": "Available on The Graph’s hosted service",
"description": "Boolean value indicating if the function can be called in an unauthenticated manner using The Graph’s hosted (unauthenticated) service.",
"type": "boolean",
"isIdentifier": true
},
{
"label": "Available on the decentralized Graph Network",
"description": "Boolean value indicating if the function can make use of indexed data from the decentralized Graph Network.",
"type": "boolean",
"isIdentifier": true
},
{
"label": "Description",
"description": "A field used to describe the range of contracts being curated here, specifying (if applicable) the version, type and purpose of the contracts that are returned. ",
"type": "long text",
"isIdentifier": false
}
],
"values": {
"Github Repository URL": "https://github.com/gmkung/balancer-v2-pools-atq-module.git",
"Commit hash": " 628491a",
"Chain ID": "137",
"Available on The Graph’s hosted service": "true",
"Available on the decentralized Graph Network": "false",
"Description": "A module to retrieve address tags describing Balancer V2 pools on Polygon."
}
}
99 changes: 99 additions & 0 deletions tests/litem.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {
Address,
Bytes,
DataSourceContext,
ethereum,
} from '@graphprotocol/graph-ts';
import {
afterAll,
assert,
beforeAll,
clearStore,
createMockedFunction,
dataSourceMock,
describe,
readFile,
test,
} from 'matchstick-as/assembly/index';
import { ZERO } from '../src/utils';
import { createNewItemEvent } from './utils/litem-utils';
import { handleNewGTCR } from '../src/LightGTCRFactoryMapping';
import { handleNewItem } from '../src/LightGeneralizedTCRMapping';
import { handleLItemMetadata } from '../src/fileHandlers/LItemMetadataHandler';
import {
GRAPH_ITEM_ID,
IPFS_HASH,
ITEM_DATA,
ITEM_ID,
REGISTRY_ADDRESS,
} from './utils/mockValues';
import { createNewGTCREvent } from './utils/lregistry-utils';

// mock getItemInfo function, called inside handleNewItem
createMockedFunction(
Address.fromString(REGISTRY_ADDRESS),
'getItemInfo',
'getItemInfo(bytes32):(uint8,uint256,uint256)',
)
.withArgs([ethereum.Value.fromFixedBytes(Bytes.fromHexString(ITEM_ID))])
.returns([
ethereum.Value.fromI32(0),
ethereum.Value.fromUnsignedBigInt(ZERO),
ethereum.Value.fromUnsignedBigInt(ZERO),
]);

describe('Testing LItem creation', () => {
beforeAll(() => {
const newGTCREvent = createNewGTCREvent(REGISTRY_ADDRESS);

handleNewGTCR(newGTCREvent);

assert.fieldEquals(
'LRegistry',
REGISTRY_ADDRESS,
'id',
REGISTRY_ADDRESS,
'LRegistry not created',
);
});

test('Should create LItem entity', () => {
const newItemEvent = createNewItemEvent(
REGISTRY_ADDRESS,
ITEM_ID,
ITEM_DATA,
);

handleNewItem(newItemEvent);

assert.fieldEquals('LItem', GRAPH_ITEM_ID, 'id', GRAPH_ITEM_ID);
});

test('Should create LItemMetadata datasource', () => {
// previous test should have created this datasource
assert.dataSourceExists('LItemMetadata', IPFS_HASH);

const context = new DataSourceContext();
context.setString('graphItemID', GRAPH_ITEM_ID);
context.setString('address', REGISTRY_ADDRESS);
dataSourceMock.setReturnValues(IPFS_HASH, 'arbitrum-one', context);

const content = readFile('tests/ipfs/item.json');

handleLItemMetadata(content);

const metadataEntityId = `${IPFS_HASH}-${GRAPH_ITEM_ID}`;

assert.fieldEquals(
'LItemMetadata',
metadataEntityId,
'id',
metadataEntityId,
);
dataSourceMock.resetValues();
});

afterAll(() => {
clearStore();
});
});
Loading
Loading