Skip to content

Commit

Permalink
chore: resolve review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys committed Dec 4, 2024
1 parent 7a26c70 commit 804a2bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export function generateTransactionRequests({
* @param params.cnt - Number of transaction to generate.
* @returns An array of transaction object.
*/
export function generateStarkScanTranscations({
export function generateStarkScanTransactions({
address,
startFrom = Date.now(),
timestampReduction = 100,
Expand Down
24 changes: 13 additions & 11 deletions packages/starknet-snap/src/chain/data-client/starkscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransactionType, constants } from 'starknet';

import {
generateAccounts,
generateStarkScanTranscations,
generateStarkScanTransactions,
} from '../../__tests__/helper';
import type { Network, Transaction } from '../../types/snapState';
import {
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('StarkScanClient', () => {
};

const mockTxByType = (txnType: TransactionType, address: string) => {
const mockResponse = generateStarkScanTranscations({
const mockResponse = generateStarkScanTransactions({
address,
txnTypes: [txnType],
cnt: 1,
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('StarkScanClient', () => {
const { fetchSpy } = createMockFetch();
const { from, to } = getFromAndToTimestamp(5);
// generate 10 invoke transactions
const mockResponse = generateStarkScanTranscations({
const mockResponse = generateStarkScanTransactions({
address: account.address,
startFrom: from,
});
Expand Down Expand Up @@ -258,12 +258,12 @@ describe('StarkScanClient', () => {
const { fetchSpy } = createMockFetch();
// generate the to timestamp which is 100 days ago
const { to } = getFromAndToTimestamp(100);
const mockPage1Response = generateStarkScanTranscations({
const mockPage1Response = generateStarkScanTransactions({
address: account.address,
txnTypes: [TransactionType.INVOKE],
cnt: 10,
});
const mockPage2Response = generateStarkScanTranscations({
const mockPage2Response = generateStarkScanTransactions({
address: account.address,
cnt: 10,
});
Expand Down Expand Up @@ -304,14 +304,14 @@ describe('StarkScanClient', () => {
// generate the to timestamp which is 5 days ago
const { from, to } = getFromAndToTimestamp(5);
// generate 10 invoke transactions, and 1 day time gap between each transaction
const mockInvokeResponse = generateStarkScanTranscations({
const mockInvokeResponse = generateStarkScanTransactions({
address: account.address,
startFrom: from,
timestampReduction: mSecsFor24Hours,
txnTypes: [TransactionType.INVOKE],
});
// generate another 5 invoke transactions + deploy transactions for testing the fallback case
const mockDeployResponse = generateStarkScanTranscations({
const mockDeployResponse = generateStarkScanTransactions({
address: account.address,
// generate transactions that start from 100 days ago, to ensure not overlap with above invoke transactions
startFrom: mSecsFor24Hours * 100,
Expand Down Expand Up @@ -370,7 +370,8 @@ describe('StarkScanClient', () => {
},
],
},
version: 'V2',
version: mockTx.version,
dataVersion: 'V2',
});
});

Expand All @@ -397,7 +398,8 @@ describe('StarkScanClient', () => {
maxFee: mockTx.max_fee,
actualFee: mockTx.actual_fee,
accountCalls: null,
version: 'V2',
version: mockTx.version,
dataVersion: 'V2',
});
});
});
Expand All @@ -407,7 +409,7 @@ describe('StarkScanClient', () => {
const account = await mockAccount();
const { fetchSpy } = createMockFetch();
// generate 5 invoke transactions with deploy transaction
const mockResponse = generateStarkScanTranscations({
const mockResponse = generateStarkScanTransactions({
address: account.address,
cnt: 5,
});
Expand All @@ -424,7 +426,7 @@ describe('StarkScanClient', () => {
const account = await mockAccount();
const { fetchSpy } = createMockFetch();
// generate 5 invoke transactions with deploy transaction
const mockResponse = generateStarkScanTranscations({
const mockResponse = generateStarkScanTransactions({
address: account.address,
cnt: 1,
txnTypes: [TransactionType.INVOKE],
Expand Down
6 changes: 4 additions & 2 deletions packages/starknet-snap/src/chain/data-client/starkscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class StarkScanClient extends ApiClient implements IDataClient {
* The transactions are fetched in descending order and it will include the deploy transaction.
*
* @param address - The address of the contract to fetch the transactions for.
* @param to - The timestamp to fetch the transactions until.
* @param to - The filter includes transactions with a timestamp that is >= a specified value, but the deploy transaction is always included regardless of its timestamp.
* @returns A Promise that resolve an array of Transaction object.
*/
async getTransactions(address: string, to: number): Promise<Transaction[]> {
Expand Down Expand Up @@ -212,6 +212,7 @@ export class StarkScanClient extends ApiClient implements IDataClient {
actual_fee: actualFee,
revert_error: failureReason,
account_calls: calls,
version,
} = tx;

// account_calls representing the calls to invoke from the account contract, it can be multiple
Expand All @@ -231,7 +232,8 @@ export class StarkScanClient extends ApiClient implements IDataClient {
contractAddress: this.getContractAddress(tx),
accountCalls,
failureReason: failureReason ?? '',
version: 'V2',
version,
dataVersion: 'V2',
};

/* eslint-enable */
Expand Down
4 changes: 3 additions & 1 deletion packages/starknet-snap/src/types/snapState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export type V2Transaction = {
actualFee?: string | null;
// using Record<string, TranscationAccountCall[]> to support O(1) searching
accountCalls?: Record<string, TranscationAccountCall[]> | null;
version: 'V2';
version: number;
// Snap data Version to support backward compatibility , migration.
dataVersion: 'V2';
};

// FIXME: temp solution for backward compatibility before StarkScan implemented in get transactions
Expand Down

0 comments on commit 804a2bd

Please sign in to comment.