-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throw/warn on mismatch of client version and supported version (#…
- Loading branch information
Showing
10 changed files
with
202 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-ts/errors": minor | ||
"@fuel-ts/providers": minor | ||
--- | ||
|
||
Check mismatch of fuel client version and supported version: throw on major/minor mismatch, warn on patch mismatch |
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
65 changes: 65 additions & 0 deletions
65
packages/versions/src/lib/checkFuelCoreVersionCompatibility.test.ts
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,65 @@ | ||
import { checkFuelCoreVersionCompatibility } from './checkFuelCoreVersionCompatibility'; | ||
import * as getSupportedVersionsMod from './getSupportedVersions'; | ||
|
||
describe('getDifferenceToUserFuelCoreVersion', () => { | ||
afterAll(() => jest.restoreAllMocks()); | ||
|
||
it('should validate all possible version mismatches', () => { | ||
const supportedVersion = '0.1.2'; | ||
|
||
jest.spyOn(getSupportedVersionsMod, 'getSupportedVersions').mockImplementation(() => ({ | ||
FUELS: '1', // not under test | ||
FORC: '1', // not under test | ||
FUEL_CORE: supportedVersion, | ||
})); | ||
|
||
expect(checkFuelCoreVersionCompatibility('1.1.2')).toEqual({ | ||
isMajorSupported: false, | ||
isMinorSupported: true, | ||
isPatchSupported: true, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('1.2.2')).toEqual({ | ||
isMajorSupported: false, | ||
isMinorSupported: false, | ||
isPatchSupported: true, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('1.1.3')).toEqual({ | ||
isMajorSupported: false, | ||
isMinorSupported: true, | ||
isPatchSupported: false, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('0.2.2')).toEqual({ | ||
isMajorSupported: true, | ||
isMinorSupported: false, | ||
isPatchSupported: true, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('0.2.3')).toEqual({ | ||
isMajorSupported: true, | ||
isMinorSupported: false, | ||
isPatchSupported: false, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('0.1.3')).toEqual({ | ||
isMajorSupported: true, | ||
isMinorSupported: true, | ||
isPatchSupported: false, | ||
supportedVersion, | ||
}); | ||
|
||
expect(checkFuelCoreVersionCompatibility('0.1.2')).toEqual({ | ||
isMajorSupported: true, | ||
isMinorSupported: true, | ||
isPatchSupported: true, | ||
supportedVersion, | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/versions/src/lib/checkFuelCoreVersionCompatibility.ts
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,22 @@ | ||
import semver from 'semver'; | ||
|
||
import { getSupportedVersions } from './getSupportedVersions'; | ||
|
||
export function checkFuelCoreVersionCompatibility(networkVersion: string) { | ||
const { FUEL_CORE: supportedVersion } = getSupportedVersions(); | ||
|
||
const networkMajor = semver.major(networkVersion); | ||
const networkMinor = semver.minor(networkVersion); | ||
const networkPatch = semver.patch(networkVersion); | ||
|
||
const supportedMajor = semver.major(supportedVersion); | ||
const supportedMinor = semver.minor(supportedVersion); | ||
const supportedPatch = semver.patch(supportedVersion); | ||
|
||
return { | ||
supportedVersion, | ||
isMajorSupported: networkMajor === supportedMajor, | ||
isMinorSupported: networkMinor === supportedMinor, | ||
isPatchSupported: networkPatch === supportedPatch, | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.