diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 256ecf8b4..ec24c59d6 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -21,7 +21,7 @@ jobs: # 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.0.4-seed0' || '' }} + image: ${{ (inputs.use-devnet) && 'shardlabs/starknet-devnet-rs:0.0.5-seed0' || '' }} ports: - 5050:5050 diff --git a/__tests__/config/fixtures.ts b/__tests__/config/fixtures.ts index bb8132383..d02a6008b 100644 --- a/__tests__/config/fixtures.ts +++ b/__tests__/config/fixtures.ts @@ -2,12 +2,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { Account, Provider, ProviderInterface, RpcProvider, json } from '../../src'; -import { - CompiledSierra, - CompiledSierraCasm, - LegacyCompiledContract, - waitForTransactionOptions, -} from '../../src/types'; +import { CompiledSierra, CompiledSierraCasm, LegacyCompiledContract } from '../../src/types'; import { ETransactionVersion } from '../../src/types/api'; import { toHex } from '../../src/utils/num'; @@ -73,22 +68,18 @@ export const compiledTestRejectSierra = readContractSierra('cairo/testReject/tes export const compiledTestRejectCasm = readContractSierraCasm('cairo/testReject/test_reject'); export const compiledSidMulticall = readContractSierra('starknetId/multicall/multicall.sierra'); export const compiledSidMulticallCasm = readContractSierraCasm('starknetId/multicall/multicall'); + export function getTestProvider(isProvider?: true): ProviderInterface; export function getTestProvider(isProvider?: false): RpcProvider; export function getTestProvider(isProvider: boolean = true): ProviderInterface | RpcProvider { - const provider = isProvider - ? new Provider({ nodeUrl: process.env.TEST_RPC_URL }) - : new RpcProvider({ nodeUrl: process.env.TEST_RPC_URL }); + const isDevnet = process.env.IS_DEVNET === 'true'; - if (process.env.IS_DEVNET === 'true') { + const providerOptions = { + nodeUrl: process.env.TEST_RPC_URL, // accelerate the tests when running locally - const originalWaitForTransaction = provider.waitForTransaction.bind(provider); - provider.waitForTransaction = (txHash: string, options: waitForTransactionOptions = {}) => { - return originalWaitForTransaction(txHash, { retryInterval: 1000, ...options }); - }; - } - - return provider; + ...(isDevnet && { transactionRetryIntervalFallback: 1000 }), + }; + return isProvider ? new Provider(providerOptions) : new RpcProvider(providerOptions); } export const TEST_TX_VERSION = process.env.TX_VERSION === 'v3' ? ETransactionVersion.V3 : undefined; diff --git a/src/account/interface.ts b/src/account/interface.ts index 66b308777..eba6e4b4e 100644 --- a/src/account/interface.ts +++ b/src/account/interface.ts @@ -147,11 +147,11 @@ export abstract class AccountInterface extends ProviderInterface { * Estimate Fee for executing a list of transactions on starknet * Contract must be deployed for fee estimation to be possible * - * @param transactions array of transaction object containing : + * @param invocations array of transaction object containing : * - type - the type of transaction : 'DECLARE' | (multi)'DEPLOY' | (multi)'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT' * - payload - the payload of the transaction * - * @param estimateFeeDetails - + * @param details - * - blockIdentifier? * - nonce? * - skipValidate? - default true @@ -344,34 +344,34 @@ export abstract class AccountInterface extends ProviderInterface { ): Promise; /** - * Signs a JSON object for off-chain usage with the Starknet private key and returns the signature + * Signs a TypedData object for off-chain usage with the Starknet private key and returns the signature * This adds a message prefix so it can't be interchanged with transactions * - * @param json - JSON object to be signed - * @returns the signature of the JSON object - * @throws {Error} if the JSON object is not a valid JSON + * @param typedData - TypedData object to be signed + * @returns the signature of the TypedData object + * @throws {Error} if typedData is not a valid TypedData */ public abstract signMessage(typedData: TypedData): Promise; /** - * Hash a JSON object with Pedersen hash and return the hash + * Hash a TypedData object with Pedersen hash and return the hash * This adds a message prefix so it can't be interchanged with transactions * - * @param json - JSON object to be hashed - * @returns the hash of the JSON object - * @throws {Error} if the JSON object is not a valid JSON + * @param typedData - TypedData object to be hashed + * @returns the hash of the TypedData object + * @throws {Error} if typedData is not a valid TypedData */ public abstract hashMessage(typedData: TypedData): Promise; /** - * Verify a signature of a JSON object + * Verify a signature of a TypedData object * - * @param typedData - JSON object to be verified - * @param signature - signature of the JSON object + * @param typedData - TypedData object to be verified + * @param signature - signature of the TypedData object * @param signatureVerificationFunctionName - optional account contract verification function name override * @param signatureVerificationResponse - optional response override { okResponse: string[]; nokResponse: string[]; error: string[] } * @returns true if the signature is valid, false otherwise - * @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature + * @throws {Error} if typedData is not a valid TypedData or the signature is not a valid signature */ public abstract verifyMessage(typedData: TypedData, signature: Signature): Promise; diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index a4c66ca00..3074c82d0 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -222,12 +222,13 @@ export class RpcChannel { */ public simulateTransaction( invocations: AccountInvocations, - { + simulateTransactionOptions: getSimulateTransactionOptions = {} + ) { + const { blockIdentifier = this.blockIdentifier, skipValidate = true, skipFeeCharge = true, - }: getSimulateTransactionOptions = {} - ) { + } = simulateTransactionOptions; const block_id = new Block(blockIdentifier).identifier; const simulationFlags: RPC.ESimulationFlag[] = []; if (skipValidate) simulationFlags.push(RPC.ESimulationFlag.SKIP_VALIDATE); diff --git a/src/channel/rpc_0_7.ts b/src/channel/rpc_0_7.ts index 53e51aed2..00e875bd4 100644 --- a/src/channel/rpc_0_7.ts +++ b/src/channel/rpc_0_7.ts @@ -50,11 +50,21 @@ export class RpcChannel { private specVersion?: string; + private transactionRetryIntervalFallback?: number; + readonly waitMode: Boolean; // behave like web2 rpc and return when tx is processed constructor(optionsOrProvider?: RpcProviderOptions) { - const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = - optionsOrProvider || {}; + const { + nodeUrl, + retries, + headers, + blockIdentifier, + chainId, + specVersion, + waitMode, + transactionRetryIntervalFallback, + } = optionsOrProvider || {}; if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) { this.nodeUrl = getDefaultNodeUrl(nodeUrl as NetworkName, optionsOrProvider?.default); } else if (nodeUrl) { @@ -69,6 +79,11 @@ export class RpcChannel { this.specVersion = specVersion; this.waitMode = waitMode || false; this.requestId = 0; + this.transactionRetryIntervalFallback = transactionRetryIntervalFallback; + } + + private get transactionRetryIntervalDefault() { + return this.transactionRetryIntervalFallback ?? 5000; } public setChainId(chainId: StarknetChainId) { @@ -227,12 +242,13 @@ export class RpcChannel { */ public simulateTransaction( invocations: AccountInvocations, - { + simulateTransactionOptions: getSimulateTransactionOptions = {} + ) { + const { blockIdentifier = this.blockIdentifier, skipValidate = true, skipFeeCharge = true, - }: getSimulateTransactionOptions = {} - ) { + } = simulateTransactionOptions; const block_id = new Block(blockIdentifier).identifier; const simulationFlags: RPC.ESimulationFlag[] = []; if (skipValidate) simulationFlags.push(RPC.ESimulationFlag.SKIP_VALIDATE); @@ -250,7 +266,7 @@ export class RpcChannel { let { retries } = this; let onchain = false; let isErrorState = false; - const retryInterval = options?.retryInterval ?? 5000; + const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault; const errorStates: any = options?.errorStates ?? [ RPC.ETransactionStatus.REJECTED, // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default diff --git a/src/provider/interface.ts b/src/provider/interface.ts index 8903bbd98..15d00904b 100644 --- a/src/provider/interface.ts +++ b/src/provider/interface.ts @@ -61,8 +61,7 @@ export abstract class ProviderInterface { * @param blockIdentifier block identifier * @returns the block object */ - public abstract getBlock(): Promise; - public abstract getBlock(blockIdentifier: 'pending'): Promise; + public abstract getBlock(blockIdentifier?: 'pending'): Promise; public abstract getBlock(blockIdentifier: 'latest'): Promise; public abstract getBlock(blockIdentifier: BlockIdentifier): Promise; @@ -134,7 +133,7 @@ export abstract class ProviderInterface { /** * Gets the transaction information from a tx id. * - * @param txHash + * @param transactionHash * @returns the transaction object \{ transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? \} */ public abstract getTransaction(transactionHash: BigNumberish): Promise; @@ -142,7 +141,7 @@ export abstract class ProviderInterface { /** * Gets the transaction receipt from a tx hash. * - * @param txHash + * @param transactionHash * @returns the transaction receipt object */ public abstract getTransactionReceipt( diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 66ee958e9..4823cda60 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -176,7 +176,7 @@ export class RpcProvider implements ProviderInterface { /** * @param invocations AccountInvocations - * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge
+ * @param options blockIdentifier and flags to skip validation and fee charge
* - blockIdentifier
* - skipValidate (default false)
* - skipFeeCharge (default true)
@@ -199,6 +199,7 @@ export class RpcProvider implements ProviderInterface { txHash, options )) as GetTxReceiptResponseWithoutHelper; + return new ReceiptTx(receiptWoHelper) as GetTransactionReceiptResponse; } diff --git a/src/signer/interface.ts b/src/signer/interface.ts index 47c08dd7a..beaea9bd3 100644 --- a/src/signer/interface.ts +++ b/src/signer/interface.ts @@ -47,7 +47,7 @@ export abstract class SignerInterface { /** * Signs a DEPLOY_ACCOUNT transaction with the Starknet private key and returns the signature * - * @param transaction
+ * @param transaction
* - contractAddress
* - chainId
* - classHash
@@ -64,7 +64,7 @@ export abstract class SignerInterface { /** * Signs a DECLARE transaction with the Starknet private key and returns the signature * - * @param transaction
+ * @param transaction
* - classHash
* - compiledClassHash? - used for Cairo1
* - senderAddress
diff --git a/src/types/account.ts b/src/types/account.ts index 9572cfeb8..4da859a92 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -76,11 +76,6 @@ export type SimulateTransactionDetails = { skipExecute?: boolean; } & Partial; -export enum SIMULATION_FLAG { - SKIP_VALIDATE = 'SKIP_VALIDATE', - SKIP_EXECUTE = 'SKIP_EXECUTE', -} - export type EstimateFeeAction = | { type: TransactionType.INVOKE; diff --git a/src/types/provider/configuration.ts b/src/types/provider/configuration.ts index 71eaf534f..db1825f42 100644 --- a/src/types/provider/configuration.ts +++ b/src/types/provider/configuration.ts @@ -6,6 +6,7 @@ export interface ProviderOptions extends RpcProviderOptions {} export type RpcProviderOptions = { nodeUrl?: string | NetworkName; retries?: number; + transactionRetryIntervalFallback?: number; headers?: object; blockIdentifier?: BlockIdentifier; chainId?: StarknetChainId; diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index e4a4fa361..a91534778 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -137,6 +137,7 @@ export type Storage = FELT; export type Nonce = string; +export type { SIMULATION_FLAG }; export type SimulationFlags = Array; export type SimulatedTransaction = SimulateTransaction & { diff --git a/src/utils/calldata/byteArray.ts b/src/utils/calldata/byteArray.ts index 288848259..28febc303 100644 --- a/src/utils/calldata/byteArray.ts +++ b/src/utils/calldata/byteArray.ts @@ -32,7 +32,7 @@ export function stringFromByteArray(myByteArray: ByteArray): string { /** * convert a JS string to a Cairo ByteArray - * @param myString a JS string + * @param targetString a JS string * @returns Cairo representation of a LongString * @example * ```typescript diff --git a/src/utils/calldata/index.ts b/src/utils/calldata/index.ts index 904e99506..9d01d4f91 100644 --- a/src/utils/calldata/index.ts +++ b/src/utils/calldata/index.ts @@ -104,7 +104,7 @@ export class CallData { * Compile contract callData with abi * Parse the calldata by using input fields from the abi for that method * @param method string - method name - * @param args RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order). + * @param argsCalldata RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order). * @return Calldata - parsed arguments in format that contract is expecting * @example * ```typescript diff --git a/src/wallet/connect.ts b/src/wallet/connect.ts index c9be27f49..258c91f80 100644 --- a/src/wallet/connect.ts +++ b/src/wallet/connect.ts @@ -121,7 +121,8 @@ export function addDeclareTransaction( /** * Sign typed data using the wallet. - * @param params The typed data to sign. + * @param swo the starknet (wallet) window object to request the signature. + * @param typedData The typed data to sign. * @returns An array of signatures as strings. */ export function signMessage(swo: StarknetWindowObject, typedData: TypedData) {