diff --git a/packages/starknet-snap/src/__tests__/helper.ts b/packages/starknet-snap/src/__tests__/helper.ts index 8ef6580c..31bbf1f9 100644 --- a/packages/starknet-snap/src/__tests__/helper.ts +++ b/packages/starknet-snap/src/__tests__/helper.ts @@ -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, diff --git a/packages/starknet-snap/src/chain/data-client/starkscan.test.ts b/packages/starknet-snap/src/chain/data-client/starkscan.test.ts index 24dd6302..61594dc4 100644 --- a/packages/starknet-snap/src/chain/data-client/starkscan.test.ts +++ b/packages/starknet-snap/src/chain/data-client/starkscan.test.ts @@ -2,7 +2,7 @@ import { TransactionType, constants } from 'starknet'; import { generateAccounts, - generateStarkScanTranscations, + generateStarkScanTransactions, } from '../../__tests__/helper'; import type { Network, Transaction } from '../../types/snapState'; import { @@ -95,7 +95,7 @@ describe('StarkScanClient', () => { }; const mockTxByType = (txnType: TransactionType, address: string) => { - const mockResponse = generateStarkScanTranscations({ + const mockResponse = generateStarkScanTransactions({ address, txnTypes: [txnType], cnt: 1, @@ -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, }); @@ -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, }); @@ -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, @@ -370,7 +370,8 @@ describe('StarkScanClient', () => { }, ], }, - version: 'V2', + version: mockTx.version, + dataVersion: 'V2', }); }); @@ -397,7 +398,8 @@ describe('StarkScanClient', () => { maxFee: mockTx.max_fee, actualFee: mockTx.actual_fee, accountCalls: null, - version: 'V2', + version: mockTx.version, + dataVersion: 'V2', }); }); }); @@ -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, }); @@ -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], diff --git a/packages/starknet-snap/src/chain/data-client/starkscan.ts b/packages/starknet-snap/src/chain/data-client/starkscan.ts index 98eab071..d1dac1e6 100644 --- a/packages/starknet-snap/src/chain/data-client/starkscan.ts +++ b/packages/starknet-snap/src/chain/data-client/starkscan.ts @@ -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 { @@ -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 @@ -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 */ diff --git a/packages/starknet-snap/src/types/snapState.ts b/packages/starknet-snap/src/types/snapState.ts index ea6cbf1b..5be52899 100644 --- a/packages/starknet-snap/src/types/snapState.ts +++ b/packages/starknet-snap/src/types/snapState.ts @@ -157,7 +157,9 @@ export type V2Transaction = { actualFee?: string | null; // using Record to support O(1) searching accountCalls?: Record | 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