Skip to content

Commit

Permalink
Revert "chore: update create account and upgrade account"
Browse files Browse the repository at this point in the history
This reverts commit cf64931.
  • Loading branch information
stanleyyconsensys committed Dec 10, 2024
1 parent c5e7741 commit bb69ff5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
21 changes: 14 additions & 7 deletions packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type {
ApiParamsWithKeyDeriver,
CreateAccountRequestParams,
} from './types/snapApi';
import type { AccContract } from './types/snapState';
import type { AccContract, Transaction } from './types/snapState';
import { VoyagerTransactionType, TransactionStatus } from './types/snapState';
import { CAIRO_VERSION_LEGACY, CAIRO_VERSION } from './utils/constants';
import { logger } from './utils/logger';
import { toJson } from './utils/serializer';
Expand All @@ -25,7 +26,6 @@ import {
waitForTransaction,
estimateAccountDeployFee,
} from './utils/starknetUtils';
import { newDeployTransaction } from './utils/transaction';

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

await upsertAccount(userAccount, wallet, saveMutex);

const txn = newDeployTransaction({
const txn: Transaction = {
txnHash: deployResp.transaction_hash,
txnType: VoyagerTransactionType.DEPLOY_ACCOUNT,
chainId: network.chainId,
senderAddress: deployResp.contract_address,
// 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,
})
contractAddress: deployResp.contract_address,
contractFuncName: '',
contractCallData: [],
finalityStatus: TransactionStatus.RECEIVED,
executionStatus: TransactionStatus.RECEIVED,
status: '',
failureReason: '',
eventIds: [],
timestamp: Math.floor(Date.now() / 1000),
};

await upsertTransaction(txn, wallet, saveMutex);
}
Expand Down
21 changes: 14 additions & 7 deletions packages/starknet-snap/src/upgradeAccContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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 @@ -21,7 +23,6 @@ import {
isAccountDeployed,
estimateFee,
} from './utils/starknetUtils';
import { newInvokeTransaction } from './utils/transaction';

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

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

await upsertTransaction(txn, wallet, saveMutex);

Expand Down
31 changes: 30 additions & 1 deletion packages/starknet-snap/test/src/upgradeAccContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,35 @@ describe('Test function: upgradeAccContract', function () {
}
});


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 bb69ff5

Please sign in to comment.