Skip to content

feat: full spec version implementation #1384

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions __tests__/config/helpers/strategyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class StrategyResolver {
process.env.TX_VERSION = process.env.TX_VERSION ?? DEFAULT_GLOBAL_CONFIG.transactionVersion;
}

async getSpecVersion() {
async getNodeSpecVersion() {
const tempProv = new RpcProvider({
nodeUrl: process.env.TEST_RPC_URL,
});

process.env.RPC_SPEC_VERSION = await tempProv.getSpecVersion();
process.env.RPC_FULL_SPEC_VERSION = await tempProv.getSpecificationVersion();
console.log('Detected Spec Version:', process.env.RPC_SPEC_VERSION);
}

async logConfigInfo() {
Expand All @@ -96,8 +96,7 @@ class StrategyResolver {
IS_DEVNET: process.env.IS_DEVNET,
IS_RPC: process.env.IS_RPC,
IS_TESTNET: process.env.IS_TESTNET,
'Rpc node spec version': process.env.RPC_SPEC_VERSION,
'Rpc node full spec v.': process.env.RPC_FULL_SPEC_VERSION,
'Detected Spec Version': process.env.RPC_SPEC_VERSION,
});

console.log('Global Test Environment is Ready');
Expand Down Expand Up @@ -148,7 +147,7 @@ class StrategyResolver {
if (!this.hasAllAccountEnvs) console.error('Test Setup Environment is NOT Ready');

this.defineTestTransactionVersion();
await this.getSpecVersion();
await this.getNodeSpecVersion();

this.logConfigInfo();
}
Expand Down
4 changes: 1 addition & 3 deletions __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
BlockNumber,
CallData,
GetBlockResponse,
isPendingStateUpdate,
LibraryError,
Provider,
provider,
ProviderInterface,
stark,
} from '../src';
Expand All @@ -20,8 +20,6 @@ import {
} from './config/fixtures';
import { initializeMatcher } from './config/schema';

const { isPendingStateUpdate } = provider;

