Skip to content

Commit 411eeec

Browse files
committed
fix: update ws impl, add TEST_WS_URL, update token constants
1 parent d600703 commit 411eeec

File tree

8 files changed

+34
-42
lines changed

8 files changed

+34
-42
lines changed

__tests__/WebSocketChannel.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { WebSocket } from 'isows';
22

33
import { Provider, WSSubscriptions, WebSocketChannel } from '../src';
44
import { StarknetChainId } from '../src/global/constants';
5-
import { getTestAccount, getTestProvider } from './config/fixtures';
5+
import { getTestAccount, getTestProvider, STRKtokenAddress, TEST_WS_URL } from './config/fixtures';
66

77
const nodeUrl = 'wss://sepolia-pathfinder-rpc.spaceshard.io/rpc/v0_8';
88

@@ -15,7 +15,7 @@ describe('websocket specific endpoints - pathfinder test', () => {
1515
let webSocketChannel: WebSocketChannel;
1616

1717
beforeAll(async () => {
18-
webSocketChannel = new WebSocketChannel({ nodeUrl });
18+
webSocketChannel = new WebSocketChannel({ nodeUrl: TEST_WS_URL });
1919
expect(webSocketChannel.isConnected()).toBe(false);
2020
try {
2121
await webSocketChannel.waitForConnection();
@@ -122,7 +122,7 @@ describe('websocket specific endpoints - pathfinder test', () => {
122122

123123
test('Test subscribeTransactionStatus', async () => {
124124
const { transaction_hash } = await account.execute({
125-
contractAddress: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
125+
contractAddress: STRKtokenAddress,
126126
entrypoint: 'transfer',
127127
calldata: [account.address, '10', '0'],
128128
});
@@ -147,11 +147,8 @@ describe('websocket specific endpoints - pathfinder test', () => {
147147
});
148148

149149
test('Test subscribeTransactionStatus and block_id', async () => {
150-
const latestBlock = await account.getBlockLatestAccepted();
151-
const blockId = latestBlock.block_number - 5;
152-
153150
const { transaction_hash } = await account.execute({
154-
contractAddress: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
151+
contractAddress: STRKtokenAddress,
155152
entrypoint: 'transfer',
156153
calldata: [account.address, '10', '0'],
157154
});
@@ -167,7 +164,7 @@ describe('websocket specific endpoints - pathfinder test', () => {
167164
}
168165
};
169166

170-
const subid = await webSocketChannel.subscribeTransactionStatus(transaction_hash, blockId);
167+
const subid = await webSocketChannel.subscribeTransactionStatus(transaction_hash);
171168
expect(subid).toEqual(expect.any(Number));
172169
const expectedId = webSocketChannel.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS);
173170
const subscriptionId = await webSocketChannel.waitForUnsubscription(expectedId);

__tests__/account.outsideExecution.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import {
2323
} from '../src';
2424
import { getSelectorFromName } from '../src/utils/hash';
2525
import { getDecimalString } from '../src/utils/num';
26-
import { contracts, createTestProvider, getTestAccount } from './config/fixtures';
26+
import { contracts, createTestProvider, ETHtokenAddress, getTestAccount } from './config/fixtures';
2727

2828
describe('Account and OutsideExecution', () => {
29-
const ethAddress = '0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7';
3029
let provider: Provider;
3130
let executorAccount: Account;
3231
let signerAccount: Account;
@@ -40,7 +39,7 @@ describe('Account and OutsideExecution', () => {
4039
provider = new Provider(await createTestProvider());
4140
executorAccount = getTestAccount(provider);
4241
recipientAccount = executorAccount;
43-
ethContract = new Contract(contracts.Erc20OZ.sierra.abi, ethAddress, provider);
42+
ethContract = new Contract(contracts.Erc20OZ.sierra.abi, ETHtokenAddress, provider);
4443

4544
// Deploy the SNIP-9 signer account (ArgentX v 0.4.0, using SNIP-9 v2):
4645
const calldataAX = new CallData(contracts.ArgentX4Account.sierra.abi);
@@ -61,7 +60,7 @@ describe('Account and OutsideExecution', () => {
6160

6261
// Transfer dust of ETH token to the signer account
6362
const transferCall = {
64-
contractAddress: ethAddress,
63+
contractAddress: ETHtokenAddress,
6564
entrypoint: 'transfer',
6665
calldata: {
6766
recipient: signerAccount.address,
@@ -245,31 +244,31 @@ describe('Account and OutsideExecution', () => {
245244
caller: 'ANY_CALLER',
246245
};
247246
const call1: Call = {
248-
contractAddress: ethAddress,
247+
contractAddress: ETHtokenAddress,
249248
entrypoint: 'transfer',
250249
calldata: {
251250
recipient: recipientAccount.address,
252251
amount: cairo.uint256(100),
253252
},
254253
};
255254
const call2: Call = {
256-
contractAddress: ethAddress,
255+
contractAddress: ETHtokenAddress,
257256
entrypoint: 'transfer',
258257
calldata: {
259258
recipient: recipientAccount.address,
260259
amount: cairo.uint256(200),
261260
},
262261
};
263262
const call3: Call = {
264-
contractAddress: ethAddress,
263+
contractAddress: ETHtokenAddress,
265264
entrypoint: 'transfer',
266265
calldata: {
267266
recipient: recipientAccount.address,
268267
amount: cairo.uint256(300),
269268
},
270269
};
271270
const call4: Call = {
272-
contractAddress: ethAddress,
271+
contractAddress: ETHtokenAddress,
273272
entrypoint: 'transfer',
274273
calldata: {
275274
recipient: recipientAccount.address,
@@ -293,7 +292,7 @@ describe('Account and OutsideExecution', () => {
293292
expect(outsideTransaction1.outsideExecution.execute_before).toBe(hour_later);
294293
expect(outsideTransaction1.outsideExecution.calls).toEqual([
295294
{
296-
to: ethAddress,
295+
to: ETHtokenAddress,
297296
selector: '0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e',
298297
calldata: [getDecimalString(recipientAccount.address), '300', '0'],
299298
},
@@ -305,12 +304,12 @@ describe('Account and OutsideExecution', () => {
305304
);
306305
expect(outsideTransaction2.outsideExecution.calls).toEqual([
307306
{
308-
to: ethAddress,
307+
to: ETHtokenAddress,
309308
selector: '0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e',
310309
calldata: [getDecimalString(recipientAccount.address), '100', '0'],
311310
},
312311
{
313-
to: ethAddress,
312+
to: ETHtokenAddress,
314313
selector: '0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e',
315314
calldata: [getDecimalString(recipientAccount.address), '200', '0'],
316315
},

__tests__/config/fixtures.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export async function createTestProvider(
131131
}
132132

133133
export const TEST_TX_VERSION = process.env.TX_VERSION as SupportedTransactionVersion;
134+
export const { TEST_WS_URL } = process.env;
134135

135136
export const getTestAccount = (
136137
provider: ProviderInterface,
@@ -182,9 +183,7 @@ export const describeIfDevnet = describeIf(process.env.IS_DEVNET === 'true');
182183
export const describeIfTestnet = describeIf(process.env.IS_TESTNET === 'true');
183184
export const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
184185
export const wrongClassHash = '0x000000000000000000000000000000000000000000000000000000000000000';
185-
export const devnetETHtokenAddress =
186-
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7';
187-
export const devnetSTRKtokenAddress =
186+
export const ETHtokenAddress = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7';
187+
export const STRKtokenAddress =
188188
'0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d';
189-
export const devnetFeeTokenAddress =
190-
TEST_TX_VERSION === '0x3' ? devnetSTRKtokenAddress : devnetETHtokenAddress;
189+
export const devnetFeeTokenAddress = TEST_TX_VERSION === '0x3' ? STRKtokenAddress : ETHtokenAddress;

__tests__/config/helpers/strategyResolver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class StrategyResolver {
8787
TEST_ACCOUNT_PRIVATE_KEY: '****',
8888
INITIAL_BALANCE: process.env.INITIAL_BALANCE,
8989
TEST_RPC_URL: process.env.TEST_RPC_URL,
90+
TEST_WS_URL: process.env.TEST_WS_URL,
9091
TX_VERSION: process.env.TX_VERSION,
9192
SPEC_VERSION: process.env.SPEC_VERSION,
9293
});

__tests__/rpcProvider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
describeIfNotDevnet,
2828
describeIfRpc,
2929
describeIfTestnet,
30-
devnetETHtokenAddress,
30+
ETHtokenAddress,
3131
getTestAccount,
3232
waitNextBlock,
3333
} from './config/fixtures';
@@ -290,7 +290,7 @@ describeIfRpc('RPCProvider', () => {
290290
beforeAll(async () => {
291291
// add a Tx to be sure to have at least one Tx in the last block
292292
const { transaction_hash } = await account.execute({
293-
contractAddress: devnetETHtokenAddress,
293+
contractAddress: ETHtokenAddress,
294294
entrypoint: 'transfer',
295295
calldata: {
296296
recipient: account.address,

__tests__/utils/ethSigner.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import {
2424
contracts,
2525
createTestProvider,
2626
describeIfDevnet,
27-
devnetETHtokenAddress,
27+
ETHtokenAddress,
2828
getTestAccount,
29+
STRKtokenAddress,
2930
} from '../config/fixtures';
3031

3132
describe('Ethereum signer', () => {
@@ -150,7 +151,7 @@ describe('Ethereum signer', () => {
150151
await ethAccount.estimateAccountDeployFee(deployPayload);
151152
// fund account with ETH
152153
const { transaction_hash } = await account.execute({
153-
contractAddress: devnetETHtokenAddress,
154+
contractAddress: ETHtokenAddress,
154155
entrypoint: 'transfer',
155156
calldata: {
156157
recipient: contractETHAccountAddress,
@@ -168,7 +169,7 @@ describe('Ethereum signer', () => {
168169
});
169170

170171
test('ETH account transaction V2', async () => {
171-
const ethContract2 = new Contract(contracts.Erc20.abi, devnetETHtokenAddress, ethAccount);
172+
const ethContract2 = new Contract(contracts.Erc20.abi, ETHtokenAddress, ethAccount);
172173
const respTransfer = await ethContract2
173174
.withOptions({ maxFee: 1 * 10 ** 16 })
174175
.transfer(account.address, cairo.uint256(1 * 10 ** 4));
@@ -203,8 +204,6 @@ describe('Ethereum signer', () => {
203204
let provider: Provider;
204205
let account: Account;
205206
let ethAccount: Account;
206-
const devnetSTRKtokenAddress =
207-
'0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d';
208207

209208
beforeAll(async () => {
210209
provider = new Provider(await createTestProvider());
@@ -250,7 +249,7 @@ describe('Ethereum signer', () => {
250249
});
251250
// fund account with STRK
252251
const { transaction_hash } = await account.execute({
253-
contractAddress: devnetSTRKtokenAddress,
252+
contractAddress: STRKtokenAddress,
254253
entrypoint: 'transfer',
255254
calldata: {
256255
recipient: contractETHAccountAddress,
@@ -281,7 +280,7 @@ describe('Ethereum signer', () => {
281280
});
282281

283282
test('ETH account transaction V3', async () => {
284-
const strkContract2 = new Contract(contracts.Erc20.abi, devnetSTRKtokenAddress, ethAccount);
283+
const strkContract2 = new Contract(contracts.Erc20.abi, STRKtokenAddress, ethAccount);
285284
const txCallData = strkContract2.populate('transfer', [
286285
account.address,
287286
cairo.uint256(1 * 10 ** 4),

__tests__/utils/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as starkCurve from '@scure/starknet';
22

33
import { constants, ec, hash, num, stark, units } from '../../src';
4+
import { ETHtokenAddress } from '../config/fixtures';
45

56
const { IS_BROWSER } = constants;
67

@@ -103,19 +104,18 @@ describe('estimatedFeeToMaxFee()', () => {
103104
});
104105

105106
describe('calculateContractAddressFromHash()', () => {
106-
const ethAddress = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7';
107107
const daiAddress = '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9';
108108
const factoryAddress = '0x249827618A01858A72B7D04339C47195A324D20D6037033DFE2829F98AFF4FC';
109109
const classHash = '0x55187E68C60664A947048E0C9E5322F9BF55F7D435ECDCF17ED75724E77368F';
110110
// Any type of salt can be used. It depends on the dApp what kind of salt it wants to use.
111-
const salt = ec.starkCurve.pedersen(ethAddress, daiAddress);
111+
const salt = ec.starkCurve.pedersen(ETHtokenAddress, daiAddress);
112112

113113
// This test just shows how to use calculateContractAddressFromHash for new devs
114114
test('calculated contract address should match the snapshot', () => {
115115
const res = hash.calculateContractAddressFromHash(
116116
salt,
117117
classHash,
118-
[ethAddress, daiAddress, factoryAddress],
118+
[ETHtokenAddress, daiAddress, factoryAddress],
119119
factoryAddress
120120
);
121121

@@ -130,7 +130,7 @@ describe('calculateContractAddressFromHash()', () => {
130130
const res = hash.calculateContractAddressFromHash(
131131
salt,
132132
classHash,
133-
[ethAddress, daiAddress, factoryAddress],
133+
[ETHtokenAddress, daiAddress, factoryAddress],
134134
factoryAddress
135135
);
136136
expect(starkCurveSpy).toHaveBeenCalled();

src/channel/ws_0_8.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,9 @@ export class WebSocketChannel {
505505
/**
506506
* subscribe to transaction status
507507
*/
508-
public async subscribeTransactionStatus(
509-
transactionHash: BigNumberish,
510-
blockIdentifier?: SubscriptionBlockIdentifier
511-
) {
508+
public async subscribeTransactionStatus(transactionHash: BigNumberish) {
512509
if (this.subscriptions.get(WSSubscriptions.TRANSACTION_STATUS)) return false;
513-
const subId = await this.subscribeTransactionStatusUnmanaged(transactionHash, blockIdentifier);
510+
const subId = await this.subscribeTransactionStatusUnmanaged(transactionHash);
514511
this.subscriptions.set(WSSubscriptions.TRANSACTION_STATUS, subId);
515512
return subId;
516513
}

0 commit comments

Comments
 (0)