Skip to content

Commit

Permalink
Merge branch 'develop' into security_provider_metrics_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Oct 17, 2023
2 parents fcbc895 + 4af7578 commit efaed38
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
7 changes: 3 additions & 4 deletions shared/constants/security-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export enum BlockaidReason {
transferFarming = 'transfer_farming',
/** Direct theft of assets using transferFrom */
transferFromFarming = 'transfer_from_farming',
/** Malicious trade that results in the victim being drained */
unfairTrade = 'unfair_trade',

other = 'other',

// Locally defined
// MetaMask defined reasons
failed = 'Failed',
notApplicable = 'NotApplicable',
}
Expand All @@ -57,7 +55,8 @@ export enum BlockaidResultType {
Malicious = 'Malicious',
Warning = 'Warning',
Benign = 'Benign',
// Locally defined

// MetaMask defined result types
Failed = 'Failed',
NotApplicable = 'NotApplicable',
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/flask/ppom-blockaid-alert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Confirmation Security Alert - Blockaid', function () {

/**
* Disclaimer: This test does not test all reason types. e.g. 'blur_farming',
* 'malicious_domain', 'unfair_trade'. Some other tests are found in other files:
* 'malicious_domain'. Some other tests are found in other files:
* e.g. test/e2e/flask/ppom-blockaid-alert-<name>.spec.js
*/
it('should show security alerts for malicious requests', async function () {
Expand Down
1 change: 1 addition & 0 deletions test/jest/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const getInitialSendStateWithExistingTxState = (draftTxState) => ({
...draftTxState.recipient,
},
history: draftTxState.history ?? [],
userInputHexData: draftTxState.userInputHexData ?? null,
// Use this key if you want to console.log inside the send.js file.
test: draftTxState.test ?? 'yo',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const REASON_TO_DESCRIPTION_TKEY = Object.freeze({

[BlockaidReason.rawSignatureFarming]: 'blockaidDescriptionMightLoseAssets',
[BlockaidReason.tradeOrderFarming]: 'blockaidDescriptionMightLoseAssets',
[BlockaidReason.unfairTrade]: 'blockaidDescriptionMightLoseAssets',

[BlockaidReason.rawNativeTokenTransfer]: 'blockaidDescriptionTransferFarming',
[BlockaidReason.transferFarming]: 'blockaidDescriptionTransferFarming',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ describe('Blockaid Banner Alert', () => {
'If you approve this request, a third party known for scams will take all your assets.',
[BlockaidReason.transferFarming]:
'If you approve this request, a third party known for scams will take all your assets.',
[BlockaidReason.unfairTrade]:
'If you approve this request, you might lose your assets.',
}).forEach(([reason, expectedDescription]) => {
it(`should render for '${reason}' correctly`, () => {
const { getByText } = renderWithLocalization(
Expand Down
1 change: 1 addition & 0 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ const slice = createSlice({
slice.caseReducers.updateAmountToMax(state);
} else if (initialAssetSet === false) {
slice.caseReducers.updateSendAmount(state, { payload: '0x0' });
slice.caseReducers.updateUserInputHexData(state, { payload: '' });
}
// validate send state
slice.caseReducers.validateSendState(state);
Expand Down
27 changes: 27 additions & 0 deletions ui/ducks/send/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,33 @@ describe('Send Slice', () => {
);
});

it('should update hex data if its not the initial asset set', () => {
const updateAssetState = getInitialSendStateWithExistingTxState({
asset: {
type: 'old type',
balance: 'old balance',
},
userInputHexData: '0xTestHexData',
});

const action = {
type: 'send/updateAsset',
payload: {
asset: {
type: 'new type',
balance: 'new balance',
},
initialAssetSet: false,
},
};

const result = sendReducer(updateAssetState, action);

const draftTransaction = getTestUUIDTx(result);

expect(draftTransaction.userInputHexData).toStrictEqual('');
});

it('should nullify old contract address error when asset types is not TOKEN', () => {
const recipientErrorState = getInitialSendStateWithExistingTxState({
recipient: {
Expand Down

0 comments on commit efaed38

Please sign in to comment.