describe('defaultProvider', () => {
let testProvider: ProviderInterface;
let account: Account;
Expand Down
4 changes: 2 additions & 2 deletions __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import {
cairo,
stark,
waitForTransactionOptions,
isVersion,
} from '../src';
import { StarknetChainId } from '../src/global/constants';
import { felt, uint256 } from '../src/utils/calldata/cairo';
import { toBigInt, toHexString } from '../src/utils/num';
import { isVersion } from '../src/utils/provider';
import { isBoolean } from '../src/utils/typed';
import { RpcProvider as BaseRpcProvider } from '../src/provider/rpc';
import { RpcProvider as ExtendedRpcProvider } from '../src/provider/extensions/default';
Expand Down Expand Up @@ -75,7 +75,7 @@ describeIfRpc('RPCProvider', () => {
const rawResult = await channel.fetch('starknet_specVersion');
const j = await rawResult.json();
expect(channel.readSpecVersion()).toBeDefined();
expect(isVersion(j.result, await channel.getSpecVersion())).toBeTruthy();
expect(isVersion(j.result, await channel.setupSpecVersion())).toBeTruthy();
});

test('baseFetch override', async () => {
Expand Down
149 changes: 149 additions & 0 deletions __tests__/utils/resolve.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { isVersion, toAnyPatchVersion, isSupportedSpecVersion, constants } from '../../src';

describe('isVersion', () => {
it('matches exact versions', () => {
expect(isVersion('0.7.0', '0.7.0')).toBe(true);
expect(isVersion('0.7', '0.7')).toBe(true);
expect(isVersion('1.2.3', '1.2.3')).toBe(true);
expect(isVersion('0.7', '0.8')).toBe(false);
expect(isVersion('0.7.0', '0.7.1')).toBe(false);
expect(isVersion('0.7.0', '0.8.0')).toBe(false);
expect(isVersion('1.0.0', '2.0.0')).toBe(false);
});

it('handles wildcard in major version', () => {
expect(isVersion('*.7.0', '0.7.0')).toBe(true);
expect(isVersion('*.7.0', '1.7.0')).toBe(true);
expect(isVersion('*.7.0', '2.7.0')).toBe(true);
expect(isVersion('*.7.0', '0.8.0')).toBe(false);
});

it('handles wildcard in minor version', () => {
expect(isVersion('0.*.0', '0.7.0')).toBe(true);
expect(isVersion('0.*.0', '0.8.0')).toBe(true);
expect(isVersion('0.*.0', '0.9.0')).toBe(true);
expect(isVersion('0.*.0', '1.7.0')).toBe(false);
});

it('handles wildcard in patch version', () => {
expect(isVersion('0.7.*', '0.7.0')).toBe(true);
expect(isVersion('0.7.*', '0.7.1')).toBe(true);
expect(isVersion('0.7', '0.7.1')).toBe(true);
expect(isVersion('0.7.*', '0.7.2')).toBe(true);
expect(isVersion('0.8.*', '0.8.1-rc2')).toBe(true);
expect(isVersion('0.8.*', '0.8')).toBe(true);
expect(isVersion('0.8', '0.8.1')).toBe(true);
expect(isVersion('0.7.*', '0.8.1-rc3')).toBe(false);
expect(isVersion('0.7.*', '0.8.0')).toBe(false);
expect(isVersion('0.7', '0.8.1')).toBe(false);
});

it('handles multiple wildcards', () => {
expect(isVersion('*.*.0', '0.7.0')).toBe(true);
expect(isVersion('*.*.0', '1.8.0')).toBe(true);
expect(isVersion('*.*.0', '0.7.1')).toBe(false);
expect(isVersion('0.*.*', '0.7.0')).toBe(true);
expect(isVersion('0.*.*', '0.8.1')).toBe(true);
expect(isVersion('0.*.*', '1.7.0')).toBe(false);
expect(isVersion('*.*.*', '0.7.0')).toBe(true);
expect(isVersion('*.*.*', '1.8.2')).toBe(true);
expect(isVersion('*.*.*', '2.3.4')).toBe(true);
expect(isVersion('', '2.3.4')).toBe(false);
expect(isVersion('*', '2.3.4')).toBe(true);
expect(isVersion('*.3', '2.3.4')).toBe(true);
expect(isVersion('*.2', '2.3.4')).toBe(false);
expect(isVersion('*.3.5', '2.3.4')).toBe(false);
expect(isVersion('*.3.4', '2.3.4')).toBe(true);
});
});

describe('toAnyPatchVersion', () => {
it('converts version strings to wildcard patch versions', () => {
expect(toAnyPatchVersion('0.7.0')).toBe('0.7.*');
expect(toAnyPatchVersion('1.2.3')).toBe('1.2.*');
expect(toAnyPatchVersion('0.8')).toBe('0.8.*');
expect(toAnyPatchVersion('2.0')).toBe('2.0.*');
});

it('handles invalid or empty version strings', () => {
expect(toAnyPatchVersion('')).toBe('');
expect(toAnyPatchVersion('invalid')).toBe('invalid');
expect(toAnyPatchVersion('0')).toBe('0.*');
});

it('handles already wildcarded versions', () => {
expect(toAnyPatchVersion('0.7.*')).toBe('0.7.*');
expect(toAnyPatchVersion('1.*')).toBe('1.*');
expect(toAnyPatchVersion('*')).toBe('*');
});
});

describe('isSupportedSpecVersion', () => {
it('returns true for supported spec versions', () => {
expect(isSupportedSpecVersion('0.7')).toBe(true);
expect(isSupportedSpecVersion('0.8')).toBe(true);
expect(isSupportedSpecVersion('1.0')).toBe(true);
});

it('returns false for unsupported spec versions', () => {
expect(isSupportedSpecVersion('0.6')).toBe(false);
expect(isSupportedSpecVersion('2.0')).toBe(false);
expect(isSupportedSpecVersion('')).toBe(false);
expect(isSupportedSpecVersion('invalid')).toBe(false);
});

it('handles wildcard and partial versions', () => {
expect(isSupportedSpecVersion('*')).toBe(false);
expect(isSupportedSpecVersion('0.*')).toBe(false);
expect(isSupportedSpecVersion('*.8')).toBe(false);
});

describe('isSupportedSpecVersion', () => {
it('returns true for exact supported version', () => {
expect(isSupportedSpecVersion(constants.SupportedRpcVersion.v0_7_1)).toBe(true);
});

it('returns false for unsupported version', () => {
expect(isSupportedSpecVersion('9.9.9')).toBe(false);
});

it('returns true for supported version with allowAnyPatchVersion=true', () => {
expect(isSupportedSpecVersion('0.7.1', { allowAnyPatchVersion: true })).toBe(true);
});

it('returns false for supported version with allowAnyPatchVersion=false and mismatched patch', () => {
expect(isSupportedSpecVersion('0.7.444', { allowAnyPatchVersion: false })).toBe(false);
});

it('returns true for supported version with wildcard in SupportedRpcVersion', () => {
// Simulate a SupportedRpcVersion with a wildcard
expect(isSupportedSpecVersion('0.7.123', { allowAnyPatchVersion: true })).toBe(true);
});

it('returns false for empty version', () => {
expect(isSupportedSpecVersion('')).toBe(false);
});

it('returns false for malformed version', () => {
expect(isSupportedSpecVersion('abc.def.ghi')).toBe(false);
});

it('returns true for supported version with allowAnyPatchVersion explicitly set to true', () => {
expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: true })).toBe(true);
});

it('returns false for supported version with allowAnyPatchVersion explicitly set to false', () => {
expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: false })).toBe(false);
});

it('returns true for supported version when options is omitted (defaults to false)', () => {
expect(isSupportedSpecVersion('0.7.1')).toBe(true);
expect(isSupportedSpecVersion('0.7.0')).toBe(false);
});

it('returns false for unsupported version regardless of options', () => {
expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: true })).toBe(false);
expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: false })).toBe(false);
});
});
});
Loading
Loading