Skip to content

Commit 6486e4b

Browse files
authored
Merge pull request #1384 from starknet-io/full-speck-version
feat: full spec version implementation
2 parents 960981c + 89b4f83 commit 6486e4b

File tree

14 files changed

+518
-256
lines changed

14 files changed

+518
-256
lines changed

__tests__/config/helpers/strategyResolver.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class StrategyResolver {
7272
process.env.TX_VERSION = process.env.TX_VERSION ?? DEFAULT_GLOBAL_CONFIG.transactionVersion;
7373
}
7474

75-
async getSpecVersion() {
75+
async getNodeSpecVersion() {
7676
const tempProv = new RpcProvider({
7777
nodeUrl: process.env.TEST_RPC_URL,
7878
});
7979

8080
process.env.RPC_SPEC_VERSION = await tempProv.getSpecVersion();
81-
process.env.RPC_FULL_SPEC_VERSION = await tempProv.getSpecificationVersion();
81+
console.log('Detected Spec Version:', process.env.RPC_SPEC_VERSION);
8282
}
8383

8484
async logConfigInfo() {
@@ -96,8 +96,7 @@ class StrategyResolver {
9696
IS_DEVNET: process.env.IS_DEVNET,
9797
IS_RPC: process.env.IS_RPC,
9898
IS_TESTNET: process.env.IS_TESTNET,
99-
'Rpc node spec version': process.env.RPC_SPEC_VERSION,
100-
'Rpc node full spec v.': process.env.RPC_FULL_SPEC_VERSION,
99+
'Detected Spec Version': process.env.RPC_SPEC_VERSION,
101100
});
102101

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

150149
this.defineTestTransactionVersion();
151-
await this.getSpecVersion();
150+
await this.getNodeSpecVersion();
152151

153152
this.logConfigInfo();
154153
}

__tests__/defaultProvider.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
BlockNumber,
44
CallData,
55
GetBlockResponse,
6+
isPendingStateUpdate,
67
LibraryError,
78
Provider,
8-
provider,
99
ProviderInterface,
1010
stark,
1111
} from '../src';
@@ -20,8 +20,6 @@ import {
2020
} from './config/fixtures';
2121
import { initializeMatcher } from './config/schema';
2222

