Skip to content

Commit

Permalink
feat: accept longer app property
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 17, 2024
1 parent 26c3a77 commit 539eab9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ export function captureError(e: any, context?: any, ignoredErrorCodes?: number[]
export async function clearStampCache(type: string, id: string) {
return fetch(`https://cdn.stamp.fyi/clear/${type}/${type === 'avatar' ? 'eth:' : ''}${id}`);
}

export function formatApp(app: string | undefined): string {
if (!app || app?.length > 128) return '';

return app;
}
7 changes: 3 additions & 4 deletions src/ingestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { capture } from '@snapshot-labs/snapshot-sentry';
import snapshot from '@snapshot-labs/snapshot.js';
import hashTypes from '@snapshot-labs/snapshot.js/src/sign/hashedTypes.json';
import castArray from 'lodash/castArray';
import kebabCase from 'lodash/kebabCase';
import { getProposal, getSpace } from './helpers/actions';
import { isValidAlias } from './helpers/alias';
import envelope from './helpers/envelope.json';
Expand All @@ -13,7 +12,7 @@ import log from './helpers/log';
import { timeIngestorProcess } from './helpers/metrics';
import { flaggedIps } from './helpers/moderation';
import relayer, { issueReceipt } from './helpers/relayer';
import { getIp, jsonParse, sha256 } from './helpers/utils';
import { formatApp, getIp, jsonParse, sha256 } from './helpers/utils';
import writer from './writer';

const NETWORK_METADATA = {
Expand Down Expand Up @@ -151,7 +150,7 @@ export default async function ingestor(req) {
plugins: JSON.parse(message.plugins)
},
type: message.type,
app: kebabCase(message.app || '')
app: formatApp(message.app)
};
if (type === 'alias') payload = { alias: message.alias };
if (type === 'statement')
Expand Down Expand Up @@ -200,7 +199,7 @@ export default async function ingestor(req) {
proposal: message.proposal,
choice,
reason: message.reason || '',
app: kebabCase(message.app || ''),
app: formatApp(message.app),
metadata: jsonParse(message.metadata, {})
};
type = 'vote';
Expand Down
3 changes: 1 addition & 2 deletions src/writer/proposal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { capture } from '@snapshot-labs/snapshot-sentry';
import snapshot from '@snapshot-labs/snapshot.js';
import networks from '@snapshot-labs/snapshot.js/src/networks.json';
import kebabCase from 'lodash/kebabCase';
import { validateSpaceSettings } from './settings';
import { getSpace } from '../helpers/actions';
import { ACTIVE_PROPOSAL_BY_AUTHOR_LIMIT, getSpaceLimits } from '../helpers/limits';
Expand Down Expand Up @@ -240,7 +239,7 @@ export async function action(body, ipfs, receipt, id): Promise<void> {
quorum_type: (quorum && spaceSettings.voting?.quorumType) || '',
privacy: spaceSettings.voting?.privacy || '',
snapshot: proposalSnapshot || 0,
app: kebabCase(msg.payload.app || ''),
app: msg.payload.app,
scores: JSON.stringify([]),
scores_by_strategy: JSON.stringify([]),
scores_state: 'pending',
Expand Down
3 changes: 1 addition & 2 deletions src/writer/vote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import snapshot from '@snapshot-labs/snapshot.js';
import kebabCase from 'lodash/kebabCase';
import { getProposal } from '../helpers/actions';
import log from '../helpers/log';
import db from '../helpers/mysql';
Expand Down Expand Up @@ -108,7 +107,7 @@ export async function action(body, ipfs, receipt, id, context): Promise<void> {
const created = parseInt(msg.timestamp);
const choice = JSON.stringify(msg.payload.choice);
const metadata = JSON.stringify(msg.payload.metadata || {});
const app = kebabCase(msg.payload.app || '');
const app = msg.payload.app;
const reason = msg.payload.reason || '';
const proposalId = msg.payload.proposal;

Expand Down
4 changes: 2 additions & 2 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CREATE TABLE proposals (
quorum_type VARCHAR(24) NOT NULL DEFAULT '',
privacy VARCHAR(24) NOT NULL,
snapshot INT(24) NOT NULL,
app VARCHAR(24) NOT NULL,
app VARCHAR(128) NOT NULL,
scores JSON NOT NULL,
scores_by_strategy JSON NOT NULL,
scores_state VARCHAR(24) NOT NULL,
Expand Down Expand Up @@ -86,7 +86,7 @@ CREATE TABLE votes (
choice JSON NOT NULL,
metadata JSON NOT NULL,
reason TEXT NOT NULL,
app VARCHAR(24) NOT NULL,
app VARCHAR(128) NOT NULL,
vp DECIMAL(64,30) NOT NULL,
vp_by_strategy JSON NOT NULL,
vp_state VARCHAR(24) NOT NULL,
Expand Down
20 changes: 20 additions & 0 deletions test/unit/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { formatApp } from '../../../src/helpers/utils';

describe('utils', () => {
describe('formatApp()', () => {
it('returns an empty string on empty', () => {
expect(formatApp(undefined)).toEqual('');
expect(formatApp('')).toEqual('');
});

it('returns the input when valid', () => {
expect('0xAaB').toBe('0xAaB');
});

it('returns an empty string exceeding the chars limit', () => {
expect(
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz!'
).toBe('');
});
});
});

0 comments on commit 539eab9

Please sign in to comment.