Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: public responseParser #1154

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 15 additions & 4 deletions __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import {
compiledL1L2,
compiledOpenZeppelinAccount,
createBlockForDevnet,
describeIfRpc,
describeIfNotDevnet,
describeIfDevnet,
describeIfNotDevnet,
describeIfRpc,
describeIfTestnet,
devnetETHtokenAddress,
getTestAccount,
getTestProvider,
describeIfTestnet,
waitNextBlock,
devnetETHtokenAddress,
} from './config/fixtures';
import { initializeMatcher } from './config/schema';

Expand All @@ -50,6 +50,17 @@ describeIfRpc('RPCProvider', () => {
await createBlockForDevnet();
});

test('instantiate from rpcProvider', () => {
// instantiate rpc provider template
const newInsRPCProvider = new RpcProvider();
// like* change channel and parser
newInsRPCProvider.channel = rpcProvider.channel;
newInsRPCProvider.responseParser = rpcProvider.responseParser;
// instantiate from modified instance
const FinalInsRPCProvider = new RpcProvider(newInsRPCProvider);
expect(FinalInsRPCProvider).toBeInstanceOf(RpcProvider);
tabaktoni marked this conversation as resolved.
Show resolved Hide resolved
});

test('getChainId', async () => {
const fetchSpy = jest.spyOn(rpcProvider.channel as any, 'fetchEndpoint');
(rpcProvider as any).chainId = undefined as unknown as StarknetChainId;
Expand Down
20 changes: 12 additions & 8 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SPEC } from 'starknet-types-07';
import { bytesToHex } from '@noble/curves/abstract/utils';
import { keccak_256 } from '@noble/hashes/sha3';
import type { SPEC } from 'starknet-types-07';

import { RPC06, RPC07, RpcChannel } from '../channel';
import {
AccountInvocations,
Expand Down Expand Up @@ -29,27 +30,30 @@ import {
getSimulateTransactionOptions,
waitForTransactionOptions,
} from '../types';
import { getAbiContractVersion } from '../utils/calldata/cairo';
import { isSierra } from '../utils/contract';
import { RPCResponseParser } from '../utils/responseParser/rpc';
import { GetTransactionReceiptResponse, ReceiptTx } from '../utils/transactionReceipt';
import type { TransactionWithHash } from '../types/provider/spec';
import assert from '../utils/assert';
import { hexToBytes, toHex } from '../utils/num';
import { getAbiContractVersion } from '../utils/calldata/cairo';
import { isSierra } from '../utils/contract';
import { addHexPrefix, removeHexPrefix } from '../utils/encode';
import { hexToBytes, toHex } from '../utils/num';
import { wait } from '../utils/provider';
import { RPCResponseParser } from '../utils/responseParser/rpc';
import { GetTransactionReceiptResponse, ReceiptTx } from '../utils/transactionReceipt';
import { LibraryError } from './errors';
import { ProviderInterface } from './interface';

export class RpcProvider implements ProviderInterface {
private responseParser: RPCResponseParser;
public responseParser: RPCResponseParser;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest making this private again or adding an export for the RPCResponseParser class somewhere so it is exposed by the library and can be picked up by the automated documentation generation.

Copy link
Collaborator Author

@tabaktoni tabaktoni Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c2887ed

Exported both interface and Imp


public channel: RPC07.RpcChannel | RPC06.RpcChannel;

constructor(optionsOrProvider?: RpcProviderOptions | ProviderInterface | RpcProvider) {
if (optionsOrProvider && 'channel' in optionsOrProvider) {
this.channel = optionsOrProvider.channel;
this.responseParser = (optionsOrProvider as any).responseParser;
this.responseParser =
'responseParser' in optionsOrProvider
? optionsOrProvider.responseParser
: new RPCResponseParser();
} else {
this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage);
Expand Down