Skip to content

chore: litem-tests #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: chore/abstract-zero
Choose a base branch
from
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
18 changes: 4 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
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}`;
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"resolveJsonModule": true,
"experimentalDecorators": true
},
"include": ["src"],
"exclude": ["node_modules"]
"include": [
"src",
"tests"
],
"exclude": [
"node_modules"
]
}
Loading
Loading