Skip to content

Commit

Permalink
feat: 馃幐 Update supported spec version to 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper committed Jan 25, 2023
1 parent 86edc56 commit 0ef1eee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 28 additions & 8 deletions src/utils/__tests__/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { tuple } from '~/types/utils';
import { MAX_TICKER_LENGTH } from '~/utils/constants';
import * as utilsConversionModule from '~/utils/conversion';

import { SUPPORTED_NODE_VERSION_RANGE, SUPPORTED_SPEC_VERSION_RANGE } from '../constants';
import {
asAccount,
assertAddressValid,
Expand Down Expand Up @@ -1131,6 +1132,18 @@ describe('assertExpectedChainVersion', () => {
let client: MockWebSocket;
let warnSpy: jest.SpyInstance;

const getSpecVersion = (spec: string): string =>
`${+spec
.split('.')
.map(number => `00${number}`.slice(-3))
.join('')}`;

const getMismatchedVersion = (version: string, versionIndex = 2): string =>
version
.split('.')
.map((number, index) => (index === versionIndex ? +number + 1 : number))
.join('.');

beforeAll(() => {
dsMockUtils.initMocks();
warnSpy = jest.spyOn(console, 'warn');
Expand All @@ -1157,7 +1170,8 @@ describe('assertExpectedChainVersion', () => {

it('should throw an error given a major RPC node version mismatch', () => {
const signal = assertExpectedChainVersion('ws://example.com');
client.sendRpcVersion('3.0.0');
const mismatchedVersion = getMismatchedVersion(SUPPORTED_NODE_VERSION_RANGE, 0);
client.sendRpcVersion(mismatchedVersion);
const expectedError = new PolymeshError({
code: ErrorCode.FatalError,
message: 'Unsupported Polymesh RPC node version. Please upgrade the SDK',
Expand All @@ -1167,17 +1181,22 @@ describe('assertExpectedChainVersion', () => {

it('should log a warning given a minor or patch RPC node version mismatch', async () => {
const signal = assertExpectedChainVersion('ws://example.com');
client.sendSpecVersion('5001030');
client.sendRpcVersion('5.1.7');

client.sendSpecVersion(getSpecVersion(SUPPORTED_SPEC_VERSION_RANGE));

const mockRpcVersion = getMismatchedVersion(SUPPORTED_NODE_VERSION_RANGE);
client.sendRpcVersion(mockRpcVersion);

await signal;
expect(warnSpy).toHaveBeenCalledWith(
'This version of the SDK supports Polymesh RPC node version 5.1.3. The node is at version 5.1.7. Please upgrade the SDK'
`This version of the SDK supports Polymesh RPC node version ${SUPPORTED_NODE_VERSION_RANGE}. The node is at version ${mockRpcVersion}. Please upgrade the SDK`
);
});

it('should throw an error given a major chain spec version mismatch', () => {
const signal = assertExpectedChainVersion('ws://example.com');
client.sendSpecVersion('9000000');
const mismatchedSpecVersion = getMismatchedVersion(SUPPORTED_SPEC_VERSION_RANGE, 0);
client.sendSpecVersion(getSpecVersion(mismatchedSpecVersion));
const expectedError = new PolymeshError({
code: ErrorCode.FatalError,
message: 'Unsupported Polymesh chain spec version. Please upgrade the SDK',
Expand All @@ -1187,11 +1206,12 @@ describe('assertExpectedChainVersion', () => {

it('should log a warning given a minor or patch chain spec version mismatch', async () => {
const signal = assertExpectedChainVersion('ws://example.com');
client.sendSpecVersion('5001007');
client.sendRpcVersion('5.1.1');
const mockSpecVersion = getMismatchedVersion(SUPPORTED_SPEC_VERSION_RANGE);
client.sendSpecVersion(getSpecVersion(mockSpecVersion));
client.sendRpcVersion(SUPPORTED_NODE_VERSION_RANGE);
await signal;
expect(warnSpy).toHaveBeenCalledWith(
'This version of the SDK supports Polymesh chain spec version 5.1.30. The chain spec is at version 5.1.7. Please upgrade the SDK'
`This version of the SDK supports Polymesh chain spec version ${SUPPORTED_SPEC_VERSION_RANGE}. The chain spec is at version ${mockSpecVersion}. Please upgrade the SDK`
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ export const ROOT_TYPES = rootTypes;
/**
* The Polymesh RPC node version range that is compatible with this version of the SDK
*/
export const SUPPORTED_NODE_VERSION_RANGE = '5.1.3';
export const SUPPORTED_NODE_VERSION_RANGE = '5.2.0';

/**
* The Polymesh chain spec version range that is compatible with this version of the SDK
*/
export const SUPPORTED_SPEC_VERSION_RANGE = '5.1.30';
export const SUPPORTED_SPEC_VERSION_RANGE = '5.2.0';

export const SYSTEM_VERSION_RPC_CALL = {
jsonrpc: '2.0',
Expand Down

0 comments on commit 0ef1eee

Please sign in to comment.