-
Notifications
You must be signed in to change notification settings - Fork 5.4k
test: Use real storage in E2E #38093
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
Changes from all commits
3efffa7
41b2e32
4e55405
3e97ac5
22223d2
fee3bfb
778459d
f64bfeb
17fc776
ab882fb
cccca99
8b82805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,7 @@ | ||
| import log from 'loglevel'; | ||
| import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout'; | ||
| import type { | ||
| MetaMaskStateType, | ||
| BaseStore, | ||
| MetaMaskStorageStructure, | ||
| } from './base-store'; | ||
| import ExtensionStore from './extension-store'; | ||
| import type { MetaMaskStorageStructure } from './base-store'; | ||
|
|
||
| const fetchWithTimeout = getFetchWithTimeout(); | ||
|
|
||
|
|
@@ -13,33 +10,25 @@ const FIXTURE_SERVER_PORT = 12345; | |
| const FIXTURE_SERVER_URL = `http://${FIXTURE_SERVER_HOST}:${FIXTURE_SERVER_PORT}/state.json`; | ||
|
|
||
| /** | ||
| * A read-only network-based storage wrapper | ||
| * Derived class of ExtensionStore that initializes the store using the fixture server. | ||
| */ | ||
| export default class ReadOnlyNetworkStore implements BaseStore { | ||
| export class FixtureExtensionStore extends ExtensionStore { | ||
| #initialized: boolean = false; | ||
|
|
||
| #initializing?: Promise<void>; | ||
|
|
||
| #state: MetaMaskStateType | null = null; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| this.#initializing = this.#init(); | ||
| } | ||
|
|
||
| /** | ||
| * Declares this store as compatible with the current browser | ||
| */ | ||
| isSupported = true; | ||
|
|
||
| /** | ||
| * Initializes by loading state from the network | ||
| */ | ||
| async #init() { | ||
| try { | ||
| const response = await fetchWithTimeout(FIXTURE_SERVER_URL); | ||
|
|
||
| if (response.ok) { | ||
| this.#state = await response.json(); | ||
| const state = await response.json(); | ||
| await super.set(state); | ||
| } else { | ||
| log.debug( | ||
| `Received response with a status of ${response.status} ${response.statusText}`, | ||
|
|
@@ -57,37 +46,23 @@ export default class ReadOnlyNetworkStore implements BaseStore { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns state | ||
| */ | ||
| async get() { | ||
| async get(): Promise<MetaMaskStorageStructure | null> { | ||
FrederikBolding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!this.#initialized) { | ||
| await this.#initializing; | ||
| } | ||
| return this.#state; | ||
| return super.get(); | ||
| } | ||
|
|
||
| /** | ||
| * Overwrite in-memory copy of state. | ||
| * | ||
| * @param data - The data to set | ||
| */ | ||
| async set(data: Required<MetaMaskStorageStructure>): Promise<void> { | ||
| if (!data) { | ||
| throw new Error('MetaMask - updated state is missing'); | ||
| } | ||
| if (!this.#initialized) { | ||
| await this.#initializing; | ||
| } | ||
| this.#state = data; | ||
| return super.set(data); | ||
| } | ||
|
|
||
| /** | ||
| * Resets data to its initial state. | ||
| */ | ||
| async reset(): Promise<void> { | ||
| this.#initialized = false; | ||
| this.#state = null; | ||
| await super.reset(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Race condition in reset methodThe
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this matters in practice, but can fix it if anyone feels strongly about it |
||
| this.#initializing = this.#init(); | ||
| await this.#initializing; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.