-
Notifications
You must be signed in to change notification settings - Fork 20
Read settings from one storage snapshot #1600
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1289fbf
Read settings from one storage snapshot
KillariDev aec8305
Merge branch 'main' into fix/atomic-settings-snapshot
KillariDev c62d70e
Merge branch 'main' into fix/atomic-settings-snapshot
KillariDev f48544f
Move own-key guard to TypeScript utilities
KillariDev 5c1dbe3
Merge branch 'main' into fix/atomic-settings-snapshot
KillariDev 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
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
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
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,76 @@ | ||
| import * as assert from 'assert' | ||
| import { test } from 'bun:test' | ||
|
|
||
| const firstSnapshot = { | ||
| independentActiveSimulationAddress: '0x1111111111111111111111111111111111111111', | ||
| activeSigningSafeAddress: '0x3333333333333333333333333333333333333333', | ||
| openedPageV2: { page: 'Home' }, | ||
| useSignersAddressAsActiveAddress: false, | ||
| websiteAccess: [], | ||
| simulationMode: true, | ||
| activeRpcNetwork: { | ||
| name: 'First network', | ||
| chainId: '0x1', | ||
| httpsRpc: 'https://first.example', | ||
| currencyName: 'Ether', | ||
| currencyTicker: 'ETH', | ||
| primary: true, | ||
| minimized: true, | ||
| }, | ||
| } | ||
|
|
||
| const secondSnapshot = { | ||
| independentActiveSimulationAddress: '0x2222222222222222222222222222222222222222', | ||
| activeSigningSafeAddress: '0x4444444444444444444444444444444444444444', | ||
| openedPageV2: { page: 'Settings' }, | ||
| useSignersAddressAsActiveAddress: true, | ||
| websiteAccess: [], | ||
| simulationMode: false, | ||
| activeRpcNetwork: { | ||
| name: 'Second network', | ||
| chainId: '0xa', | ||
| httpsRpc: 'https://second.example', | ||
| currencyName: 'Ether', | ||
| currencyTicker: 'ETH', | ||
| primary: true, | ||
| minimized: true, | ||
| }, | ||
| } | ||
|
|
||
| let storageReadCount = 0 | ||
|
|
||
| Object.defineProperty(globalThis, 'browser', { | ||
| configurable: true, | ||
| writable: true, | ||
| value: { | ||
| storage: { | ||
| local: { | ||
| async get(keys: string | readonly string[]) { | ||
| const snapshot = storageReadCount++ === 0 ? firstSnapshot : secondSnapshot | ||
| const requestedKeys = Array.isArray(keys) ? keys : [keys] | ||
| return Object.fromEntries(Object.entries(snapshot).filter(([key]) => requestedKeys.includes(key))) | ||
| }, | ||
| async set() { | ||
| throw new Error('Valid settings should not require repair writes') | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const { getSettings } = await import('../../app/ts/background/settings.js') | ||
|
|
||
| test('getSettings returns one atomic browser storage snapshot', async () => { | ||
| storageReadCount = 0 | ||
|
|
||
| const settings = await getSettings() | ||
|
|
||
| assert.equal(storageReadCount, 1) | ||
| assert.equal(settings.activeSimulationAddress, 0x1111111111111111111111111111111111111111n) | ||
| assert.equal(settings.activeSigningSafeAddress, 0x3333333333333333333333333333333333333333n) | ||
| assert.deepEqual(settings.openedPage, { page: 'Home' }) | ||
| assert.equal(settings.useSignersAddressAsActiveAddress, false) | ||
| assert.equal(settings.simulationMode, true) | ||
| assert.equal(settings.activeRpcNetwork.name, 'First network') | ||
| assert.equal(settings.activeRpcNetwork.chainId, 1n) | ||
| }) |
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 |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| import { describe, test } from 'bun:test' | ||
| import * as assert from 'assert' | ||
| import { isNumberOrBigint } from '../../app/ts/utils/typescript.js' | ||
| import { hasOwnKey, isNumberOrBigint } from '../../app/ts/utils/typescript.js' | ||
|
|
||
| describe('typescript utils', () => { | ||
| test('isNumberOrBigint accepts numeric primitive values', () => { | ||
| assert.equal(isNumberOrBigint(6), true) | ||
| assert.equal(isNumberOrBigint(6n), true) | ||
| assert.equal(isNumberOrBigint('6'), false) | ||
| }) | ||
|
|
||
| test('hasOwnKey rejects properties inherited from Object.prototype', () => { | ||
| const value = { ownProperty: true } | ||
| assert.equal(hasOwnKey(value, 'ownProperty'), true) | ||
| assert.equal(hasOwnKey(value, 'toString'), false) | ||
| assert.equal(hasOwnKey(value, 'constructor'), false) | ||
| }) | ||
| }) |
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.
Minor cohesion concern (low severity, non-blocking): this import pulls the generic object-own-key guard
hasOwnKeyfrommethodHandlers.js, a module whose purpose is RPC-method dispatch. Importing a general-purpose utility from that module into the settings/storage domain extends coupling across module boundaries and is a cohesion smell. This is noted as pre-existing utility misplacement rather than a regression introduced here, but a generic utils module (e.g.utils/typescript.ts) would be a cleaner home forhasOwnKey.