Skip to content

Commit

Permalink
fix: ensure snapshot value is in the network range (#225)
Browse files Browse the repository at this point in the history
* fix: check that snapshot is after network start block

* chore: add tests
  • Loading branch information
wa0x6e authored Oct 30, 2023
1 parent bf6cd26 commit 6b0af1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/writer/proposal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import snapshot from '@snapshot-labs/snapshot.js';
import networks from '@snapshot-labs/snapshot.js/src/networks.json';
import kebabCase from 'lodash/kebabCase';
import { jsonParse, validateChoices } from '../helpers/utils';
import db from '../helpers/mysql';
Expand Down Expand Up @@ -155,6 +156,9 @@ export async function verify(body): Promise<any> {
if (msg.payload.snapshot > currentBlockNum)
return Promise.reject('proposal snapshot must be in past');

if (msg.payload.snapshot < networks[space.network].start)
return Promise.reject('proposal snapshot must be after network start');

try {
const [{ dayCount, monthCount, activeProposalsByAuthor }] = await getProposalsCount(
space.id,
Expand Down
12 changes: 11 additions & 1 deletion test/unit/writer/proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,17 @@ describe('writer/proposal', () => {
msg.payload.snapshot = Number.MAX_SAFE_INTEGER;

await expect(writer.verify({ ...input, msg: JSON.stringify(msg) })).rejects.toMatch(
'snapshot'
'proposal snapshot must be in past'
);
});

it('rejects if the snapshot is lower than network start block', async () => {
expect.assertions(1);
const msg = JSON.parse(input.msg);
msg.payload.snapshot = 1000;

await expect(writer.verify({ ...input, msg: JSON.stringify(msg) })).rejects.toMatch(
'proposal snapshot must be after network start'
);
});

Expand Down

0 comments on commit 6b0af1b

Please sign in to comment.