Skip to content

Commit

Permalink
refactor: delegationNetwork default value (#462)
Browse files Browse the repository at this point in the history
* refactor: delegationNetwork default value

* test: add tests

---------

Co-authored-by: Wan Qi Chen <[email protected]>
  • Loading branch information
ChaituVR and wa0x6e authored Oct 17, 2024
1 parent d838cd9 commit 26c3a77
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export async function addOrUpdateSpace(space: string, settings: any) {
}
if (settings.delegationPortal) {
settings.delegationPortal = {
...settings.delegationPortal,
delegationNetwork: settings.delegationPortal.delegationNetwork ?? '1'
delegationNetwork: '1',
...settings.delegationPortal
};
}

Expand Down
50 changes: 49 additions & 1 deletion test/integration/helpers/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSpace, sxSpaceExists } from '../../../src/helpers/actions';
import { addOrUpdateSpace, getSpace, sxSpaceExists } from '../../../src/helpers/actions';
import db, { sequencerDB } from '../../../src/helpers/mysql';
import { DEFAULT_NETWORK_ID } from '../../../src/helpers/utils';
import { spacesSqlFixtures } from '../../fixtures/space';
Expand Down Expand Up @@ -118,4 +118,52 @@ describe('helpers/actions', () => {
return expect(sxSpaceExists('sep', mapping['eth'])).resolves.toEqual(false);
});
});

describe('addOrUpdateSpace', () => {
const testId = 'test-add-or-update-space.eth';

afterEach(async () => {
await db.queryAsync('DELETE FROM snapshot_sequencer_test.spaces WHERE id = ?', [testId]);
});

describe('cleanup delegationPortal', () => {
it('set the given delegationNetwork', async () => {
const settings = {
...spacesSqlFixtures[0].settings,
delegationPortal: { delegationNetwork: '1234' }
};
await addOrUpdateSpace(testId, settings);
const space = (await db.queryAsync('SELECT * FROM spaces WHERE id = ?', [testId]))[0];

expect(JSON.parse(space.settings).delegationPortal).toEqual(settings.delegationPortal);
});

it('set a default delegationNetwork when missing', async () => {
const settings = {
...spacesSqlFixtures[0].settings,
delegationPortal: { delegationType: 'compound-governor' }
};
await addOrUpdateSpace(testId, settings);
const space = (await db.queryAsync('SELECT * FROM spaces WHERE id = ?', [testId]))[0];

expect(JSON.parse(space.settings).delegationPortal).toEqual({
...settings.delegationPortal,
delegationNetwork: '1'
});
});
});

describe('cleanup domain', () => {
it('normalize the domain', async () => {
const settings = {
...spacesSqlFixtures[0].settings,
domain: 'https://vote.snapshot.org/'
};
await addOrUpdateSpace(testId, settings);
const space = (await db.queryAsync('SELECT * FROM spaces WHERE id = ?', [testId]))[0];

expect(JSON.parse(space.settings).domain).toEqual('vote.snapshot.org');
});
});
});
});

0 comments on commit 26c3a77

Please sign in to comment.