Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Jan 27, 2025
1 parent c73c35a commit 770c98d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 44 deletions.
4 changes: 1 addition & 3 deletions app/scripts/lib/ppom/ppom-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ describe('PPOMMiddleware', () => {
() => undefined,
);

expect(req.securityAlertResponse?.reason).toBe(
BlockaidReason.checkingChain,
);
expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress);
expect(req.securityAlertResponse?.result_type).toBe(
BlockaidResultType.Loading,
);
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/lib/ppom/ppom-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import { SIGNING_METHODS } from '../../../../shared/constants/transaction';
import { PreferencesController } from '../../controllers/preferences-controller';
import { AppStateController } from '../../controllers/app-state-controller';
import { SECURITY_ALERT_RESPONSE_CHECKING_CHAIN } from '../../../../shared/constants/security-provider';
import { getProviderConfig } from '../../../../shared/modules/selectors/networks';
import { trace, TraceContext, TraceName } from '../../../../shared/lib/trace';
import { LOADING_SECURITY_ALERT_RESPONSE } from '../../../../shared/constants/security-provider';
import {
generateSecurityAlertId,
handlePPOMError,
Expand Down Expand Up @@ -118,18 +118,18 @@ export function createPPOMMiddleware<
}),
);

const securityAlertResponseCheckingChain: SecurityAlertResponse = {
...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
const securityAlertResponseLoading: SecurityAlertResponse = {
...LOADING_SECURITY_ALERT_RESPONSE,
securityAlertId,
};

if (SIGNING_METHODS.includes(req.method)) {
appStateController.addSignatureSecurityAlertResponse(
securityAlertResponseCheckingChain,
securityAlertResponseLoading,
);
}

req.securityAlertResponse = securityAlertResponseCheckingChain;
req.securityAlertResponse = securityAlertResponseLoading;
} catch (error) {
req.securityAlertResponse = handlePPOMError(
error,
Expand Down
18 changes: 0 additions & 18 deletions app/scripts/lib/ppom/ppom-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
BlockaidReason,
BlockaidResultType,
LOADING_SECURITY_ALERT_RESPONSE,
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
SecurityAlertSource,
} from '../../../../shared/constants/security-provider';
import { AppStateController } from '../../controllers/app-state-controller';
Expand Down Expand Up @@ -303,23 +302,6 @@ describe('PPOM Utils', () => {
});
},
);

it('updates response indicating chain is not supported', async () => {
const ppomController = {} as PPOMController;
const CHAIN_ID_UNSUPPORTED_MOCK = '0x2';

await validateRequestWithPPOM({
...validateRequestWithPPOMOptionsBase,
ppomController,
chainId: CHAIN_ID_UNSUPPORTED_MOCK,
});

expect(updateSecurityAlertResponseMock).toHaveBeenCalledWith(
validateRequestWithPPOMOptionsBase.request.method,
SECURITY_ALERT_ID_MOCK,
SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED,
);
});
});

describe('generateSecurityAlertId', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('Transaction Utils', () => {
).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, {
...TRANSACTION_OPTIONS_MOCK,
securityAlertResponse: {
reason: BlockaidReason.checkingChain,
reason: BlockaidReason.inProgress,
result_type: BlockaidResultType.Loading,
securityAlertId: SECURITY_ALERT_ID_MOCK,
},
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/lib/transaction/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
UpdateSecurityAlertResponse,
} from '../ppom/types';
import {
SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
LOADING_SECURITY_ALERT_RESPONSE,
SECURITY_PROVIDER_EXCLUDED_TRANSACTION_TYPES,
} from '../../../../shared/constants/security-provider';
import { endTrace, TraceName } from '../../../../shared/lib/trace';
Expand Down Expand Up @@ -287,13 +287,13 @@ async function validateSecurity(request: AddTransactionRequest) {
updateSecurityAlertResponse,
});

const securityAlertResponseCheckingChain: SecurityAlertResponse = {
...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN,
const securityAlertResponseLoading: SecurityAlertResponse = {
...LOADING_SECURITY_ALERT_RESPONSE,
securityAlertId,
};

request.transactionOptions.securityAlertResponse =
securityAlertResponseCheckingChain;
securityAlertResponseLoading;
} catch (error) {
handlePPOMError(error, 'Error validating JSON RPC using PPOM: ');
}
Expand Down
13 changes: 0 additions & 13 deletions shared/constants/security-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export enum BlockaidReason {
errored = 'Error',
notApplicable = 'NotApplicable',
inProgress = 'validation_in_progress',
checkingChain = 'CheckingChain',
chainNotSupported = 'ChainNotSupported',
}

export enum BlockaidResultType {
Expand Down Expand Up @@ -102,17 +100,6 @@ export const LOADING_SECURITY_ALERT_RESPONSE: SecurityAlertResponse = {
reason: BlockaidReason.inProgress,
};

export const SECURITY_ALERT_RESPONSE_CHECKING_CHAIN: SecurityAlertResponse = {
result_type: BlockaidResultType.Loading,
reason: BlockaidReason.checkingChain,
};

export const SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED: SecurityAlertResponse =
{
result_type: BlockaidResultType.Benign,
reason: BlockaidReason.chainNotSupported,
};

export enum SecurityAlertSource {
/** Validation performed remotely using the Security Alerts API. */
API = 'api',
Expand Down

0 comments on commit 770c98d

Please sign in to comment.