Skip to content

Commit

Permalink
Merge branch 'master' into feat-support-variables-in-subgraphRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Aug 20, 2024
2 parents 4a1d95a + 75f1a0b commit 6ebe7c4
Show file tree
Hide file tree
Showing 9 changed files with 1,057 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.12.2",
"version": "0.12.4",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand Down
1 change: 1 addition & 0 deletions src/delegationSubgraphs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"100": "https://subgrapher.snapshot.org/delegation/100",
"137": "https://subgrapher.snapshot.org/delegation/137",
"250": "https://subgrapher.snapshot.org/delegation/250",
"8453": "https://subgrapher.snapshot.org/delegation/8453",
"42161": "https://subgrapher.snapshot.org/delegation/42161",
"11155111": "https://subgrapher.snapshot.org/delegation/11155111"
}
5 changes: 4 additions & 1 deletion src/schemas/proposal.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"type": "array",
"title": "choices",
"minItems": 1,
"maxItems": 500
"maxLengthWithSpaceType": {
"default": 500,
"turbo": 1000
}
},
"type": {
"type": "string",
Expand Down
5 changes: 4 additions & 1 deletion src/schemas/update-proposal.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"type": "array",
"title": "choices",
"minItems": 1,
"maxItems": 500
"maxLengthWithSpaceType": {
"default": 500,
"turbo": 1000
}
},
"type": {
"enum": [
Expand Down
18 changes: 17 additions & 1 deletion src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
validateSchema,
getScores,
getVp,
getFormattedAddress
getFormattedAddress,
getEnsOwner,
getEnsTextRecord
} from './utils';

vi.mock('cross-fetch', async () => {
Expand Down Expand Up @@ -611,4 +613,18 @@ describe('utils', () => {
expect(result).not.toBe(true);
});
});

describe('getEnsOwner', () => {
test('should return null when the ENS is not valid', () => {
// special hidden characters after the k
expect(getEnsOwner('elonmusk‍‍.eth')).resolves.toBe(null);
});
});

describe('getEnsTextRecord', () => {
test('should return null when the ENS is not valid', () => {
// special hidden characters after the k
expect(getEnsTextRecord('elonmusk‍‍.eth')).resolves.toBe(null);
});
});
});
21 changes: 18 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ajv.addKeyword({
validate.errors = [
{
keyword: 'maxLengthWithSpaceType',
message: `must NOT have more than ${schema[spaceType]} characters`,
message: `must not have more than ${schema[spaceType]}`,
params: { limit: schema[spaceType] }
}
];
Expand Down Expand Up @@ -546,7 +546,14 @@ export async function getEnsTextRecord(
...multicallOptions
} = options;

const ensHash = namehash(ensNormalize(ens));
let ensHash: string;

try {
ensHash = namehash(ensNormalize(ens));
} catch (e: any) {
return null;
}

const provider = getProvider(network, { broviderUrl });

const calls = [
Expand Down Expand Up @@ -594,9 +601,17 @@ export async function getEnsOwner(
['function owner(bytes32) view returns (address)'],
provider
);

let ensHash: string;

try {
ensHash = namehash(ensNormalize(ens));
} catch (e: any) {
return null;
}

const ensNameWrapper =
options.ensNameWrapper || networks[network].ensNameWrapper;
const ensHash = namehash(ensNormalize(ens));
let owner = await ensRegistry.owner(ensHash);
// If owner is the ENSNameWrapper contract, resolve the owner of the name
if (owner === ensNameWrapper) {
Expand Down
11 changes: 10 additions & 1 deletion test/examples/proposal-maxLengthWithSpaceType-error.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
{
"instancePath": "/body",
"keyword": "maxLengthWithSpaceType",
"message": "must NOT have more than 10000 characters",
"message": "must not have more than 10000",
"params": {
"limit": 10000
},
"schemaPath": "#/properties/body/maxLengthWithSpaceType"
},
{
"instancePath": "/choices",
"keyword": "maxLengthWithSpaceType",
"message": "must not have more than 500",
"params": {
"limit": 500
},
"schemaPath": "#/properties/choices/maxLengthWithSpaceType"
}
]
1,002 changes: 1,000 additions & 2 deletions test/examples/proposal-turbo.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import schemas from '../src/schemas';
import proposalMaxLengthWithSpaceTypeError from './examples/proposal-maxLengthWithSpaceType-error.json';
import spaceMaxItemsWithSpaceTypeError from './examples/space-maxItemsWithSpaceType-error.json';

// Tests for default spaces
describe.each([
{ schemaType: 'space', schema: schemas.space, example: space },
{ schemaType: 'proposal', schema: schemas.proposal, example: proposal },
Expand All @@ -30,7 +31,6 @@ describe.each([
});

// Tests for turbo spaces

describe.each([
{ schemaType: 'space', schema: schemas.space, example: spaceTurbo },
{ schemaType: 'proposal', schema: schemas.proposal, example: proposalTurbo }
Expand All @@ -44,6 +44,7 @@ describe.each([
});
});

// tests for default schema with turbo example, should fail
describe.each([
{
schemaType: 'space',
Expand Down

0 comments on commit 6ebe7c4

Please sign in to comment.