Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.2.1",
"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();
}
16 changes: 14 additions & 2 deletions src/LightGeneralizedTCRMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
Ruling,
ConnectedTCRSet as ConnectedTCRSetEvent,
} from '../generated/templates/LightGeneralizedTCR/LightGeneralizedTCR';
import { ZERO_ADDRESS, extractPath } from './utils';
import { ZERO, ZERO_ADDRESS, extractPath } from './utils';

// Items on a TCR can be in 1 of 4 states:
// - (0) Absent: The item is not registered on the TCR and there are no pending requests.
Expand Down Expand Up @@ -284,7 +284,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 @@ -686,6 +689,15 @@ export function handleStatusUpdated(event: ItemStatusChange): void {

item.latestRequestResolutionTime = event.block.timestamp;

if(item.numberOfRequests.equals(ZERO)){
log.error(
`Encountered 0 as numberOfRequest for Item : {}`,
[graphItemID],
);
item.save();
return;
}

let requestIndex = safeDecrement(item.numberOfRequests);
let requestInfoResult = tcr.try_getRequestInfo(event.params._itemID, requestIndex);
if (requestInfoResult.reverted) {
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);
2 changes: 1 addition & 1 deletion subgraph.template.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
specVersion: 1.0.0
description: Generalized TCR
description: Generalized TCR v1.2.1
features:
- fullTextSearch
- ipfsOnEthereumContracts
Expand Down
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();
});
});
42 changes: 42 additions & 0 deletions tests/utils/litem-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Address, Bytes, ethereum } from '@graphprotocol/graph-ts';
import { NewItem } from '../../generated/templates/LightGeneralizedTCR/LightGeneralizedTCR';
import { newMockEvent } from 'matchstick-as';

export function createNewItemEvent(
registry: string,
itemID: string,
data: string,
): NewItem {
const mockEvent = newMockEvent();

const newNewItemEvent = new NewItem(
Address.fromString(registry),
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
mockEvent.parameters,
mockEvent.receipt,
);
newNewItemEvent.parameters = [];

const itemIDParam = new ethereum.EventParam(
'_itemID',
ethereum.Value.fromBytes(Bytes.fromHexString(itemID)),
);
const dataParam = new ethereum.EventParam(
'_data',
ethereum.Value.fromString(data),
);
const addedDirectlyParam = new ethereum.EventParam(
'_addedDirectly',
ethereum.Value.fromBoolean(false),
);

newNewItemEvent.parameters.push(itemIDParam);
newNewItemEvent.parameters.push(dataParam);
newNewItemEvent.parameters.push(addedDirectlyParam);

return newNewItemEvent;
}
28 changes: 28 additions & 0 deletions tests/utils/lregistry-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Address, ethereum } from '@graphprotocol/graph-ts';
import { newMockEvent } from 'matchstick-as';
import { NewGTCR } from '../../generated/LightGTCRFactory/LightGTCRFactory';

export function createNewGTCREvent(address: string): NewGTCR {
const mockEvent = newMockEvent();

const newGTCREvent = new NewGTCR(
mockEvent.address,
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
mockEvent.parameters,
mockEvent.receipt,
);
newGTCREvent.parameters = [];

const addressParam = new ethereum.EventParam(
'_address',
ethereum.Value.fromAddress(Address.fromString(address)),
);

newGTCREvent.parameters.push(addressParam);

return newGTCREvent;
}
7 changes: 7 additions & 0 deletions tests/utils/mockValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const REGISTRY_ADDRESS = '0x08e58bc26cfb0d346babd253a1799866f269805a';
export const ITEM_ID =
'0x9caa5e1ac3fac10c7953a80f022f78bce895bff8e6c4eeca0aab987e1f5aa103';
export const GRAPH_ITEM_ID = `${ITEM_ID}@${REGISTRY_ADDRESS}`;
export const IPFS_HASH =
'QmfNNjdL5P2J9gM3yk8qoFUixqzsSF2Yzo1gYrfZ6QBgw6/item.json';
export const ITEM_DATA = `/ipfs/${IPFS_HASH}`;
Loading
Loading