Skip to content

Commit 4d08021

Browse files
authored
Merge pull request #1365 from starknet-io/beta
2 parents 83a59c3 + ffe4895 commit 4d08021

File tree

101 files changed

+3937
-4129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3937
-4129
lines changed

CHANGELOG.md

+43
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
# [7.0.0-beta.4](https://github.com/starknet-io/starknet.js/compare/v7.0.0-beta.3...v7.0.0-beta.4) (2025-03-28)
2+
3+
### Bug Fixes
4+
5+
- repair snip-12 enum type nested dependency ([#1289](https://github.com/starknet-io/starknet.js/issues/1289)) ([1cd4219](https://github.com/starknet-io/starknet.js/commit/1cd4219df5e61a676bc58ba8c8673269695fc2db))
6+
7+
### Features
8+
9+
- drop fetch-cookie dependency ([9a57daf](https://github.com/starknet-io/starknet.js/commit/9a57dafce473432df7040f68e0824e9e78f6e215))
10+
- drop isomorphic-fetch dependency ([9da0083](https://github.com/starknet-io/starknet.js/commit/9da0083d2084b0bd9ec7da06ea9a80f267f4e397))
11+
- prune deprecated functionalities ([cbd18f5](https://github.com/starknet-io/starknet.js/commit/cbd18f59fb0749c558ba4eabc0f094464941b088))
12+
13+
### BREAKING CHANGES
14+
15+
- Removed multiple functionalities that have been marked as deprecated
16+
17+
# [7.0.0-beta.3](https://github.com/starknet-io/starknet.js/compare/v7.0.0-beta.2...v7.0.0-beta.3) (2025-03-13)
18+
19+
### Features
20+
21+
- add simulate and estimate fee utility methods for outside execution ([#1327](https://github.com/starknet-io/starknet.js/issues/1327)) ([3668b01](https://github.com/starknet-io/starknet.js/commit/3668b01c4f63969bb0770ee6120fe3eac72d0335))
22+
- implement cairo fixed array support ([#1310](https://github.com/starknet-io/starknet.js/issues/1310)) ([45df63e](https://github.com/starknet-io/starknet.js/commit/45df63e7bb7f7cb2de2e98900387b1c44a95f257))
23+
24+
# [7.0.0-beta.2](https://github.com/starknet-io/starknet.js/compare/v7.0.0-beta.1...v7.0.0-beta.2) (2025-03-10)
25+
26+
### Bug Fixes
27+
28+
- contract withOptions Fix/1252 ([#1255](https://github.com/starknet-io/starknet.js/issues/1255)) ([b59952e](https://github.com/starknet-io/starknet.js/commit/b59952e74baf82641d6028c96625db104049c02e))
29+
- update ws impl, add TEST_WS_URL, update token constants ([411eeec](https://github.com/starknet-io/starknet.js/commit/411eeec1df6a38358f28612260066b38fc942957))
30+
31+
### Features
32+
33+
- the WebSockets ([#1251](https://github.com/starknet-io/starknet.js/issues/1251)) ([fabca27](https://github.com/starknet-io/starknet.js/commit/fabca27a7a3e398030a99cf8d78bffa51cebfe9a)), closes [#1272](https://github.com/starknet-io/starknet.js/issues/1272)
34+
- v7 fee, new methods, tests ([#1337](https://github.com/starknet-io/starknet.js/issues/1337)) ([00743de](https://github.com/starknet-io/starknet.js/commit/00743de2cad5375a558844646f11b4adef15188b))
35+
36+
# [7.0.0-beta.1](https://github.com/starknet-io/starknet.js/compare/v6.24.0-beta.1...v7.0.0-beta.1) (2025-03-04)
37+
38+
- Implement RPC 0.8 and V3 transactions ([#1328](https://github.com/starknet-io/starknet.js/issues/1328)) ([316ae27](https://github.com/starknet-io/starknet.js/commit/316ae2789376368dcffe653ce4817eebf0a63d97))
39+
40+
### BREAKING CHANGES
41+
42+
- Library defaults to RPC 0.8 with the corresponding API changes, dropped RPC 0.6 support
43+
144
## [6.24.1](https://github.com/starknet-io/starknet.js/compare/v6.24.0...v6.24.1) (2025-03-20)
245

346
### Bug Fixes

__tests__/WebSocketChannel.test.ts

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import { WebSocket } from 'isows';
2+
3+
import { Provider, WSSubscriptions, WebSocketChannel } from '../src';
4+
import { StarknetChainId } from '../src/global/constants';
5+
import { getTestAccount, getTestProvider, STRKtokenAddress, TEST_WS_URL } from './config/fixtures';
6+
7+
const nodeUrl = 'wss://sepolia-pathfinder-rpc.spaceshard.io/rpc/v0_8';
8+
9+
describe('websocket specific endpoints - pathfinder test', () => {
10+
// account provider
11+
const provider = new Provider(getTestProvider());
12+
const account = getTestAccount(provider);
13+
14+
// websocket
15+
let webSocketChannel: WebSocketChannel;
16+
17+
beforeAll(async () => {
18+
webSocketChannel = new WebSocketChannel({ nodeUrl: TEST_WS_URL });
19+
expect(webSocketChannel.isConnected()).toBe(false);
20+
try {
21+
await webSocketChannel.waitForConnection();
22+
} catch (error: any) {
23+
console.log(error.message);
24+
}
25+
expect(webSocketChannel.isConnected()).toBe(true);
26+
});
27+
28+
afterAll(async () => {
29+
expect(webSocketChannel.isConnected()).toBe(true);
30+
webSocketChannel.disconnect();
31+
await expect(webSocketChannel.waitForDisconnection()).resolves.toBe(WebSocket.CLOSED);
32+
});
33+
34+
test('Test WS Error and edge cases', async () => {
35+
webSocketChannel.disconnect();
36+
37+
// should fail as disconnected
38+
await expect(webSocketChannel.subscribeNewHeads()).rejects.toThrow();
39+
40+
// should reconnect
41+
webSocketChannel.reconnect();
42+
await webSocketChannel.waitForConnection();
43+
44+
// should succeed after reconnection
45+
await expect(webSocketChannel.subscribeNewHeads()).resolves.toEqual(expect.any(Number));
46+
47+
// should fail because already subscribed
48+
await expect(webSocketChannel.subscribeNewHeads()).resolves.toBe(false);
49+
});
50+
51+
test('onUnsubscribe with unsubscribeNewHeads', async () => {
52+
const mockOnUnsubscribe = jest.fn().mockImplementation((subId: number) => {
53+
expect(subId).toEqual(expect.any(Number));
54+
});
55+
webSocketChannel.onUnsubscribe = mockOnUnsubscribe;
56+
57+
await webSocketChannel.subscribeNewHeads();
58+
await expect(webSocketChannel.unsubscribeNewHeads()).resolves.toBe(true);
59+
await expect(webSocketChannel.unsubscribeNewHeads()).rejects.toThrow();
60+
61+
expect(mockOnUnsubscribe).toHaveBeenCalled();
62+
expect(webSocketChannel.subscriptions.has(WSSubscriptions.NEW_HEADS)).toBeFalsy();
63+
});
64+
65+
test('Test subscribeNewHeads', async () => {
66+
await webSocketChannel.subscribeNewHeads();
67+
68+
let i = 0;
69+
webSocketChannel.onNewHeads = async function (data) {
70+
expect(this).toBeInstanceOf(WebSocketChannel);
71+
i += 1;
72+
// TODO : Add data format validation
73+
expect(data.result).toBeDefined();
74+
if (i === 2) {
75+
const status = await webSocketChannel.unsubscribeNewHeads();
76+
expect(status).toBe(true);
77+
}
78+
};
79+
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.NEW_HEADS);
80+
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);
81+
expect(subscriptionId).toBe(expectedId);
82+
expect(webSocketChannel.subscriptions.get(WSSubscriptions.NEW_HEADS)).toBe(undefined);
83+
});
84+
85+
test('Test subscribeEvents', async () => {
86+
await webSocketChannel.subscribeEvents();
87+
88+
let i = 0;
89+
webSocketChannel.onEvents = async (data) => {
90+
i += 1;
91+
// TODO : Add data format validation
92+
expect(data.result).toBeDefined();
93+
if (i === 5) {
94+
const status = await webSocketChannel.unsubscribeEvents();
95+
expect(status).toBe(true);
96+
}
97+
};
98+
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.EVENTS);
99+
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);
100+
expect(subscriptionId).toBe(expectedId);
101+
expect(webSocketChannel.subscriptions.get(WSSubscriptions.EVENTS)).toBe(undefined);
102+
});
103+
104+
test('Test subscribePendingTransaction', async () => {
105+
await webSocketChannel.subscribePendingTransaction(true);
106+
107+
let i = 0;
108+
webSocketChannel.onPendingTransaction = async (data) => {
109+
i += 1;
110+
// TODO : Add data format validation
111+
expect(data.result).toBeDefined();
112+
if (i === 5) {
113+
const status = await webSocketChannel.unsubscribePendingTransaction();
114+
expect(status).toBe(true);
115+
}
116+
};
117+
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.PENDING_TRANSACTION);
118+
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);
119+
expect(subscriptionId).toBe(expectedId);
120+
expect(webSocketChannel.subscriptions.get(WSSubscriptions.PENDING_TRANSACTION)).toBe(undefined);
121+
});
122+
123+
test('Test subscribeTransactionStatus', async () => {
124+
const { transaction_hash } = await account.execute({
125+
contractAddress: STRKtokenAddress,
126+
entrypoint: 'transfer',
127+
calldata: [account.address, '10', '0'],
128+
});
129+
130+
let i = 0;
131+
webSocketChannel.onTransactionStatus = async (data) => {
132+
i += 1;
133+
// TODO : Add data format validation
134+
expect(data.result).toBeDefined();
135+
if (i >= 1) {
136+
const status = await webSocketChannel.unsubscribeTransactionStatus();
137+
expect(status).toBe(true);
138+
}
139+
};
140+
141+
const subid = await webSocketChannel.subscribeTransactionStatus(transaction_hash);
142+
expect(subid).toEqual(expect.any(Number));
143+
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS);
144+
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);
145+
expect(subscriptionId).toEqual(expectedId);
146+
expect(webSocketChannel.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS)).toBe(undefined);
147+
});
148+
149+
test('Test subscribeTransactionStatus and block_id', async () => {
150+
const { transaction_hash } = await account.execute({
151+
contractAddress: STRKtokenAddress,
152+
entrypoint: 'transfer',
153+
calldata: [account.address, '10', '0'],
154+
});
155+
156+
let i = 0;
157+
webSocketChannel.onTransactionStatus = async (data) => {
158+
i += 1;
159+
// TODO : Add data format validation
160+
expect(data.result).toBeDefined();
161+
if (i >= 1) {
162+
const status = await webSocketChannel.unsubscribeTransactionStatus();
163+
expect(status).toBe(true);
164+
}
165+
};
166+
167+
const subid = await webSocketChannel.subscribeTransactionStatus(transaction_hash);
168+
expect(subid).toEqual(expect.any(Number));
169+
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS);
170+
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);
171+
expect(subscriptionId).toEqual(expectedId);
172+
expect(webSocketChannel.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS)).toBe(undefined);
173+
});
174+
});
175+
176+
describe('websocket regular endpoints - pathfinder test', () => {
177+
let webSocketChannel: WebSocketChannel;
178+
179+
beforeAll(async () => {
180+
webSocketChannel = new WebSocketChannel({ nodeUrl });
181+
expect(webSocketChannel.isConnected()).toBe(false);
182+
const status = await webSocketChannel.waitForConnection();
183+
expect(status).toBe(WebSocket.OPEN);
184+
});
185+
186+
afterAll(async () => {
187+
expect(webSocketChannel.isConnected()).toBe(true);
188+
webSocketChannel.disconnect();
189+
});
190+
191+
test('regular rpc endpoint', async () => {
192+
const response = await webSocketChannel.sendReceiveAny('starknet_chainId');
193+
expect(response).toBe(StarknetChainId.SN_SEPOLIA);
194+
});
195+
});

0 commit comments

Comments
 (0)