Skip to content

Commit

Permalink
Merge branch 'feat/refactor-list-transactions-with-starkscan' into ch…
Browse files Browse the repository at this point in the history
…ore/sf-742
  • Loading branch information
khanti42 authored Dec 11, 2024
2 parents 87ff473 + 6619c62 commit 3e950f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 61 deletions.
21 changes: 7 additions & 14 deletions packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {
ApiParamsWithKeyDeriver,
CreateAccountRequestParams,
} from './types/snapApi';
import type { AccContract, Transaction } from './types/snapState';
import { VoyagerTransactionType, TransactionStatus } from './types/snapState';
import type { AccContract } from './types/snapState';
import { CAIRO_VERSION_LEGACY, CAIRO_VERSION } from './utils/constants';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
Expand All @@ -26,6 +25,7 @@ import {
waitForTransaction,
estimateAccountDeployFee,
} from './utils/starknetUtils';
import { newDeployTransaction } from './utils/transaction';

/**
* Create an starknet account.
Expand Down Expand Up @@ -142,21 +142,14 @@ export async function createAccount(

await upsertAccount(userAccount, wallet, saveMutex);

const txn: Transaction = {
const txn = newDeployTransaction({
txnHash: deployResp.transaction_hash,
txnType: VoyagerTransactionType.DEPLOY_ACCOUNT,
chainId: network.chainId,
senderAddress: deployResp.contract_address,
contractAddress: deployResp.contract_address,
contractFuncName: '',
contractCallData: [],
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '',
failureReason: '',
eventIds: [],
timestamp: Math.floor(Date.now() / 1000),
};
// whenever create account is happen, we pay the fee in ETH, so txnVersion is 1
// FIXME: it should allow to pay the fee in STRK
txnVersion: 1,
});

await upsertTransaction(txn, wallet, saveMutex);
}
Expand Down
23 changes: 8 additions & 15 deletions packages/starknet-snap/src/upgradeAccContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type {
ApiParamsWithKeyDeriver,
UpgradeTransactionRequestParams,
} from './types/snapApi';
import type { Transaction } from './types/snapState';
import { TransactionStatus, VoyagerTransactionType } from './types/snapState';
import { ACCOUNT_CLASS_HASH, CAIRO_VERSION_LEGACY } from './utils/constants';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
Expand All @@ -23,6 +21,7 @@ import {
isAccountDeployed,
estimateFee,
} from './utils/starknetUtils';
import { newInvokeTransaction } from './utils/transaction';

/**
*
Expand Down Expand Up @@ -145,21 +144,15 @@ export async function upgradeAccContract(params: ApiParamsWithKeyDeriver) {
throw new Error(`Transaction hash is not found`);
}

const txn: Transaction = {
const txn = newInvokeTransaction({
txnHash: txnResp.transaction_hash,
txnType: VoyagerTransactionType.INVOKE,
chainId: network.chainId,
senderAddress: contractAddress,
contractAddress,
contractFuncName: 'upgrade',
contractCallData: CallData.compile(calldata),
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '', // DEPRECATED LATER
failureReason: '',
eventIds: [],
timestamp: Math.floor(Date.now() / 1000),
};
chainId: network.chainId,
maxFee: maxFee.toString(10),
calls: [txnInvocation],
// whenever upgrade is happen, we pay the fee in ETH, so txnVersion is 1
txnVersion: 1,
});

await upsertTransaction(txn, wallet, saveMutex);

Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/utils/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('feeTokenToTransactionVersion', () => {
});

it.each([FeeToken.ETH, 'invalid_unit'])(
'converts feeToken string to transaction version v1 if it not STRK - %s',
'converts feeToken string to transaction version v1 if it is not STRK - %s',
(txnVersion: string) => {
expect(feeTokenToTransactionVersion(txnVersion)).toStrictEqual(
constants.TRANSACTION_VERSION.V1,
Expand Down
31 changes: 0 additions & 31 deletions packages/starknet-snap/test/src/upgradeAccContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,36 +280,5 @@ describe('Test function: upgradeAccContract', function () {
expect(result.message).to.be.include('Transaction hash is not found');
}
});

it('should save transaction when execute transaction success', async function () {
executeTxnStub.resolves(sendTransactionResp);
estimateFeeStub.resolves(estimateFeeResp);
walletStub.rpcStubs.snap_dialog.resolves(true);
const address = (
apiParams.requestParams as UpgradeTransactionRequestParams
).contractAddress;
const calldata = CallData.compile({
implementation: ACCOUNT_CLASS_HASH,
calldata: [0],
});
const txn = {
txnHash: sendTransactionResp.transaction_hash,
txnType: VoyagerTransactionType.INVOKE,
chainId: STARKNET_SEPOLIA_TESTNET_NETWORK.chainId,
senderAddress: address,
contractAddress: address,
contractFuncName: 'upgrade',
contractCallData: CallData.compile(calldata),
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '',
failureReason: '',
eventIds: [],
};

const result = await upgradeAccContract(apiParams);
expect(result).to.be.equal(sendTransactionResp);
expect(upsertTransactionStub).to.calledOnceWith(sinon.match(txn));
});
});
});

0 comments on commit 3e950f5

Please sign in to comment.