Skip to content
Draft
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
25 changes: 21 additions & 4 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ jobs:
test:
name: Run tests
runs-on: ubuntu-latest
timeout-minutes: 20

# TODO - periodically check if conditional services are supported; https://github.com/actions/runner/issues/822
services:
devnet:
image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.5.0-rc.3' || '' }}
image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.5.0-rc.4' || '' }}
ports:
- 5050:5050

env:
PROTOCOL: ${{ inputs.protocol == 'WS' && 'wss' || 'https' }}
PROTOCOL: ${{ inputs.protocol == 'WS' && 'wss' || inputs.protocol == 'RPC' && 'https' || '' }}
NODE: ${{ inputs.node == 'Juno' && 'juno' || inputs.node == 'Pathfinder' && 'pathfinder' || '' }}
VERSION: ${{ inputs.version }}

NODE_URL: ${{ secrets.TEST_NODE_URL }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}

DEVNET_RPC_URL: 'http://127.0.0.1:5050/rpc'
DEVNET_WS_URL: 'ws://127.0.0.1:5050/ws'

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -62,16 +66,29 @@ jobs:
run: |
echo "::add-mask::$FORMATED_URL"
echo "NODE_URL=$FORMATED_URL" >> "$GITHUB_OUTPUT"
if: ${{ !!env.FORMATED_URL }}
env:
FORMATED_URL: ${{ format(env.NODE_URL, env.PROTOCOL, env.NODE, env.VERSION) }}
- id: url-resolution
name: url-resolution
run: |
echo "DEVNET_RPC_URL=$DEVNET_RPC_URL" >> "$GITHUB_OUTPUT"
echo "DEVNET_WS_URL=$DEVNET_WS_URL" >> "$GITHUB_OUTPUT"
echo "REMOTE_RPC_URL=$REMOTE_RPC_URL" >> "$GITHUB_OUTPUT"
echo "REMOTE_WS_URL=$REMOTE_WS_URL" >> "$GITHUB_OUTPUT"
env:
DEVNET_RPC_URL: ${{ inputs.use-devnet && env.DEVNET_RPC_URL || null }}
DEVNET_WS_URL: ${{ inputs.use-devnet && inputs.protocol == 'WS' && env.DEVNET_WS_URL || null }}
REMOTE_RPC_URL: ${{ inputs.protocol != 'WS' && steps.env-modification.outputs.NODE_URL || null }}
REMOTE_WS_URL: ${{ inputs.protocol == 'WS' && (env.NODE == 'juno' && secrets.TEST_WS_JUNO || steps.env-modification.outputs.NODE_URL) || null }}
- id: run-tests
name: run tests
run: |
args=()
[[ "${{ inputs.protocol }}" == "WS" ]] && args+=( '__tests__/WebSocket' )
npm run test:coverage "${args[@]}"
env:
TEST_RPC_URL: ${{ inputs.protocol != 'WS' && steps.env-modification.outputs.NODE_URL || null }}
TEST_WS_URL: ${{ inputs.protocol == 'WS' && (env.NODE == 'juno' && secrets.TEST_WS_JUNO || steps.env-modification.outputs.NODE_URL) || null }}
TEST_RPC_URL: ${{ steps.url-resolution.outputs.DEVNET_RPC_URL || steps.url-resolution.outputs.REMOTE_RPC_URL }}
TEST_WS_URL: ${{ steps.url-resolution.outputs.DEVNET_WS_URL || steps.url-resolution.outputs.REMOTE_WS_URL }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
14 changes: 6 additions & 8 deletions .github/workflows/manual-tests-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ on:
ignore-scripts:
description: 'Ignore scripts'
type: boolean
default: false
default: true

jobs:
tests:
name: Run test on ${{ matrix.name }}
name: Run test on Devnet ${{ matrix.protocol }}
strategy:
max-parallel: 1
fail-fast: false
matrix:
include:
- name: rpc-devnet
TEST_NODE_URL: http://127.0.0.1:5050/rpc
protocol: [RPC, WS]

uses: ./.github/workflows/_test.yml
with:
use-devnet: ${{ matrix.TEST_NODE_URL != '' }}
use-devnet: true
protocol: ${{ matrix.protocol }}
ignore-scripts: ${{ inputs.ignore-scripts }}
secrets:
TEST_NODE_URL: ${{ matrix.TEST_NODE_URL }}
2 changes: 1 addition & 1 deletion .github/workflows/manual-tests-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
ignore-scripts:
description: 'Ignore scripts'
type: boolean
default: false
default: true
fail-fast:
description: 'Fail fast'
type: boolean
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/pr-push-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ jobs:
cancel_others: 'true'

tests:
name: Run test on ${{ matrix.name }}
name: Run test on Devnet ${{ matrix.protocol }}
needs: [skip_check]
if: needs.skip_check.outputs.should_skip != 'true'
strategy:
max-parallel: 1
fail-fast: false
matrix:
include:
- name: rpc-devnet
TEST_NODE_URL: http://127.0.0.1:5050/rpc
protocol: [RPC, WS]

uses: ./.github/workflows/_test.yml
with:
use-devnet: ${{ matrix.TEST_NODE_URL != '' }}
secrets:
TEST_NODE_URL: ${{ matrix.TEST_NODE_URL }}
use-devnet: true
protocol: ${{ matrix.protocol }}

release:
name: Release
Expand Down
98 changes: 92 additions & 6 deletions __tests__/WebSocketChannel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-underscore-dangle */
import { Provider, Subscription, WebSocketChannel } from '../src';
import { Provider, Subscription, SubscriptionNewHeadsEvent, WebSocketChannel } from '../src';
import { logger } from '../src/global/logger';
import { StarknetChainId } from '../src/global/constants';
import { getTestProvider, TEST_WS_URL } from './config/fixtures';
Expand All @@ -10,6 +10,8 @@ const NODE_URL = TEST_WS_URL!;

describeIfWs('E2E WebSocket Tests', () => {
describe('websocket specific endpoints', () => {
// Updated for RPC 0.9: removed subscribePendingTransaction (not available in 0.9)
// Added subscribeNewTransactionReceipts and subscribeNewTransactions (new in 0.9)
// account provider
const provider = new Provider(getTestProvider());
const account = getTestAccount(provider);
Expand Down Expand Up @@ -63,7 +65,8 @@ describeIfWs('E2E WebSocket Tests', () => {
});

test('Test subscribeNewHeads', async () => {
const sub = await webSocketChannel.subscribeNewHeads();
// type not required, here I just test type availability
const sub: SubscriptionNewHeadsEvent = await webSocketChannel.subscribeNewHeads();
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
Expand All @@ -87,6 +90,7 @@ describeIfWs('E2E WebSocket Tests', () => {
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
expect(result).toHaveProperty('event');
if (i === 5) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
Expand All @@ -96,19 +100,99 @@ describeIfWs('E2E WebSocket Tests', () => {
await webSocketChannel.waitForUnsubscription(sub.id);
});

test('Test subscribePendingTransaction', async () => {
const sub = await webSocketChannel.subscribePendingTransaction(true);
test('Test subscribeEvents with finality status filter', async () => {
const sub = await webSocketChannel.subscribeEvents({
finalityStatus: 'ACCEPTED_ON_L2',
});
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
if (i === 5) {
expect(result).toHaveProperty('event');
if (i === 2) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
}
});

await webSocketChannel.waitForUnsubscription(sub.id);
});

test('Test subscribeNewTransactionReceipts', async () => {
const sub = await webSocketChannel.subscribeNewTransactionReceipts();
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
expect(result).toHaveProperty('transaction_receipt');
if (i === 2) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
}
});

await webSocketChannel.waitForUnsubscription(sub.id);
});

test('Test subscribeNewTransactionReceipts with finality status filter', async () => {
const sub = await webSocketChannel.subscribeNewTransactionReceipts({
finalityStatus: ['ACCEPTED_ON_L2'],
});
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
expect(result).toHaveProperty('transaction_receipt');
if (i === 1) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
}
});

await webSocketChannel.waitForUnsubscription(sub.id);
});

test('Test subscribeNewTransactions', async () => {
const sub = await webSocketChannel.subscribeNewTransactions();
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
expect(result).toHaveProperty('transaction');
if (i === 2) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
}
});

await webSocketChannel.waitForUnsubscription(sub.id);
});

test('Test subscribeNewTransactions with finality status filter', async () => {
const sub = await webSocketChannel.subscribeNewTransactions({
finalityStatus: ['ACCEPTED_ON_L2'],
});
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
sub.on(async (result) => {
i += 1;
expect(result).toBeDefined();
expect(result).toHaveProperty('transaction');
if (i === 1) {
const status = await sub.unsubscribe();
expect(status).toBe(true);
}
});

await webSocketChannel.waitForUnsubscription(sub.id);
});

Expand All @@ -119,7 +203,9 @@ describeIfWs('E2E WebSocket Tests', () => {
calldata: [account.address, '10', '0'],
});

const sub = await webSocketChannel.subscribeTransactionStatus(transaction_hash);
const sub = await webSocketChannel.subscribeTransactionStatus({
transactionHash: transaction_hash,
});
expect(sub).toBeInstanceOf(Subscription);

let i = 0;
Expand Down
Loading