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: estimate fee response bulk type #482

Merged
merged 7 commits into from
Jan 10, 2023
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
31 changes: 31 additions & 0 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
compiledOpenZeppelinAccount,
compiledStarknetId,
compiledTestDapp,
describeIfDevnetSequencer,
describeIfSequencer,
erc20ClassHash,
getTestAccount,
Expand Down Expand Up @@ -71,6 +72,36 @@ describe('deploy and test Wallet', () => {
innerInvokeEstFeeSpy.mockClear();
});

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'],
},
},
]);

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);

Expand Down
4 changes: 4 additions & 0 deletions __tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
4 changes: 2 additions & 2 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
EstimateFee,
EstimateFeeAction,
EstimateFeeDetails,
EstimateFeeResponseBulk,
Invocation,
InvocationsDetails,
InvocationsSignerDetails,
Expand All @@ -32,6 +31,7 @@ import {
TransactionBulk,
UniversalDeployerContractPayload,
} from '../types';
import { EstimateFeeBulk } from '../types/account';
import { parseUDCEvent } from '../utils/events';
import {
calculateContractAddressFromHash,
Expand Down Expand Up @@ -220,7 +220,7 @@ export class Account extends Provider implements AccountInterface {
public async estimateFeeBulk(
transactions: TransactionBulk,
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
): Promise<EstimateFeeResponseBulk> {
): Promise<EstimateFeeBulk> {
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();
Expand Down
2 changes: 2 additions & 0 deletions src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface EstimateFee extends EstimateFeeResponse {
suggestedMaxFee: BN;
}

export type EstimateFeeBulk = Array<EstimateFee>;

export interface EstimateFeeDetails {
nonce?: BigNumberish;
blockIdentifier?: BlockIdentifier;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2017",
"es7",
Expand Down