-
Notifications
You must be signed in to change notification settings - Fork 14
fix(APP-965): Derive SPP proposal creation restriction from sub-plugin rules #1218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milosh86
merged 2 commits into
main
from
app-965-proposal-eligibility-shows-unrestricted-for-eligible-wallets
Jul 15, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@aragon/app": patch | ||
| --- | ||
|
|
||
| Fix proposal creation eligibility showing "Unrestricted" for eligible wallets on restricted SPP processes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,3 +66,4 @@ next-env.d.ts | |
| !.agents/shared/** | ||
| .playwright-mcp | ||
| .patches | ||
| .omp | ||
200 changes: 200 additions & 0 deletions
200
...hooks/useSppPermissionCheckProposalCreation/useSppPermissionCheckProposalCreation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| import { renderHook } from '@testing-library/react'; | ||
| import * as useSimulateProposalModule from '@/modules/governance/hooks/useSimulateProposal'; | ||
| import type { IPermissionCheckGuardResult } from '@/modules/governance/types'; | ||
| import * as daoService from '@/shared/api/daoService'; | ||
| import * as useDaoPluginsModule from '@/shared/hooks/useDaoPlugins'; | ||
| import { | ||
| generateDao, | ||
| generateDaoPlugin, | ||
| generateFilterComponentPlugin, | ||
| generateReactQueryResultSuccess, | ||
| } from '@/shared/testUtils'; | ||
| import { pluginRegistryUtils } from '@/shared/utils/pluginRegistryUtils'; | ||
| import { | ||
| generateSppPluginSettings, | ||
| generateSppStage, | ||
| generateSppStagePlugin, | ||
| } from '../../testUtils'; | ||
| import { useSppPermissionCheckProposalCreation } from './useSppPermissionCheckProposalCreation'; | ||
|
|
||
| describe('useSppPermissionCheckProposalCreation', () => { | ||
| const useDaoPluginsSpy = jest.spyOn(useDaoPluginsModule, 'useDaoPlugins'); | ||
| const useDaoSpy = jest.spyOn(daoService, 'useDao'); | ||
| const useSimulateProposalCreationSpy = jest.spyOn( | ||
| useSimulateProposalModule, | ||
| 'useSimulateProposalCreation', | ||
| ); | ||
| const getSlotFunctionSpy = jest.spyOn( | ||
| pluginRegistryUtils, | ||
| 'getSlotFunction', | ||
| ); | ||
|
|
||
| afterEach(() => { | ||
| useDaoPluginsSpy.mockReset(); | ||
| useDaoSpy.mockReset(); | ||
| useSimulateProposalCreationSpy.mockReset(); | ||
| getSlotFunctionSpy.mockReset(); | ||
| }); | ||
|
|
||
| const createTestParams = (guardResults: IPermissionCheckGuardResult[]) => { | ||
| const subPluginMetas = guardResults.map((_result, index) => | ||
| generateDaoPlugin({ | ||
| address: `0x${String(index + 1).padStart(40, '0')}`, | ||
| }), | ||
| ); | ||
|
|
||
| const sppPlugin = generateDaoPlugin({ | ||
| address: `0x${'a'.repeat(40)}`, | ||
| settings: generateSppPluginSettings({ | ||
| stages: [ | ||
| generateSppStage({ | ||
| plugins: subPluginMetas.map((meta) => | ||
| generateSppStagePlugin({ address: meta.address }), | ||
| ), | ||
| }), | ||
| ], | ||
| }), | ||
| }); | ||
|
|
||
| useDaoPluginsSpy.mockReturnValue( | ||
| subPluginMetas.map((meta) => | ||
| generateFilterComponentPlugin({ meta }), | ||
| ), | ||
| ); | ||
| useDaoSpy.mockReturnValue( | ||
| generateReactQueryResultSuccess({ data: generateDao() }), | ||
| ); | ||
|
|
||
| const slotFunctions = new Map( | ||
| subPluginMetas.map((meta, index) => [ | ||
| meta.address, | ||
| () => guardResults[index], | ||
| ]), | ||
| ); | ||
| getSlotFunctionSpy.mockImplementation( | ||
| () => | ||
| ((params: { plugin: { address: string } }) => | ||
| slotFunctions.get(params.plugin.address)?.()) as never, | ||
| ); | ||
|
|
||
| return { daoId: 'dao-test', plugin: sppPlugin }; | ||
| }; | ||
|
|
||
| const generateGuardResult = ( | ||
| result?: Partial<IPermissionCheckGuardResult>, | ||
| ): IPermissionCheckGuardResult => ({ | ||
| hasPermission: false, | ||
| settings: [], | ||
| isLoading: false, | ||
| isRestricted: false, | ||
| ...result, | ||
| }); | ||
|
|
||
| const mockSimulation = (result: { | ||
| isLoading: boolean; | ||
| isSuccess: boolean; | ||
| }) => | ||
| useSimulateProposalCreationSpy.mockReturnValue( | ||
| result as ReturnType< | ||
| typeof useSimulateProposalModule.useSimulateProposalCreation | ||
| >, | ||
| ); | ||
|
|
||
| it('returns isRestricted true for a restricted process even when the connected wallet can create a proposal', () => { | ||
| const settings = [[{ term: 'Members', definition: 'Listed only' }]]; | ||
| const guardResult = generateGuardResult({ | ||
| isRestricted: true, | ||
| settings, | ||
| hasPermission: true, | ||
| }); | ||
| const params = createTestParams([guardResult]); | ||
| mockSimulation({ isLoading: false, isSuccess: true }); | ||
|
|
||
| const { result } = renderHook(() => | ||
| useSppPermissionCheckProposalCreation( | ||
| params as Parameters< | ||
| typeof useSppPermissionCheckProposalCreation | ||
| >[0], | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current.isRestricted).toBeTruthy(); | ||
| expect(result.current.settings).toEqual(settings); | ||
| }); | ||
|
|
||
| it('returns isRestricted false when no sub-plugin restricts proposal creation', () => { | ||
| const params = createTestParams([ | ||
| generateGuardResult({ isRestricted: false }), | ||
| generateGuardResult({ isRestricted: false }), | ||
| ]); | ||
| mockSimulation({ isLoading: false, isSuccess: true }); | ||
|
|
||
| const { result } = renderHook(() => | ||
| useSppPermissionCheckProposalCreation( | ||
| params as Parameters< | ||
| typeof useSppPermissionCheckProposalCreation | ||
| >[0], | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current.isRestricted).toBeFalsy(); | ||
| }); | ||
|
|
||
| it('returns isRestricted true when any sub-plugin restricts proposal creation', () => { | ||
| const restrictedSettings = [ | ||
| [{ term: 'Voting power', definition: '≥10' }], | ||
| ]; | ||
| const params = createTestParams([ | ||
| generateGuardResult({ isRestricted: false }), | ||
| generateGuardResult({ | ||
| isRestricted: true, | ||
| settings: restrictedSettings, | ||
| }), | ||
| ]); | ||
| mockSimulation({ isLoading: false, isSuccess: true }); | ||
|
|
||
| const { result } = renderHook(() => | ||
| useSppPermissionCheckProposalCreation( | ||
| params as Parameters< | ||
| typeof useSppPermissionCheckProposalCreation | ||
| >[0], | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current.isRestricted).toBeTruthy(); | ||
| expect(result.current.settings).toEqual(restrictedSettings); | ||
| }); | ||
|
|
||
| it('derives hasPermission from the proposal creation simulation', () => { | ||
| const params = createTestParams([ | ||
| generateGuardResult({ isRestricted: true }), | ||
| ]); | ||
| mockSimulation({ isLoading: false, isSuccess: false }); | ||
|
|
||
| const { result } = renderHook(() => | ||
| useSppPermissionCheckProposalCreation( | ||
| params as Parameters< | ||
| typeof useSppPermissionCheckProposalCreation | ||
| >[0], | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current.hasPermission).toBeFalsy(); | ||
| expect(result.current.isRestricted).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns isLoading true while the simulation is loading', () => { | ||
| const params = createTestParams([generateGuardResult()]); | ||
| mockSimulation({ isLoading: true, isSuccess: false }); | ||
|
|
||
| const { result } = renderHook(() => | ||
| useSppPermissionCheckProposalCreation( | ||
| params as Parameters< | ||
| typeof useSppPermissionCheckProposalCreation | ||
| >[0], | ||
| ), | ||
| ); | ||
|
|
||
| expect(result.current.isLoading).toBeTruthy(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably could've used
settings.lengthas a proxy forisRestrictedtoo, but I think your version reads better 👍