-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: migrate from decommissioned ipfs gateway to new one #11985
Open
NicolasMassart
wants to merge
3
commits into
main
Choose a base branch
from
fix/11692_ipfs_state_migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−18
Open
Changes from all commits
Commits
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 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 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 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 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 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 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 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 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 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 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,119 @@ | ||
import migrate from './056'; | ||
import { merge } from 'lodash'; | ||
import { captureException } from '@sentry/react-native'; | ||
import initialRootState from '../../util/test/initial-root-state'; | ||
import mockedEngine from '../../core/__mocks__/MockedEngine'; | ||
|
||
jest.mock('@sentry/react-native', () => ({ | ||
captureException: jest.fn(), | ||
})); | ||
const mockedCaptureException = jest.mocked(captureException); | ||
|
||
jest.mock('../../core/Engine', () => ({ | ||
init: () => mockedEngine.init(), | ||
})); | ||
|
||
describe('Migration #56', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const invalidStates = [ | ||
{ | ||
state: null, | ||
errorMessage: "FATAL ERROR: Migration 56: Invalid state error: 'object'", | ||
scenario: 'state is invalid', | ||
}, | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: null, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 56: Invalid engine state error: 'object'", | ||
scenario: 'engine state is invalid', | ||
}, | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: { | ||
backgroundState: null, | ||
}, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 56: Invalid engine backgroundState error: 'object'", | ||
scenario: 'backgroundState is invalid', | ||
}, | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: { | ||
backgroundState: { PreferencesController: null }, | ||
}, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 56: Invalid PreferencesController state error: 'object'", | ||
scenario: 'PreferencesController is invalid', | ||
}, | ||
]; | ||
|
||
for (const { errorMessage, scenario, state } of invalidStates) { | ||
it(`should capture exception if ${scenario}`, () => { | ||
const newState = migrate(state); | ||
|
||
expect(newState).toStrictEqual(state); | ||
expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error)); | ||
expect(mockedCaptureException.mock.calls[0][0].message).toBe( | ||
errorMessage, | ||
); | ||
}); | ||
} | ||
|
||
it('updates decomissioned ipfsGateway to new default', () => { | ||
const oldState = { | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
ipfsGateway: 'https://cloudflare-ipfs.com/ipfs/', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedState = { | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
ipfsGateway: 'https://dweb.link/ipfs/', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const migratedState = migrate(oldState); | ||
expect(migratedState).toStrictEqual(expectedState); | ||
}); | ||
|
||
it('does not change ipfsGateway if not decomissioned', () => { | ||
const oldState = { | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
ipfsGateway: 'https://ipfs.io/ipfs/', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedState = { | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
ipfsGateway: 'https://ipfs.io/ipfs/', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const migratedState = migrate(oldState); | ||
expect(migratedState).toStrictEqual(expectedState); | ||
}); | ||
}); |
This file contains 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,31 @@ | ||
import { captureException } from '@sentry/react-native'; | ||
import { isObject } from '@metamask/utils'; | ||
import { ensureValidState } from './util'; | ||
|
||
export default function migrate(state: unknown) { | ||
if (!ensureValidState(state, 56)) { | ||
// Increment the migration number as appropriate | ||
return state; | ||
} | ||
|
||
const preferencesController = | ||
state.engine.backgroundState.PreferencesController; | ||
|
||
if (!isObject(preferencesController)) { | ||
captureException( | ||
new Error( | ||
`FATAL ERROR: Migration 56: Invalid PreferencesController state error: '${typeof preferencesController}'`, | ||
), | ||
); | ||
return state; | ||
} | ||
|
||
const decommisionedIpfsGateway = 'https://cloudflare-ipfs.com/ipfs/'; | ||
const newDefaultIpfsGateway = 'https://dweb.link/ipfs/'; | ||
|
||
if (decommisionedIpfsGateway === preferencesController?.ipfsGateway) { | ||
preferencesController.ipfsGateway = newDefaultIpfsGateway; | ||
} | ||
// Return the modified state | ||
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. NIT: I think we can remove this comment 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. Same as above |
||
return state; | ||
} |
This file contains 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 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 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 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 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.
NIT: I think we do not need this comment
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.
I just copied it from previous migration, looks useful reminder and not doing any arm...