23-
const { isPendingStateUpdate } = provider;
24-
2523
describe('defaultProvider', () => {
2624
let testProvider: ProviderInterface;
2725
let account: Account;

__tests__/rpcProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import {
3030
cairo,
3131
stark,
3232
waitForTransactionOptions,
33+
isVersion,
3334
} from '../src';
3435
import { StarknetChainId } from '../src/global/constants';
3536
import { felt, uint256 } from '../src/utils/calldata/cairo';
3637
import { toBigInt, toHexString } from '../src/utils/num';
37-
import { isVersion } from '../src/utils/provider';
3838
import { isBoolean } from '../src/utils/typed';
3939
import { RpcProvider as BaseRpcProvider } from '../src/provider/rpc';
4040
import { RpcProvider as ExtendedRpcProvider } from '../src/provider/extensions/default';
@@ -75,7 +75,7 @@ describeIfRpc('RPCProvider', () => {
7575
const rawResult = await channel.fetch('starknet_specVersion');
7676
const j = await rawResult.json();
7777
expect(channel.readSpecVersion()).toBeDefined();
78-
expect(isVersion(j.result, await channel.getSpecVersion())).toBeTruthy();
78+
expect(isVersion(j.result, await channel.setUpSpecVersion())).toBeTruthy();
7979
});
8080

8181
test('baseFetch override', async () => {

__tests__/utils/resolve.test.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { isVersion, toAnyPatchVersion, isSupportedSpecVersion, constants } from '../../src';
2+
3+
describe('isVersion', () => {
4+
it('matches exact versions', () => {
5+
expect(isVersion('0.7.0', '0.7.0')).toBe(true);
6+
expect(isVersion('0.7', '0.7')).toBe(true);
7+
expect(isVersion('1.2.3', '1.2.3')).toBe(true);
8+
expect(isVersion('0.7', '0.8')).toBe(false);
9+
expect(isVersion('0.7.0', '0.7.1')).toBe(false);
10+
expect(isVersion('0.7.0', '0.8.0')).toBe(false);
11+
expect(isVersion('1.0.0', '2.0.0')).toBe(false);
12+
});
13+
14+
it('handles wildcard in major version', () => {
15+
expect(isVersion('*.7.0', '0.7.0')).toBe(true);
16+
expect(isVersion('*.7.0', '1.7.0')).toBe(true);
17+
expect(isVersion('*.7.0', '2.7.0')).toBe(true);
18+
expect(isVersion('*.7.0', '0.8.0')).toBe(false);
19+
});
20+
21+
it('handles wildcard in minor version', () => {
22+
expect(isVersion('0.*.0', '0.7.0')).toBe(true);
23+
expect(isVersion('0.*.0', '0.8.0')).toBe(true);
24+
expect(isVersion('0.*.0', '0.9.0')).toBe(true);
25+
expect(isVersion('0.*.0', '1.7.0')).toBe(false);
26+
});
27+
28+
it('handles wildcard in patch version', () => {
29+
expect(isVersion('0.7.*', '0.7.0')).toBe(true);
30+
expect(isVersion('0.7.*', '0.7.1')).toBe(true);
31+
expect(isVersion('0.7', '0.7.1')).toBe(true);
32+
expect(isVersion('0.7.*', '0.7.2')).toBe(true);
33+
expect(isVersion('0.8.*', '0.8.1-rc2')).toBe(true);
34+
expect(isVersion('0.8.*', '0.8')).toBe(true);
35+
expect(isVersion('0.8', '0.8.1')).toBe(true);
36+
expect(isVersion('0.7.*', '0.8.1-rc3')).toBe(false);
37+
expect(isVersion('0.7.*', '0.8.0')).toBe(false);
38+
expect(isVersion('0.7', '0.8.1')).toBe(false);
39+
});
40+
41+
it('handles multiple wildcards', () => {
42+
expect(isVersion('*.*.0', '0.7.0')).toBe(true);
43+
expect(isVersion('*.*.0', '1.8.0')).toBe(true);
44+
expect(isVersion('*.*.0', '0.7.1')).toBe(false);
45+
expect(isVersion('0.*.*', '0.7.0')).toBe(true);
46+
expect(isVersion('0.*.*', '0.8.1')).toBe(true);
47+
expect(isVersion('0.*.*', '1.7.0')).toBe(false);
48+
expect(isVersion('*.*.*', '0.7.0')).toBe(true);
49+
expect(isVersion('*.*.*', '1.8.2')).toBe(true);
50+
expect(isVersion('*.*.*', '2.3.4')).toBe(true);
51+
expect(isVersion('', '2.3.4')).toBe(false);
52+
expect(isVersion('*', '2.3.4')).toBe(true);
53+
expect(isVersion('*.3', '2.3.4')).toBe(true);
54+
expect(isVersion('*.2', '2.3.4')).toBe(false);
55+
expect(isVersion('*.3.5', '2.3.4')).toBe(false);
56+
expect(isVersion('*.3.4', '2.3.4')).toBe(true);
57+
});
58+
});
59+
60+
describe('toAnyPatchVersion', () => {
61+
it('converts version strings to wildcard patch versions', () => {
62+
expect(toAnyPatchVersion('0.7.0')).toBe('0.7.*');
63+
expect(toAnyPatchVersion('1.2.3')).toBe('1.2.*');
64+
expect(toAnyPatchVersion('0.8')).toBe('0.8.*');
65+
expect(toAnyPatchVersion('2.0')).toBe('2.0.*');
66+
});
67+
68+
it('handles invalid or empty version strings', () => {
69+
expect(toAnyPatchVersion('')).toBe('');
70+
expect(toAnyPatchVersion('invalid')).toBe('invalid');
71+
expect(toAnyPatchVersion('0')).toBe('0.*');
72+
});
73+
74+
it('handles already wildcarded versions', () => {
75+
expect(toAnyPatchVersion('0.7.*')).toBe('0.7.*');
76+
expect(toAnyPatchVersion('1.*')).toBe('1.*');
77+
expect(toAnyPatchVersion('*')).toBe('*');
78+
});
79+
});
80+
81+
describe('isSupportedSpecVersion', () => {
82+
it('returns true for supported spec versions', () => {
83+
expect(isSupportedSpecVersion('0.7')).toBe(true);
84+
expect(isSupportedSpecVersion('0.8')).toBe(true);
85+
expect(isSupportedSpecVersion('1.0')).toBe(true);
86+
});
87+
88+
it('returns false for unsupported spec versions', () => {
89+
expect(isSupportedSpecVersion('0.6')).toBe(false);
90+
expect(isSupportedSpecVersion('2.0')).toBe(false);
91+
expect(isSupportedSpecVersion('')).toBe(false);
92+
expect(isSupportedSpecVersion('invalid')).toBe(false);
93+
});
94+
95+
it('handles wildcard and partial versions', () => {
96+
expect(isSupportedSpecVersion('*')).toBe(false);
97+
expect(isSupportedSpecVersion('0.*')).toBe(false);
98+
expect(isSupportedSpecVersion('*.8')).toBe(false);
99+
});
100+
101+
describe('isSupportedSpecVersion', () => {
102+
it('returns true for exact supported version', () => {
103+
expect(isSupportedSpecVersion(constants.SupportedRpcVersion.v0_7_1)).toBe(true);
104+
});
105+
106+
it('returns false for unsupported version', () => {
107+
expect(isSupportedSpecVersion('9.9.9')).toBe(false);
108+
});
109+
110+
it('returns true for supported version with allowAnyPatchVersion=true', () => {
111+
expect(isSupportedSpecVersion('0.7.1', { allowAnyPatchVersion: true })).toBe(true);
112+
});
113+
114+
it('returns false for supported version with allowAnyPatchVersion=false and mismatched patch', () => {
115+
expect(isSupportedSpecVersion('0.7.444', { allowAnyPatchVersion: false })).toBe(false);
116+
});
117+
118+
it('returns true for supported version with wildcard in SupportedRpcVersion', () => {
119+
// Simulate a SupportedRpcVersion with a wildcard
120+
expect(isSupportedSpecVersion('0.7.123', { allowAnyPatchVersion: true })).toBe(true);
121+
});
122+
123+
it('returns false for empty version', () => {
124+
expect(isSupportedSpecVersion('')).toBe(false);
125+
});
126+
127+
it('returns false for malformed version', () => {
128+
expect(isSupportedSpecVersion('abc.def.ghi')).toBe(false);
129+
});
130+
131+
it('returns true for supported version with allowAnyPatchVersion explicitly set to true', () => {
132+
expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: true })).toBe(true);
133+
});
134+
135+
it('returns false for supported version with allowAnyPatchVersion explicitly set to false', () => {
136+
expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: false })).toBe(false);
137+
});
138+
139+
it('returns true for supported version when options is omitted (defaults to false)', () => {
140+
expect(isSupportedSpecVersion('0.7.1')).toBe(true);
141+
expect(isSupportedSpecVersion('0.7.0')).toBe(false);
142+
});
143+
144+
it('returns false for unsupported version regardless of options', () => {
145+
expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: true })).toBe(false);
146+
expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: false })).toBe(false);
147+
});
148+
});
149+
});

0 commit comments

Comments
 (0)