Skip to content

Commit

Permalink
chore: lint style
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys committed Jun 12, 2024
1 parent 61d6a0f commit 2fedd78
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 36 deletions.
14 changes: 11 additions & 3 deletions packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,17 @@ export async function createAccount(params: ApiParams, silentMode = false, waitM
}
}

const deployResp = await deployAccount(network, contractAddress, contractCallData, publicKey, privateKey, undefined, {
maxFee: estimateDeployFee?.suggestedMaxFee,
});
const deployResp = await deployAccount(
network,
contractAddress,
contractCallData,
publicKey,
privateKey,
undefined,
{
maxFee: estimateDeployFee?.suggestedMaxFee,
},
);

if (deployResp.contract_address && deployResp.transaction_hash) {
const userAccount: AccContract = {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/utils/snapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export function getRPCUrl(chainId: string) {
}

export function getRPCCredentials(): string {
return process.env.ALCHEMY_API_KEY ?? ''
return process.env.ALCHEMY_API_KEY ?? '';
}

export function getVoyagerUrl(chainId: string) {
Expand Down
55 changes: 33 additions & 22 deletions packages/starknet-snap/src/utils/starknetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
CairoVersion,
InvocationsSignerDetails,
ProviderInterface,
GetTransactionReceiptResponse,
} from 'starknet';
import { Network, SnapState, Transaction, TransactionType } from '../types/snapState';
import {
Expand Down Expand Up @@ -101,6 +102,16 @@ export const callContract = async (
);
};

export const waitForTransaction = async (
network: Network,
senderAddress: string,
privateKey: string | Uint8Array,
txnHash: num.BigNumberish,
cairoVersion?: CairoVersion,
): Promise<GetTransactionReceiptResponse> => {
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).waitForTransaction(txnHash);
};

export const declareContract = async (
network: Network,
senderAddress: string,
Expand All @@ -109,9 +120,11 @@ export const declareContract = async (
invocationsDetails?: UniversalDetails,
cairoVersion?: CairoVersion,
): Promise<DeclareContractResponse> => {
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).declare(
contractPayload, { ...invocationsDetails, skipValidate: false, blockIdentifier: 'latest' }
);
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).declare(contractPayload, {
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
});
};

export const estimateFee = async (
Expand All @@ -137,14 +150,11 @@ export const estimateFeeBulk = async (
invocationsDetails?: UniversalDetails,
cairoVersion?: CairoVersion,
): Promise<EstimateFee[]> => {
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).estimateFeeBulk(
txnInvocation,
{
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
},
);
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).estimateFeeBulk(txnInvocation, {
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
});
};

export const executeTxn = async (
Expand All @@ -156,15 +166,11 @@ export const executeTxn = async (
invocationsDetails?: UniversalDetails,
cairoVersion?: CairoVersion,
): Promise<InvokeFunctionResponse> => {
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).execute(
txnInvocation,
abis,
{
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
},
);
return getAccountInstance(network, senderAddress, privateKey, cairoVersion).execute(txnInvocation, abis, {
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
});
};

export const deployAccount = async (
Expand Down Expand Up @@ -210,7 +216,7 @@ export const estimateAccountDeployFee = async (
...invocationsDetails,
skipValidate: false,
blockIdentifier: 'latest',
}
},
);
};

