From 78a14445c75b7ec259d6cfecd1cc17869b507dd8 Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Tue, 10 Jan 2023 10:26:27 +0000 Subject: [PATCH 1/4] fix: estimate fee response bulk type --- __tests__/account.test.ts | 28 ++++++++++++++++++++++++++++ src/account/default.ts | 5 +++-- src/types/account.ts | 2 ++ tsconfig.json | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts index f3ad75d7d..39bac87e1 100644 --- a/__tests__/account.test.ts +++ b/__tests__/account.test.ts @@ -71,6 +71,34 @@ describe('deploy and test Wallet', () => { innerInvokeEstFeeSpy.mockClear(); }); + test('estimate fee bulk', async () => { + const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction'); + const estimatedFeeBulk = await account.estimateFeeBulk([ + { + type: 'INVOKE_FUNCTION', + payload: { + contractAddress: erc20Address, + entrypoint: 'transfer', + calldata: [erc20.address, '10', '0'], + }, + }, + { + type: 'INVOKE_FUNCTION', + payload: { + contractAddress: erc20Address, + entrypoint: 'transfer', + calldata: [erc20.address, '10', '0'], + }, + }, + ]); + + expect(estimatedFeeBulk[0]).toHaveProperty('suggestedMaxFee'); + expect(estimatedFeeBulk.length).toEqual(2); + expect(isBN(estimatedFeeBulk[0].overall_fee)).toBe(true); + expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion); + innerInvokeEstFeeSpy.mockClear(); + }); + test('read balance of wallet', async () => { const x = await erc20.balanceOf(account.address); diff --git a/src/account/default.ts b/src/account/default.ts index 700b02d62..4ad8f02ca 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -21,7 +21,6 @@ import { EstimateFee, EstimateFeeAction, EstimateFeeDetails, - EstimateFeeResponseBulk, Invocation, InvocationsDetails, InvocationsSignerDetails, @@ -32,6 +31,7 @@ import { TransactionBulk, UniversalDeployerContractPayload, } from '../types'; +import { EstimateFeeBulk } from '../types/account'; import { parseUDCEvent } from '../utils/events'; import { calculateContractAddressFromHash, @@ -220,7 +220,7 @@ export class Account extends Provider implements AccountInterface { public async estimateFeeBulk( transactions: TransactionBulk, { nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {} - ): Promise { + ): Promise { const nonce = toBN(providedNonce ?? (await this.getNonce())); const version = toBN(feeTransactionVersion); const chainId = await this.getChainId(); @@ -284,6 +284,7 @@ export class Account extends Provider implements AccountInterface { ); const response = await super.getEstimateFeeBulk(params, blockIdentifier); + console.log('🚀 ~ file: default.ts:287 ~ Account ~ response', response); return [].concat(response as []).map((elem: any) => { const suggestedMaxFee = estimatedFeeToMaxFee(elem.overall_fee); diff --git a/src/types/account.ts b/src/types/account.ts index 831fa958c..5d72156bc 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -8,6 +8,8 @@ export interface EstimateFee extends EstimateFeeResponse { suggestedMaxFee: BN; } +export type EstimateFeeBulk = Array; + export interface EstimateFeeDetails { nonce?: BigNumberish; blockIdentifier?: BlockIdentifier; diff --git a/tsconfig.json b/tsconfig.json index 9195619a5..034bac027 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "es2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "lib": [ "es2017", "es7", From bbe51d33438528fc0d8926e9d0050e2efd7b6437 Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Tue, 10 Jan 2023 10:28:36 +0000 Subject: [PATCH 2/4] Update src/account/default.ts --- src/account/default.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/account/default.ts b/src/account/default.ts index 4ad8f02ca..3dfe4232f 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -284,7 +284,6 @@ export class Account extends Provider implements AccountInterface { ); const response = await super.getEstimateFeeBulk(params, blockIdentifier); - console.log('🚀 ~ file: default.ts:287 ~ Account ~ response', response); return [].concat(response as []).map((elem: any) => { const suggestedMaxFee = estimatedFeeToMaxFee(elem.overall_fee); From e85ad45c5565d93417b1a18e3663bd6c5e8861c1 Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Tue, 10 Jan 2023 10:29:43 +0000 Subject: [PATCH 3/4] fix: es6 --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 034bac027..15d214462 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "lib": [ "es2017", "es7", From 5ab047ff0b272057e70a29e909084d083db36a96 Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Tue, 10 Jan 2023 10:45:19 +0000 Subject: [PATCH 4/4] fix: tests --- __tests__/account.test.ts | 49 +++++++++++++++++++++------------------ __tests__/fixtures.ts | 4 ++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts index 39bac87e1..fe63c578a 100644 --- a/__tests__/account.test.ts +++ b/__tests__/account.test.ts @@ -18,6 +18,7 @@ import { compiledOpenZeppelinAccount, compiledStarknetId, compiledTestDapp, + describeIfDevnetSequencer, describeIfSequencer, erc20ClassHash, getTestAccount, @@ -71,32 +72,34 @@ describe('deploy and test Wallet', () => { innerInvokeEstFeeSpy.mockClear(); }); - test('estimate fee bulk', async () => { - const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction'); - const estimatedFeeBulk = await account.estimateFeeBulk([ - { - type: 'INVOKE_FUNCTION', - payload: { - contractAddress: erc20Address, - entrypoint: 'transfer', - calldata: [erc20.address, '10', '0'], + describeIfDevnetSequencer('Estimate Fee Bulk on Sequencer', () => { + test('estimate fee bulk', async () => { + const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction'); + const estimatedFeeBulk = await account.estimateFeeBulk([ + { + type: 'INVOKE_FUNCTION', + payload: { + contractAddress: erc20Address, + entrypoint: 'transfer', + calldata: [erc20.address, '10', '0'], + }, }, - }, - { - type: 'INVOKE_FUNCTION', - payload: { - contractAddress: erc20Address, - entrypoint: 'transfer', - calldata: [erc20.address, '10', '0'], + { + type: 'INVOKE_FUNCTION', + payload: { + contractAddress: erc20Address, + entrypoint: 'transfer', + calldata: [erc20.address, '10', '0'], + }, }, - }, - ]); + ]); - expect(estimatedFeeBulk[0]).toHaveProperty('suggestedMaxFee'); - expect(estimatedFeeBulk.length).toEqual(2); - expect(isBN(estimatedFeeBulk[0].overall_fee)).toBe(true); - expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion); - innerInvokeEstFeeSpy.mockClear(); + expect(estimatedFeeBulk[0]).toHaveProperty('suggestedMaxFee'); + expect(estimatedFeeBulk.length).toEqual(2); + expect(isBN(estimatedFeeBulk[0].overall_fee)).toBe(true); + expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion); + innerInvokeEstFeeSpy.mockClear(); + }); }); test('read balance of wallet', async () => { diff --git a/__tests__/fixtures.ts b/__tests__/fixtures.ts index 7d3aaaf40..cec4a1177 100644 --- a/__tests__/fixtures.ts +++ b/__tests__/fixtures.ts @@ -35,6 +35,8 @@ const PROVIDER_URL = RPC_URL || BASE_URL; export const IS_LOCALHOST_DEVNET = PROVIDER_URL.includes('localhost') || PROVIDER_URL.includes('127.0.0.1'); +export const IS_DEVNET_RPC = IS_LOCALHOST_DEVNET && PROVIDER_URL.includes('rpc'); + /* Definitions */ export const IS_RPC = !!RPC_URL; export const IS_SEQUENCER = !RPC_URL; @@ -80,5 +82,7 @@ export const describeIfSequencer = describeIf(IS_SEQUENCER); export const describeIfRpc = describeIf(IS_RPC); export const describeIfNotDevnet = describeIf(!IS_LOCALHOST_DEVNET); export const describeIfDevnet = describeIf(IS_LOCALHOST_DEVNET); +export const describeIfDevnetRpc = describeIf(IS_DEVNET_RPC); +export const describeIfDevnetSequencer = describeIf(!IS_DEVNET_RPC); export const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';