This repository was archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 357
(Fix) remove module feature #1646
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4cc28df
fix remove module feature
fernandomg 32b40f3
Merge branch 'development' into fix/1367-remove-module
fernandomg 4c8080c
rename `selectedModule` to `selectedModulePair`
fernandomg 02ec0ce
add tests for `buildModulesLinkedList`
fernandomg eed7d16
fix typos
fernandomg 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
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,111 @@ | ||
| import { SENTINEL_ADDRESS } from 'src/logic/contracts/safeContracts' | ||
| import { buildModulesLinkedList } from 'src/logic/safe/utils/modules' | ||
|
|
||
| describe('modules -> buildModulesLinkedList', () => { | ||
| let moduleManager | ||
|
|
||
| beforeEach(() => { | ||
| moduleManager = { | ||
| modules: { | ||
| [SENTINEL_ADDRESS]: SENTINEL_ADDRESS, | ||
| }, | ||
| enableModule: function (module: string) { | ||
| this.modules[module] = this.modules[SENTINEL_ADDRESS] | ||
| this.modules[SENTINEL_ADDRESS] = module | ||
| }, | ||
| disableModule: function (prevModule: string, module: string) { | ||
| this.modules[prevModule] = this.modules[module] | ||
| this.modules[module] = '0x0' | ||
| }, | ||
| getModules: function (): string[] { | ||
| const modules: string[] = [] | ||
| let module: string = this.modules[SENTINEL_ADDRESS] | ||
|
|
||
| while (module !== SENTINEL_ADDRESS) { | ||
| modules.push(module) | ||
| module = this.modules[module] | ||
| } | ||
|
|
||
| return modules | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| it(`should build a collection of addresses pair associated to a linked list`, () => { | ||
| // Given | ||
| const listOfModules = ['0xa', '0xb', '0xc', '0xd', '0xe', '0xf'] | ||
|
|
||
| // When | ||
| const modulesPairList = buildModulesLinkedList(listOfModules) | ||
|
|
||
| // Then | ||
| expect(modulesPairList).toStrictEqual([ | ||
| [SENTINEL_ADDRESS, '0xa'], | ||
| ['0xa', '0xb'], | ||
| ['0xb', '0xc'], | ||
| ['0xc', '0xd'], | ||
| ['0xd', '0xe'], | ||
| ['0xe', '0xf'], | ||
| ]) | ||
| }) | ||
|
|
||
| it(`should properly provide a list of modules pair to remove an specified module`, () => { | ||
| // Given | ||
| moduleManager.enableModule('0xc') | ||
| moduleManager.enableModule('0xb') | ||
| moduleManager.enableModule('0xa') // returned list is ordered [0xa, 0xb, 0xc] | ||
| const modulesPairList = buildModulesLinkedList(moduleManager.getModules()) | ||
|
|
||
| // When | ||
| const moduleBPair = modulesPairList?.[1] ?? [] | ||
| moduleManager.disableModule(...moduleBPair) | ||
|
|
||
| // Then | ||
| expect(moduleManager.modules['0xb']).toBe('0x0') | ||
| expect(moduleManager.getModules()).toStrictEqual(['0xa', '0xc']) | ||
| expect(buildModulesLinkedList(moduleManager.getModules())).toStrictEqual([ | ||
| [SENTINEL_ADDRESS, '0xa'], | ||
| ['0xa', '0xc'], | ||
| ]) | ||
| }) | ||
|
|
||
| it(`should properly provide a list of modules pair to remove the firstly added module`, () => { | ||
| // Given | ||
| moduleManager.enableModule('0xc') | ||
| moduleManager.enableModule('0xb') | ||
| moduleManager.enableModule('0xa') // returned list is ordered [0xa, 0xb, 0xc] | ||
| const modulesPairList = buildModulesLinkedList(moduleManager.getModules()) | ||
|
|
||
| // When | ||
| const moduleBPair = modulesPairList?.[2] ?? [] | ||
| moduleManager.disableModule(...moduleBPair) | ||
|
|
||
| // Then | ||
| expect(moduleManager.modules['0xc']).toBe('0x0') | ||
| expect(moduleManager.getModules()).toStrictEqual(['0xa', '0xb']) | ||
| expect(buildModulesLinkedList(moduleManager.getModules())).toStrictEqual([ | ||
| [SENTINEL_ADDRESS, '0xa'], | ||
| ['0xa', '0xb'], | ||
| ]) | ||
| }) | ||
|
|
||
| it(`should properly provide a list of modules pair to remove the lastly added module`, () => { | ||
| // Given | ||
| moduleManager.enableModule('0xc') | ||
| moduleManager.enableModule('0xb') | ||
| moduleManager.enableModule('0xa') // returned list is ordered [0xa, 0xb, 0xc] | ||
| const modulesPairList = buildModulesLinkedList(moduleManager.getModules()) | ||
|
|
||
| // When | ||
| const moduleBPair = modulesPairList?.[0] ?? [] | ||
| moduleManager.disableModule(...moduleBPair) | ||
|
|
||
| // Then | ||
| expect(moduleManager.modules['0xa']).toBe('0x0') | ||
| expect(moduleManager.getModules()).toStrictEqual(['0xb', '0xc']) | ||
| expect(buildModulesLinkedList(moduleManager.getModules())).toStrictEqual([ | ||
| [SENTINEL_ADDRESS, '0xb'], | ||
| ['0xb', '0xc'], | ||
| ]) | ||
| }) | ||
| }) |
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
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
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
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.
can we rename
selectedModuletoselectedPairModule?also, could it be possible to assign
const prevModule = selectedModule[0]? I think it will help to understand what selectedModule[0] is.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.
the assignment to a variable was already done, but I'm going with the
selectedModulePairvariable name