Skip to content

Commit

Permalink
feat: show upgrade dialog on get-starknet calls (#247)
Browse files Browse the repository at this point in the history
* feat: change account contract to cairo 1 (#152)

* feat: change account contract to cairo 1

- update recover account to return correct address
- update create account to use isAccountAddressDeployed method
- update est gas fee to use new accountClassHash
- add upgradeRequired in to acc object
- fix test case

* fix: update incorrect name

---------

Co-authored-by: Amine Harty <[email protected]>

* feat: sf-542 block cairo0 (#153)

* feat: change account contract to cairo 1

- update recover account to return correct address
- update create account to use isAccountAddressDeployed method
- update est gas fee to use new accountClassHash
- add upgradeRequired in to acc object
- fix test case

* feat: add blocking on snap method

- add blocking on snap methods
- add test case

* fix: update incorrect name

* fix: lint style

* fix: bug in merge conflict

* fix: update yarn lock

* chore(deps): bump word-wrap from 1.2.3 to 1.2.5 (#131)

Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.5.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](jonschlinkert/word-wrap@1.2.3...1.2.5)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump @adobe/css-tools from 4.2.0 to 4.3.1 (#132)

Bumps [@adobe/css-tools](https://github.com/adobe/css-tools) from 4.2.0 to 4.3.1.
- [Changelog](https://github.com/adobe/css-tools/blob/main/History.md)
- [Commits](https://github.com/adobe/css-tools/commits)

---
updated-dependencies:
- dependency-name: "@adobe/css-tools"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump semver from 7.3.8 to 7.5.2 (#130)

Bumps [semver](https://github.com/npm/node-semver) from 7.3.8 to 7.5.2.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md)
- [Commits](npm/node-semver@v7.3.8...v7.5.2)

---
updated-dependencies:
- dependency-name: semver
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: simplify snap logic

* fix: replace hardcode class hash

* fix: get version function

* fix: recover account for getting upgraded cairo 1 address

* feat: sf 549 update all method to support upgraded address (#188)

* fix: recoverAccount to avoid duplicate called on isUpgradeRequired

* chore: hardcode cairo version 1 to constant CAIRO_VERSION 

* fix: findAddressIndex should return address if the address match either cairo0 or cairo{N}

* fix: getCorrectContractAddress, use getVersion instead of getOwner to determine account has deployed or not

* chore: getCorrectContractAddress to return upgrade required attribute

* feat: sf-540 add account contract upgrade api (#189)

* fix: fix the get correct account method

* feat: add cairo upgrade api

* fix: rollback package.json

* fix: est fee in upgrade contract

* feat: sf-539 UI upgrade account (#191)

* fix: test (#203)

* chore: rebase

* chore: update conflict

* fix: lint issue

* feat: add webpack.config.dev.js for local serving of remoteEntry.js

* chore: lint and optional env variable for SNAP_ID

* fix: update get-starknet/webpack-dev-server dep to address security vulnerability

* fix: remoteEntry.js serving done on static file from dist/webpack folder

* chore: added .env.sample example file

* feat: optional PUBLIC_PATH env variable to produce local remoteEntry.js

* chore: updated README.md

* fix: methods signature

* test: make existing tests pass successfully

* fix: rollback check CairoVersion not needed

* fix: lint

* fix: contractCallData format in massagedTransaction

* fix: upgrade function detection in getMassagedTransactions filtering method

* refactor: ugrade detection mechanism similar to transfer based on method hex definition

* test: adapt constants.test.ts

* feat: show upgrade dialog on get-starknet calls

* feat: sf 614 rebase (#246)

* fix: address field error (#234)

* fix: fix address field error

* chore: release main (#235)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: bump starknetjs to 6.7.0 (#219)

* feat: bump starknetjs to 6.6.0

* chore: remove unuse script

* chore: add default config

* chore: remove patching

* chore: update library version

* chore: update getStarkName

* feat: sf 612 add alchemy provider (#236)

* feat: bump starknetjs to 6.6.0

* chore: remove unuse script

* chore: add default config

* chore: remove patching

* chore: update library version

* chore: update getStarkName

* feat: add alchemy provider

* fix: update mainnet-url

* feat: sf 613 add cicd support for alchemy (#237)

* feat: bump starknetjs to 6.6.0

* chore: remove unuse script

* chore: add default config

* chore: remove patching

* chore: update library version

* chore: update getStarkName

* feat: add alchemy provider

* fix: add cicd pipeline

* feat: add get starknet package (#186)

* feat: add get-starknet package

* feat: test cicd

* feat: test cicd

* fix: test ccid

* feat: update read me

* fix: update lint style

* fix: update comment

* fix: update lint checking

* fix: update readme

* fix: export get-starknet type and interface

* chore: add webpack bundler to get-starknet

* chore: update get-starknet yarn

* chore: update output path for get-starknet

* fix: incorrect request result

* fix: update request method result for get-starkent

* chore: update readme

* chore: remove unuse files

* chore: remove publish script in get-starknet package

* chore: remove CICD for get-starknet package

* fix: update typo in get-starknet

* fix: update wallet default version to wildcard

* feat: update package

* fix: update root domain

* fix: update testing script name

* chore: release main (#238)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: update yarn lock (#240)

* fix: get-starknet execute txn not working in firefox (#242)

* fix: firefox undefined issue

* fix: lint style

* feat: add webpack.config.dev.js for local serving of remoteEntry.js

* chore: lint and optional env variable for SNAP_ID

* fix: update get-starknet/webpack-dev-server dep to address security vulnerability

* fix: remoteEntry.js serving done on static file from dist/webpack folder

* chore: added .env.sample example file

* feat: optional PUBLIC_PATH env variable to produce local remoteEntry.js

* chore: updated README.md

* fix: methods signature

* test: make existing tests pass successfully

* fix: rollback check CairoVersion not needed

* fix: lint

* fix: contractCallData format in massagedTransaction

* fix: upgrade function detection in getMassagedTransactions filtering method

* refactor: ugrade detection mechanism similar to transfer based on method hex definition

* test: adapt constants.test.ts

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Florin Dzeladini <[email protected]>

* chore: upgrade modal link

* chore: lint style

* fix: lint issue

* fix: yarn lock

* chore: add update text

* chore: update snap file

* chore: update yarn.lock

* style: prettier

* fix: await missing in some upgradeRequired check

* test: updated unit testing associated to get-starknet

* fix: adapted text of the upgradeRequestModal

* style: lint

* chore: update snap sdk

* fix: manifest

* test: fix on executTxn.test.ts

* fix: executeTxn with deployed cairov2 should not trigger deployment

* fix: resolve local build get-starknet config issue

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Stanley Yuen <[email protected]>
Co-authored-by: Amine Harty <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Jun 21, 2024
1 parent 35f21e6 commit 4d8a2d7
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 20 deletions.
8 changes: 6 additions & 2 deletions packages/get-starknet/webpack.config.local.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { merge } = require('webpack-merge');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const common = require('./webpack.common.js');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');

module.exports = {
module.exports = (env) => merge(common, {
mode: 'development',
output: {
publicPath: process.env.GET_STARKNET_PUBLIC_PATH ?? 'http://localhost:8082/', // Adjust the development publicPath as needed
Expand All @@ -11,4 +15,4 @@ module.exports = {
compress: true,
port: 8082,
}
};
});
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/ConsenSys/starknet-snap.git"
},
"source": {
"shasum": "kl5iM2GRyXtFYwezb2vvrh2iTNC4Gw4K1I3PVOttXJ4=",
"shasum": "w/9IComQVArE5jU1RHIW8Y5CnN//nBoHKBQDFRhM8yI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
9 changes: 7 additions & 2 deletions packages/starknet-snap/src/declareContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toJson } from './utils/serializer';
import { ApiParams, DeclareContractRequestParams } from './types/snapApi';
import { getNetworkFromChainId, getDeclareSnapTxt } from './utils/snapUtils';
import { getKeysFromAddress, declareContract as declareContractUtil } from './utils/starknetUtils';
import { getNetworkFromChainId, getDeclareSnapTxt, showUpgradeRequestModal } from './utils/snapUtils';
import { getKeysFromAddress, declareContract as declareContractUtil, isUpgradeRequired } from './utils/starknetUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';
Expand All @@ -17,6 +17,11 @@ export async function declareContract(params: ApiParams) {
const network = getNetworkFromChainId(state, requestParamsObj.chainId);
const { privateKey } = await getKeysFromAddress(keyDeriver, network, state, senderAddress);

if (await isUpgradeRequired(network, senderAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

const snapComponents = getDeclareSnapTxt(
senderAddress,
network,
Expand Down
14 changes: 10 additions & 4 deletions packages/starknet-snap/src/executeTxn.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Invocations, TransactionType } from 'starknet';
import { getNetworkFromChainId, getTxnSnapTxt, addDialogTxt } from './utils/snapUtils';
import { getNetworkFromChainId, getTxnSnapTxt, addDialogTxt, showUpgradeRequestModal } from './utils/snapUtils';
import {
getKeysFromAddress,
executeTxn as executeTxnUtil,
isAccountDeployed,
estimateFeeBulk,
getAccContractAddressAndCallData,
addFeesFromAllTransactions,
isUpgradeRequired,
} from './utils/starknetUtils';
import { ApiParams, ExecuteTxnRequestParams } from './types/snapApi';
import { createAccount } from './createAccount';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel, divider } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';
import { PROXY_CONTRACT_HASH } from './utils/constants';
import { ACCOUNT_CLASS_HASH } from './utils/constants';

export async function executeTxn(params: ApiParams) {
try {
Expand All @@ -27,18 +28,23 @@ export async function executeTxn(params: ApiParams) {
addressIndex,
} = await getKeysFromAddress(keyDeriver, network, state, senderAddress);

if (await isUpgradeRequired(network, senderAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

const txnInvocationArray = Array.isArray(requestParamsObj.txnInvocation)
? requestParamsObj.txnInvocation
: [requestParamsObj.txnInvocation];
const bulkTransactions: Invocations = txnInvocationArray.map((ele) => ({
type: TransactionType.INVOKE,
payload: ele,
}));
const accountDeployed = await isAccountDeployed(network, publicKey);
const accountDeployed = await isAccountDeployed(network, senderAddress);
if (!accountDeployed) {
const { callData } = getAccContractAddressAndCallData(publicKey);
const deployAccountpayload = {
classHash: PROXY_CONTRACT_HASH,
classHash: ACCOUNT_CLASS_HASH,
contractAddress: senderAddress,
constructorCalldata: callData,
addressSalt: publicKey,
Expand Down
13 changes: 11 additions & 2 deletions packages/starknet-snap/src/signDeclareTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { toJson } from './utils/serializer';
import { Signature } from 'starknet';
import { ApiParams, SignDeclareTransactionRequestParams } from './types/snapApi';
import { getKeysFromAddress, signDeclareTransaction as signDeclareTransactionUtil } from './utils/starknetUtils';
import { getNetworkFromChainId, getSignTxnTxt } from './utils/snapUtils';
import {
getKeysFromAddress,
signDeclareTransaction as signDeclareTransactionUtil,
isUpgradeRequired,
} from './utils/starknetUtils';
import { getNetworkFromChainId, getSignTxnTxt, showUpgradeRequestModal } from './utils/snapUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';
Expand All @@ -15,6 +19,11 @@ export async function signDeclareTransaction(params: ApiParams): Promise<Signatu
const network = getNetworkFromChainId(state, requestParamsObj.chainId);
const { privateKey } = await getKeysFromAddress(keyDeriver, network, state, signerAddress);

if (await isUpgradeRequired(network, signerAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

logger.log(`signDeclareTransaction params: ${toJson(requestParamsObj.transaction, 2)}}`);

const snapComponents = getSignTxnTxt(signerAddress, network, requestParamsObj.transaction);
Expand Down
8 changes: 7 additions & 1 deletion packages/starknet-snap/src/signDeployAccountTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { ApiParams, SignDeployAccountTransactionRequestParams } from './types/sn
import {
getKeysFromAddress,
signDeployAccountTransaction as signDeployAccountTransactionUtil,
isUpgradeRequired,
} from './utils/starknetUtils';
import { getNetworkFromChainId, getSignTxnTxt } from './utils/snapUtils';
import { getNetworkFromChainId, getSignTxnTxt, showUpgradeRequestModal } from './utils/snapUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from '../src/utils/logger';
Expand All @@ -18,6 +19,11 @@ export async function signDeployAccountTransaction(params: ApiParams): Promise<S
const network = getNetworkFromChainId(state, requestParamsObj.chainId);
const { privateKey } = await getKeysFromAddress(keyDeriver, network, state, signerAddress);

if (await isUpgradeRequired(network, signerAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

logger.log(`signDeployAccountTransaction params: ${toJson(requestParamsObj.transaction, 2)}}`);

const snapComponents = getSignTxnTxt(signerAddress, network, requestParamsObj.transaction);
Expand Down
15 changes: 12 additions & 3 deletions packages/starknet-snap/src/signMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { toJson } from './utils/serializer';
import { signMessage as signMessageUtil, getKeysFromAddress, isUpgradeRequired } from './utils/starknetUtils';
import { getNetworkFromChainId, addDialogTxt } from './utils/snapUtils';
import {
signMessage as signMessageUtil,
getKeysFromAddress,
isUpgradeRequired,
validateAndParseAddress,
} from './utils/starknetUtils';
import { getNetworkFromChainId, addDialogTxt, showUpgradeRequestModal } from './utils/snapUtils';
import { ApiParams, SignMessageRequestParams } from './types/snapApi';
import { validateAndParseAddress } from '../src/utils/starknetUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';
Expand All @@ -15,6 +19,11 @@ export async function signMessage(params: ApiParams) {
const typedDataMessage = requestParamsObj.typedDataMessage;
const network = getNetworkFromChainId(state, requestParamsObj.chainId);

if (await isUpgradeRequired(network, signerAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

logger.log(`signMessage:\nsignerAddress: ${signerAddress}\ntypedDataMessage: ${toJson(typedDataMessage)}`);

if (!signerAddress) {
Expand Down
9 changes: 7 additions & 2 deletions packages/starknet-snap/src/signTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { toJson } from './utils/serializer';
import { Signature } from 'starknet';
import { ApiParams, SignTransactionRequestParams } from './types/snapApi';
import { getKeysFromAddress, signTransactions } from './utils/starknetUtils';
import { getNetworkFromChainId, getSignTxnTxt } from './utils/snapUtils';
import { getKeysFromAddress, signTransactions, isUpgradeRequired } from './utils/starknetUtils';
import { getNetworkFromChainId, getSignTxnTxt, showUpgradeRequestModal } from './utils/snapUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from '../src/utils/logger';
Expand All @@ -15,6 +15,11 @@ export async function signTransaction(params: ApiParams): Promise<Signature | bo
const network = getNetworkFromChainId(state, requestParamsObj.chainId);
const { privateKey } = await getKeysFromAddress(keyDeriver, network, state, signerAddress);

if (await isUpgradeRequired(network, signerAddress)) {
await showUpgradeRequestModal(wallet);
throw new Error('Upgrade required');
}

logger.log(`signTransaction params: ${toJson(requestParamsObj.transactions, 2)}}`);

const snapComponents = getSignTxnTxt(signerAddress, network, requestParamsObj.transactions);
Expand Down
18 changes: 17 additions & 1 deletion packages/starknet-snap/src/utils/snapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
constants,
} from 'starknet';
import { validateAndParseAddress } from './starknetUtils';
import { Component, text, copyable } from '@metamask/snaps-sdk';
import { Component, text, copyable, panel, heading } from '@metamask/snaps-sdk';
import {
Network,
Erc20Token,
Expand Down Expand Up @@ -42,6 +42,7 @@ import {
ChainIdFilter,
} from './transaction/filter';
import { logger } from './logger';
import { DialogType } from '@metamask/rpc-methods';

function hasOnlyAsciiChars(str: string) {
return /^[ -~]+$/.test(str);
Expand Down Expand Up @@ -757,3 +758,18 @@ export function dappUrl(envt: string) {
return DAPP.prod;
}
}

export async function showUpgradeRequestModal(wallet) {
await wallet.request({
method: 'snap_dialog',
params: {
type: DialogType.Alert,
content: panel([
heading('Account Upgrade Mandatory!'),
text(
`Visit the [companion dapp for Starknet](${dappUrl(process.env.SNAP_ENV)}) and click “Upgrade”.\nThank you!`,
),
]),
},
});
}
19 changes: 19 additions & 0 deletions packages/starknet-snap/test/src/declareContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { WalletMock } from '../wallet.mock.test';
import * as utils from '../../src/utils/starknetUtils';
import * as snapsUtil from '../../src/utils/snapUtils';
import { declareContract } from '../../src/declareContract';
import { SnapState } from '../../src/types/snapState';
import { STARKNET_MAINNET_NETWORK, STARKNET_SEPOLIA_TESTNET_NETWORK } from '../../src/utils/constants';
Expand Down Expand Up @@ -55,7 +56,23 @@ describe('Test function: declareContract', function () {
sandbox.restore();
});

it('should 1) throw an error and 2) show upgrade modal if account deployed required', async function () {
const isUpgradeRequiredStub = sandbox.stub(utils, 'isUpgradeRequired').resolves(true);
const showUpgradeRequestModalStub = sandbox.stub(snapsUtil, 'showUpgradeRequestModal').resolves();
let result;
try {
result = await declareContract(apiParams);
} catch (err) {
result = err;
} finally {
expect(isUpgradeRequiredStub).to.have.been.calledOnceWith(STARKNET_SEPOLIA_TESTNET_NETWORK, account1.address);
expect(showUpgradeRequestModalStub).to.have.been.calledOnce;
expect(result).to.be.an('Error');
}
});

it('should declareContract correctly', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
const declareContractStub = sandbox.stub(utils, 'declareContract').resolves({
transaction_hash: 'transaction_hash',
class_hash: 'class_hash',
Expand Down Expand Up @@ -83,6 +100,7 @@ describe('Test function: declareContract', function () {
});

it('should throw error if declareContract fail', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
const declareContractStub = sandbox.stub(utils, 'declareContract').rejects('error');
const { privateKey } = await utils.getKeysFromAddress(
apiParams.keyDeriver,
Expand All @@ -109,6 +127,7 @@ describe('Test function: declareContract', function () {
});

it('should return false if user rejected to sign the transaction', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
walletStub.rpcStubs.snap_dialog.resolves(false);
const declareContractStub = sandbox.stub(utils, 'declareContract').resolves({
transaction_hash: 'transaction_hash',
Expand Down
22 changes: 22 additions & 0 deletions packages/starknet-snap/test/src/executeTxn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
estimateFeeResp,
} from '../constants.test';
import * as createAccountUtils from '../../src/createAccount';
import * as snapsUtil from '../../src/utils/snapUtils';
import { getAddressKeyDeriver } from '../../src/utils/keyPair';
import { Mutex } from 'async-mutex';
import { ApiParams, ExecuteTxnRequestParams } from '../../src/types/snapApi';
Expand Down Expand Up @@ -79,7 +80,23 @@ describe('Test function: executeTxn', function () {
apiParams.requestParams = requestObject;
});

it('should 1) throw an error and 2) show upgrade modal if account deployed required', async function () {
const isUpgradeRequiredStub = sandbox.stub(utils, 'isUpgradeRequired').resolves(true);
const showUpgradeRequestModalStub = sandbox.stub(snapsUtil, 'showUpgradeRequestModal').resolves();
let result;
try {
result = await executeTxn(apiParams);
} catch (err) {
result = err;
} finally {
expect(isUpgradeRequiredStub).to.have.been.calledOnceWith(STARKNET_MAINNET_NETWORK, account1.address);
expect(showUpgradeRequestModalStub).to.have.been.calledOnce;
expect(result).to.be.an('Error');
}
});

it('should executeTxn correctly and deploy an account', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
sandbox.stub(utils, 'isAccountDeployed').resolves(false);
const createAccountStub = sandbox.stub(createAccountUtils, 'createAccount').resolvesThis();
const stub = sandbox.stub(utils, 'executeTxn').resolves({
Expand Down Expand Up @@ -111,6 +128,7 @@ describe('Test function: executeTxn', function () {
});

it('should executeTxn multiple and deploy an account', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
sandbox.stub(utils, 'isAccountDeployed').resolves(false);
const createAccountStub = sandbox.stub(createAccountUtils, 'createAccount').resolvesThis();
const stub = sandbox.stub(utils, 'executeTxn').resolves({
Expand Down Expand Up @@ -171,6 +189,7 @@ describe('Test function: executeTxn', function () {

it('should executeTxn and not deploy an account', async function () {
const createAccountStub = sandbox.stub(createAccountUtils, 'createAccount');
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
sandbox.stub(utils, 'isAccountDeployed').resolves(true);
const stub = sandbox.stub(utils, 'executeTxn').resolves({
transaction_hash: 'transaction_hash',
Expand Down Expand Up @@ -204,6 +223,7 @@ describe('Test function: executeTxn', function () {

it('should executeTxn multiple and not deploy an account', async function () {
const createAccountStub = sandbox.stub(createAccountUtils, 'createAccount');
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
sandbox.stub(utils, 'isAccountDeployed').resolves(true);
const stub = sandbox.stub(utils, 'executeTxn').resolves({
transaction_hash: 'transaction_hash',
Expand Down Expand Up @@ -262,6 +282,7 @@ describe('Test function: executeTxn', function () {
});

it('should throw error if executeTxn fail', async function () {
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
sandbox.stub(utils, 'isAccountDeployed').resolves(true);
const stub = sandbox.stub(utils, 'executeTxn').rejects('error');
const { privateKey } = await utils.getKeysFromAddress(
Expand Down Expand Up @@ -295,6 +316,7 @@ describe('Test function: executeTxn', function () {

it('should return false if user rejected to sign the transaction', async function () {
sandbox.stub(utils, 'isAccountDeployed').resolves(true);
sandbox.stub(utils, 'isUpgradeRequired').resolves(false);
walletStub.rpcStubs.snap_dialog.resolves(false);
const stub = sandbox.stub(utils, 'executeTxn').resolves({
transaction_hash: 'transaction_hash',
Expand Down
Loading

0 comments on commit 4d8a2d7

Please sign in to comment.