Skip to content
Merged
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
21 changes: 6 additions & 15 deletions __tests__/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@
* - Conditional test suite helpers (describeIf*, testIf*)
*/
import { config, hash } from '../../src';
import { autoDiscoverContracts } from './helpers/contract';
import { CONTRACTS } from './helpers/contract';

/**
* Auto-discovered contracts from __mocks__ directory.
* Contracts are automatically loaded based on their file structure:
* - Cairo contracts: __mocks__/cairo/**\/*.sierra.json + matching .casm files
* - Grouped contracts: __mocks__/{groupName}/**\/*.sierra.json + matching .casm files
* (e.g., StarknetId contracts in __mocks__/starknetId/)
*
* Contract keys are generated from filenames in PascalCase:
* - cairo210.sierra.json -> Cairo210
* - openzeppelin_EthAccount090.sierra.json -> OpenzeppelinEthAccount090
* - starknetId directory -> StarknetId group
*/
export const CONTRACTS = autoDiscoverContracts();
export { CONTRACTS };

config.set('logLevel', 'ERROR');

if (process.env.IS_DEVNET === 'true') {
// accelerate the tests when running locally devnet
config.set('channelDefaults.options.transactionRetryIntervalFallback', 0);
}
export const { TEST_WS_URL } = process.env;

const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
Expand Down
14 changes: 14 additions & 0 deletions __tests__/config/helpers/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ export const autoDiscoverContracts = (
// Return discovered contracts (cairo contracts already mapped, grouped contracts already mapped)
return discovered;
};

/**
* Auto-discovered contracts from __mocks__ directory.
* Contracts are automatically loaded based on their file structure:
* - Cairo contracts: __mocks__/cairo/**\/*.sierra.json + matching .casm files
* - Grouped contracts: __mocks__/{groupName}/**\/*.sierra.json + matching .casm files
* (e.g., StarknetId contracts in __mocks__/starknetId/)
*
* Contract keys are generated from filenames in PascalCase:
* - cairo210.sierra.json -> Cairo210
* - openzeppelin_EthAccount090.sierra.json -> OpenzeppelinEthAccount090
* - starknetId directory -> StarknetId group
*/
export const CONTRACTS = autoDiscoverContracts();
6 changes: 0 additions & 6 deletions __tests__/config/helpers/testInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Provider,
ProviderInterface,
RpcProvider,
config,
getTipStatsFromBlocks,
type PaymasterInterface,
type TipAnalysisOptions,
Expand All @@ -22,21 +21,16 @@ import { toHex } from '../../../src/utils/num';
import '../customMatchers'; // ensures TS traversal
import { SupportedRpcVersion, SupportedTransactionVersion } from '../../../src/global/constants';

config.set('logLevel', 'ERROR');

/**
* Builds provider options with test environment configuration
* @param setProviderOptions - Optional provider options to merge
* @returns Provider options configured for test environment
*/
function buildTestProviderOptions(setProviderOptions?: RpcProviderOptions): RpcProviderOptions {
const isDevnet = process.env.IS_DEVNET === 'true';
return {
...setProviderOptions,
nodeUrl: process.env.TEST_RPC_URL,
specVersion: process.env.RPC_SPEC_VERSION as SupportedRpcVersion,
// accelerate the tests when running locally
...(isDevnet && { transactionRetryIntervalFallback: 0 }),
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/channel/rpc_0_10_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class RpcChannel {
this.headers = { ...channelDefaults.options.headers, ...headers };
this.retries = retries ?? channelDefaults.options.retries;
this.specVersion = specVersion;
this.transactionRetryIntervalFallback = transactionRetryIntervalFallback;
this.transactionRetryIntervalFallback =
transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;
this.waitMode = waitMode ?? false;

this.requestId = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/channel/rpc_0_9_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export class RpcChannel {
this.headers = { ...channelDefaults.options.headers, ...headers };
this.retries = retries ?? channelDefaults.options.retries;
this.specVersion = specVersion;
this.transactionRetryIntervalFallback = transactionRetryIntervalFallback;
this.transactionRetryIntervalFallback =
transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;

this.waitMode = waitMode ?? false;

this.requestId = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/global/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export type ChannelDefaultOptions = {
headers: Record<string, string>;
blockIdentifier: BlockTag;
retries: number;
transactionRetryIntervalFallback: number;
};

/**
Expand Down Expand Up @@ -184,6 +185,7 @@ export const DEFAULT_GLOBAL_CONFIG: {
headers: { 'Content-Type': 'application/json' },
blockIdentifier: BlockTag.LATEST,
retries: 200,
transactionRetryIntervalFallback: 5000,
},
methods: {
simulateTransaction: {
Expand Down