Skip to content

Commit

Permalink
test: provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Jul 19, 2024
1 parent 1791134 commit f1ca022
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 9 deletions.
25 changes: 20 additions & 5 deletions __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import fs from 'node:fs';
import path from 'node:path';

import { Account, Provider, ProviderInterface, RpcProvider, json } from '../../src';
import { CompiledSierra, CompiledSierraCasm, LegacyCompiledContract } from '../../src/types';
import {
CompiledSierra,
CompiledSierraCasm,
LegacyCompiledContract,
RpcProviderOptions,
} from '../../src/types';
import { ETransactionVersion } from '../../src/types/api';
import { toHex } from '../../src/utils/num';
import { wait } from '../../src/utils/provider';
Expand Down Expand Up @@ -72,12 +77,22 @@ export const compiledSidMulticallCasm = readContractSierraCasm('starknetId/multi
export const compiledNonZero = readContractSierra('cairo/cairo263/zeroable.sierra');
export const compiledNonZeroCasm = readContractSierraCasm('cairo/cairo263/zeroable');

export function getTestProvider(isProvider?: true): ProviderInterface;
export function getTestProvider(isProvider?: false): RpcProvider;
export function getTestProvider(isProvider: boolean = true): ProviderInterface | RpcProvider {
export function getTestProvider(
isProvider?: true,
setProviderOptions?: RpcProviderOptions
): ProviderInterface;
export function getTestProvider(
isProvider?: false,
setProviderOptions?: RpcProviderOptions
): RpcProvider;
export function getTestProvider(
isProvider: boolean = true,
setProviderOptions?: RpcProviderOptions
): ProviderInterface | RpcProvider {
const isDevnet = process.env.IS_DEVNET === 'true';

const providerOptions = {
const providerOptions: RpcProviderOptions = {
...setProviderOptions,
nodeUrl: process.env.TEST_RPC_URL,
// accelerate the tests when running locally
...(isDevnet && { transactionRetryIntervalFallback: 1000 }),
Expand Down
17 changes: 17 additions & 0 deletions __tests__/utils/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@ describe('Batch Client', () => {
expect(fetchSpy).toHaveBeenCalledTimes(1);
fetchSpy.mockRestore();
});

test('batch request using Provider', async () => {
const myBatchProvider = getTestProvider(false, {
batch: 0,
});

// eslint-disable-next-line @typescript-eslint/dot-notation
const sendBatchSpy = jest.spyOn(myBatchProvider.channel['batchClient'] as any, 'sendBatch');

await Promise.all([
myBatchProvider.getBlock(),
myBatchProvider.getBlockLatestAccepted(),
myBatchProvider.getBlockTransactionCount('latest'),
]);

expect(sendBatchSpy).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit f1ca022

Please sign in to comment.