Skip to content
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

feat: update graph endpoint and add comprehensive query tests #3

Open
wants to merge 1 commit into
base: master
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { Record, Profile } from '@resolverworks/enson';
import { mock_list } from './mock_data';

const graphUrl = `https://gateway.thegraph.com/api/1e800956ee244eeda0ad15fbad7a8c67/subgraphs/id/HxdDjjtznb8VFwqxAsHrfKUgjAUdziisERQdC1UcCr5U`
const graphUrl = `https://query.graph.tkn.xyz/subgraphs/name/tkn/l2-manager-v3`

const rpcs = [
// 'https://eth-mainnet.g.alchemy.com/v2/9T5n0ljpi0uGhLhyGnQNQ0ZJ8aU9awlQ'
Expand Down Expand Up @@ -90,4 +90,4 @@ const tkn = {
// other utilities
};

export { tkn };
export { tkn };
101 changes: 81 additions & 20 deletions test/tkn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,97 @@ describe('tkn.list', () => {
});

describe('tkn.graphQuery', () => {
it('should fetch data from the GraphQL endpoint', async () => {
const query = `
{
tokens(first: 5) {
id
name
symbol
decimals
}
it('should fetch and verify lists data', async () => {
const query = `{
lists(where: {hash: "test"}) {
id
name
hash
tokenIds
}
`;
}`;
const result = await tkn.graphQuery(query);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.data.lists).toBeDefined();
expect(Array.isArray(result.data.lists)).toBe(true);
});

it('should fetch and verify sublists data', async () => {
const query = `{
sublists(where: {name: ""}) {
owner
name
id
listHash
description
}
}`;
const result = await tkn.graphQuery(query);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.data.sublists).toBeDefined();
expect(Array.isArray(result.data.sublists)).toBe(true);
});

it('should fetch and verify tokens data', async () => {
const query = `{
tokens(where: {symbol: "ETH"}) {
id
name
symbol
addresses {
address
chainID {
id
}
}
}
}`;
const result = await tkn.graphQuery(query);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.data.tokens).toBeDefined();

// Check if tokens is an array and has elements
expect(Array.isArray(result.data.tokens)).toBe(true);
expect(result.data.tokens.length).toBeGreaterThan(0);

// Check the structure of the first token
const firstToken = result.data.tokens[0];
expect(firstToken).toHaveProperty('id');
expect(firstToken).toHaveProperty('name');
expect(firstToken).toHaveProperty('symbol');
expect(firstToken).toHaveProperty('decimals');
if (result.data.tokens.length > 0) {
const token = result.data.tokens[0];
expect(token).toHaveProperty('id');
expect(token).toHaveProperty('name');
expect(token).toHaveProperty('symbol');
expect(token).toHaveProperty('addresses');
expect(Array.isArray(token.addresses)).toBe(true);
}
});

it('should fetch and verify addresses data', async () => {
const query = `{
addresses(where: {chainID_: {id: "1"}}) {
address
id
nonEVMAddress
tokenId {
id
symbol
}
chainID {
id
}
}
}`;
const result = await tkn.graphQuery(query);
expect(result).toBeDefined();
expect(result.data).toBeDefined();
expect(result.data.addresses).toBeDefined();
expect(Array.isArray(result.data.addresses)).toBe(true);

console.log(JSON.stringify(result, null, 2));
if (result.data.addresses.length > 0) {
const address = result.data.addresses[0];
expect(address).toHaveProperty('address');
expect(address).toHaveProperty('id');
expect(address).toHaveProperty('tokenId');
expect(address).toHaveProperty('chainID');
}
});
});

5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1117,11 +1117,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
Expand Down
Loading