Skip to content

Commit

Permalink
Merge branch 'fix-privacy-check' of https://github.com/snapshot-labs/…
Browse files Browse the repository at this point in the history
…snapshot-sequencer into fix-privacy-check
  • Loading branch information
wa0x6e committed Jan 7, 2025
2 parents 66585e0 + 6ed7a53 commit adf757c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/ingestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default async function ingestor(req) {
body: message.body,
discussion: message.discussion || '',
choices: message.choices,
privacy: message.privacy || '',
privacy: message.privacy,
labels: message.labels || [],
start: message.start,
end: message.end,
Expand All @@ -169,7 +169,7 @@ export default async function ingestor(req) {
name: message.title,
body: message.body,
discussion: message.discussion || '',
privacy: message.privacy || '',
privacy: message.privacy,
choices: message.choices,
labels: message.labels || [],
metadata: {
Expand Down
13 changes: 6 additions & 7 deletions src/writer/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ export async function verify(body): Promise<any> {
if (msg.payload.type !== space.voting.type) return Promise.reject('invalid voting type');
}

if (
space.voting?.privacy !== 'any' &&
msg.payload.privacy &&
!(space.voting?.privacy === 'shutter' && msg.payload.privacy === 'shutter')
) {
const spacePrivacy = space.voting?.privacy ?? 'any';
const proposalPrivacy = msg.payload.privacy;

if (proposalPrivacy !== undefined && spacePrivacy !== 'any' && spacePrivacy !== proposalPrivacy) {
return Promise.reject('not allowed to set privacy');
}

Expand Down Expand Up @@ -214,9 +213,9 @@ export async function action(body, ipfs, receipt, id): Promise<void> {
const plugins = JSON.stringify(metadata.plugins || {});
const spaceNetwork = spaceSettings.network;
const proposalSnapshot = parseInt(msg.payload.snapshot || '0');
let privacy = spaceSettings.voting?.privacy || '';
let privacy = spaceSettings.voting?.privacy ?? 'any';
if (privacy === 'any') {
privacy = msg.payload.privacy;
privacy = msg.payload.privacy ?? '';
}

let quorum = spaceSettings.voting?.quorum || 0;
Expand Down
13 changes: 6 additions & 7 deletions src/writer/update-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ export async function verify(body): Promise<any> {

if (proposal.author !== body.address) return Promise.reject('Not the author');

if (
space.voting?.privacy !== 'any' &&
msg.payload.privacy &&
!(space.voting.privacy === 'shutter' && msg.payload.privacy === 'shutter')
) {
const spacePrivacy = space.voting?.privacy ?? 'any';
const proposalPrivacy = msg.payload.privacy;

if (proposalPrivacy !== undefined && spacePrivacy !== 'any' && spacePrivacy !== proposalPrivacy) {
return Promise.reject('not allowed to set privacy');
}

Expand All @@ -72,9 +71,9 @@ export async function action(body, ipfs): Promise<void> {
const metadata = msg.payload.metadata || {};
const plugins = JSON.stringify(metadata.plugins || {});
const spaceSettings = await getSpace(msg.space);
let privacy = spaceSettings.voting?.privacy || '';
let privacy = spaceSettings.voting?.privacy ?? 'any';
if (privacy === 'any') {
privacy = msg.payload.privacy;
privacy = msg.payload.privacy ?? '';
}

const proposal = {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fetch from 'node-fetch';
import db from '../../src/helpers/mysql';
import proposalInput from '../fixtures/ingestor-payload/proposal.json';
import { spacesSqlFixtures } from '../fixtures/space';
import proposalsFixtures from '../fixtures/proposal';
import db from '../../src/helpers/mysql';
import { spacesSqlFixtures } from '../fixtures/space';

const HOST = `http://localhost:${process.env.PORT || 3003}`;
const SPACE_PREFIX = 'e2e-';
Expand Down Expand Up @@ -71,7 +71,8 @@ describe('POST /flag', () => {
plugins: JSON.stringify(proposal.plugins),
choices: JSON.stringify(proposal.choices),
scores: JSON.stringify(proposal.scores),
scores_by_strategy: JSON.stringify(proposal.scores_by_strategy)
scores_by_strategy: JSON.stringify(proposal.scores_by_strategy),
vp_value_by_strategy: JSON.stringify(proposal.vp_value_by_strategy || [])
}))
.map(async proposal => {
db.queryAsync('INSERT INTO snapshot_sequencer_test.proposals SET ?', proposal);
Expand Down
18 changes: 13 additions & 5 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ CREATE TABLE spaces (
INDEX updated (updated)
);

-- Note: The `proposals` table schema might have some discrepancies
-- compared to the production database. This is due to legacy reasons
-- and the challenges associated with updating the schema because of its size.
-- `id` and `ipfs` columns should not have any default values.
CREATE TABLE proposals (
id VARCHAR(66) NOT NULL,
ipfs VARCHAR(64) NOT NULL,
Expand All @@ -36,8 +40,8 @@ CREATE TABLE proposals (
updated INT(11) DEFAULT NULL,
space VARCHAR(64) NOT NULL,
network VARCHAR(12) NOT NULL,
symbol VARCHAR(16) NOT NULL,
type VARCHAR(24) NOT NULL,
symbol VARCHAR(16) NOT NULL DEFAULT '',
type VARCHAR(24) NOT NULL DEFAULT '',
strategies JSON NOT NULL,
validation JSON NOT NULL,
plugins JSON NOT NULL,
Expand All @@ -49,17 +53,20 @@ CREATE TABLE proposals (
start INT(11) NOT NULL,
end INT(11) NOT NULL,
quorum DECIMAL(64,30) NOT NULL,
quorum_type VARCHAR(24) NOT NULL DEFAULT '',
quorum_type VARCHAR(24) DEFAULT '',
privacy VARCHAR(24) NOT NULL,
snapshot INT(24) NOT NULL,
app VARCHAR(24) NOT NULL,
scores JSON NOT NULL,
scores_by_strategy JSON NOT NULL,
scores_state VARCHAR(24) NOT NULL,
scores_state VARCHAR(24) NOT NULL DEFAULT '',
scores_total DECIMAL(64,30) NOT NULL,
scores_updated INT(11) NOT NULL,
scores_total_value DECIMAL(64,30) NOT NULL DEFAULT '0.000000000000000000000000000000',
vp_value_by_strategy json NOT NULL,
votes INT(12) NOT NULL,
flagged INT NOT NULL DEFAULT 0,
cb INT NOT NULL DEFAULT 0,
PRIMARY KEY (id),
INDEX ipfs (ipfs),
INDEX author (author),
Expand All @@ -73,7 +80,8 @@ CREATE TABLE proposals (
INDEX scores_state (scores_state),
INDEX scores_updated (scores_updated),
INDEX votes (votes),
INDEX flagged (flagged)
INDEX flagged (flagged),
INDEX cb (cb)
);

CREATE TABLE votes (
Expand Down
7 changes: 7 additions & 0 deletions test/unit/writer/proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ describe('writer/proposal', () => {
writer.verify(updateInputPayload(input, { privacy: undefined }))
).resolves.toBeUndefined();
});

it('rejects a proposal with privacy empty string', async () => {
expect.assertions(1);
await expect(writer.verify(updateInputPayload(input, { privacy: '' }))).rejects.toMatch(
'not allowed to set privacy'
);
});
});
});

Expand Down

0 comments on commit adf757c

Please sign in to comment.