Skip to content

Commit

Permalink
fix: change txn version for estimate fee apis to be feeTransactionVer…
Browse files Browse the repository at this point in the history
…sion

since this was a regression, also a regression test was added to 'estimate fee' account test
  • Loading branch information
yoga-braavos committed Nov 10, 2022
1 parent 73a2f3c commit 4d255c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isBN } from 'bn.js';

import typedDataExample from '../__mocks__/typedDataExample.json';
import { Account, Contract, Provider, number, stark } from '../src';
import { feeTransactionVersion } from '../src/utils/hash';
import { toBN } from '../src/utils/number';
import {
compiledErc20,
Expand Down Expand Up @@ -43,12 +44,15 @@ describe('deploy and test Wallet', () => {
});

test('estimate fee', async () => {
const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
const { overall_fee } = await account.estimateInvokeFee({
contractAddress: erc20Address,
entrypoint: 'transfer',
calldata: [erc20.address, '10', '0'],
});
expect(isBN(overall_fee)).toBe(true);
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion);
innerInvokeEstFeeSpy.mockClear();
});

test('read balance of wallet', async () => {
Expand Down
12 changes: 8 additions & 4 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
DeployAccountContractPayload,
UniversalDeployerContractPayload,
} from '../types/lib';
import { calculateContractAddressFromHash, transactionVersion } from '../utils/hash';
import {
calculateContractAddressFromHash,
feeTransactionVersion,
transactionVersion,
} from '../utils/hash';
import { BigNumberish, toBN, toCairoBool } from '../utils/number';
import { parseContract } from '../utils/provider';
import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark';
Expand Down Expand Up @@ -63,7 +67,7 @@ export class Account extends Provider implements AccountInterface {
): Promise<EstimateFee> {
const transactions = Array.isArray(calls) ? calls : [calls];
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);
const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();

const signerDetails: InvocationsSignerDetails = {
Expand Down Expand Up @@ -96,7 +100,7 @@ export class Account extends Provider implements AccountInterface {
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);
const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();
const contractDefinition = parseContract(contract);

Expand Down Expand Up @@ -132,7 +136,7 @@ export class Account extends Provider implements AccountInterface {
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
): Promise<EstimateFee> {
const nonce = toBN(providedNonce ?? (await this.getNonce()));
const version = toBN(transactionVersion);
const version = toBN(feeTransactionVersion);
const chainId = await this.getChainId();
const contractAddress =
providedContractAddress ??
Expand Down

0 comments on commit 4d255c5

Please sign in to comment.