Expand Down Expand Up @@ -384,7 +390,12 @@ export const getMassagedTransactions = async (
contractAddress: txnResp.calldata?.[1] || txnResp.contract_address || txn.contract_address || '',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
contractFuncName: num.toBigInt(txnResp.calldata?.[2] || '') === bigIntTransferSelectorHex ? 'transfer' : num.toBigInt(txnResp.calldata?.[2] || '') === bigIntUpgradeSelectorHex ? 'upgrade' : txn.operations ?? '',
contractFuncName:
num.toBigInt(txnResp.calldata?.[2] || '') === bigIntTransferSelectorHex
? 'transfer'
: num.toBigInt(txnResp.calldata?.[2] || '') === bigIntUpgradeSelectorHex
? 'upgrade'
: txn.operations ?? '',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
contractCallData: txnResp.calldata || [],
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/test/src/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('Test function: sendTransaction', function () {
beforeEach(async function () {
walletStub.rpcStubs.snap_getBip44Entropy.callsFake(getBip44EntropyStub);
apiParams.keyDeriver = await getAddressKeyDeriver(walletStub);
//sandbox.stub(utils, 'waitForTransaction').resolves({} as unknown as GetTransactionReceiptResponse);
});

afterEach(function () {
Expand Down Expand Up @@ -229,6 +228,7 @@ describe('Test function: sendTransaction', function () {
executeTxnStub = sandbox.stub(utils, 'executeTxn').resolves(executeTxnResp);
walletStub.rpcStubs.snap_manageState.resolves(state);
walletStub.rpcStubs.snap_dialog.resolves(true);
sandbox.stub(utils, 'waitForTransaction').resolves({} as unknown as GetTransactionReceiptResponse);
});

describe('when account is deployed', function () {
Expand Down
8 changes: 6 additions & 2 deletions packages/starknet-snap/test/utils/snapUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ describe('getVoyagerCredentials', () => {

describe('getRPCUrl', () => {
it('returns Mainnet RPC URL if chain id is Mainnet', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_MAIN)).to.be.equal('https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/');
expect(getRPCUrl(constants.StarknetChainId.SN_MAIN)).to.be.equal(
'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/',
);
});

it('returns Sepolia RPC URL if chain id is not either Mainnet or Sepolia', () => {
expect(getRPCUrl('0x534e5f474f45524c49')).to.be.equal('https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/');
expect(getRPCUrl('0x534e5f474f45524c49')).to.be.equal(
'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/',
);
});

it('returns Sepolia RPC URL if chain id is Sepolia', () => {
Expand Down
25 changes: 21 additions & 4 deletions packages/starknet-snap/test/utils/starknetUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
account3,
} from '../constants.test';
import { SnapState } from '../../src/types/snapState';
import { Calldata, num, Account, Provider } from 'starknet';
import { Calldata, num, Account, Provider, GetTransactionReceiptResponse } from 'starknet';
import { hexToString } from '../../src/utils/formatterUtils';

chai.use(sinonChai);
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('Test function: getVersion', function () {
const expected = '0.3.0';

beforeEach(function () {
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => ([expected]));
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => [expected]);
});

afterEach(function () {
Expand All @@ -294,7 +294,7 @@ describe('Test function: getOwner', function () {
const expected = 'pk';

beforeEach(function () {
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => ([expected]));
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => [expected]);
});

afterEach(function () {
Expand All @@ -317,7 +317,7 @@ describe('Test function: getBalance', function () {
const expected = 'pk';

beforeEach(function () {
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => ([expected]));
callContractStub = sandbox.stub(utils, 'callContract').callsFake(async () => [expected]);
});

afterEach(function () {
Expand Down Expand Up @@ -579,3 +579,20 @@ describe('Test function: getCorrectContractAddress', function () {
});
});
});

describe('Test function: waitForTransaction', function () {
const walletStub = new WalletMock();
const userAddress = '0x27f204588cadd08a7914f6a9808b34de0cbfc4cb53aa053663e7fd3a34dbc26';

afterEach(function () {
walletStub.reset();
sandbox.restore();
});

it('pass parameter to waitForTransaction correctly', async function () {
const stub = sandbox.stub(utils, 'waitForTransaction');
stub.resolves({} as unknown as GetTransactionReceiptResponse);
await utils.waitForTransaction(STARKNET_SEPOLIA_TESTNET_NETWORK, userAddress, 'pk', 'txHash');
expect(stub).to.have.been.calledWith(STARKNET_SEPOLIA_TESTNET_NETWORK, userAddress, 'pk', 'txHash');
});
});
15 changes: 12 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ __metadata:

"@consensys/starknet-snap@file:../starknet-snap::locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui":
version: 2.7.0
resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=099522&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui"
resolution: "@consensys/starknet-snap@file:../starknet-snap#../starknet-snap::hash=2d7b8f&locator=wallet-ui%40workspace%3Apackages%2Fwallet-ui"
dependencies:
"@metamask/snaps-sdk": 3.0.1
async-mutex: ^0.3.2
Expand All @@ -3257,7 +3257,7 @@ __metadata:
ethers: ^5.5.1
starknet: 6.7.0
starknet_v4.22.0: "npm:[email protected]"
checksum: a53e3b5b9b53448473b4b362ebdda3d1ecb97321baa7db52393c0b43e9454ccb81d641bd2a86956896a591c23f237566d4c131034806c2609de79f9f1a12ba41
checksum: b5bada5353623f8523c7c0ab3493b8da94446f0320b2195be81f442e4822f9c2b265da93e90a464c12c68491bb12d08438da446d263f4363fb820df1fbf7c0f1
languageName: node
linkType: hard

Expand Down Expand Up @@ -25348,6 +25348,15 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^7.5.2":
version: 7.6.2
resolution: "semver@npm:7.6.2"
bin:
semver: bin/semver.js
checksum: 40f6a95101e8d854357a644da1b8dd9d93ce786d5c6a77227bc69dbb17bea83d0d1d1d7c4cd5920a6df909f48e8bd8a5909869535007f90278289f2451d0292d
languageName: node
linkType: hard

"semver@npm:^7.5.4":
version: 7.6.0
resolution: "semver@npm:7.6.0"
Expand Down Expand Up @@ -28383,7 +28392,7 @@ __metadata:
react-scripts: 5.0.1
redux-persist: ^6.0.0
rimraf: ^3.0.2
semver: ^7.3.7
semver: ^7.5.2
starknet: ^4.22.0
styled-components: ^5.3.5
toastr2: ^3.0.0-alpha.18
Expand Down

0 comments on commit 2fedd78

Please sign in to comment.