Skip to content

Commit

Permalink
Added a test case and refactored a piece of code
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsekulic committed Jan 10, 2023
1 parent 31fe72d commit 1ba6012
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,12 @@ export default class TransactionController extends EventEmitter {
: '0x0';

if (txMethodType && this.securityProviderRequest) {
const flagAsDangerous = await this.securityProviderRequest(
const securityProviderResponse = await this.securityProviderRequest(
txMeta,
txMethodType,
);

txMeta.flagAsDangerous = flagAsDangerous;
txMeta.securityProviderResponse = securityProviderResponse;
}

this.addTransaction(txMeta);
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/controllers/transactions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,21 @@ describe('Transaction Controller', function () {
txController.txStateManager.getTransactions().length;
assert.equal(transactionCount1 + 1, transactionCount2);
});

it('should call securityProviderRequest and have flagAsDangerous inside txMeta', async function () {
const txMeta = await txController.addUnapprovedTransaction(
'eth_sendTransaction',
{
from: selectedAddress,
to: recipientAddress,
},
);

assert.ok(
'securityProviderResponse' in txMeta,
'should have a securityProviderResponse',
);
});
});

describe('#signTransaction', function () {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ export default class MessageManager extends EventEmitter {
};
this.addMsg(msgData);

const flagAsDangerous = await this.securityProviderRequest(
const securityProviderResponse = await this.securityProviderRequest(
msgData,
msgData.type,
);

msgData.flagAsDangerous = flagAsDangerous;
msgData.securityProviderResponse = securityProviderResponse;

// signal update
this.emit('update');
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/personal-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ export default class PersonalMessageManager extends EventEmitter {
};
this.addMsg(msgData);

const flagAsDangerous = await this.securityProviderRequest(
const securityProviderResponse = await this.securityProviderRequest(
msgData,
msgData.type,
);

msgData.flagAsDangerous = flagAsDangerous;
msgData.securityProviderResponse = securityProviderResponse;

// signal update
this.emit('update');
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/typed-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ export default class TypedMessageManager extends EventEmitter {
};
this.addMsg(msgData);

const flagAsDangerous = await this.securityProviderRequest(
const securityProviderResponse = await this.securityProviderRequest(
msgData,
msgData.type,
);

msgData.flagAsDangerous = flagAsDangerous;
msgData.securityProviderResponse = securityProviderResponse;

// signal update
this.emit('update');
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4545,13 +4545,14 @@ export default class MetamaskController extends EventEmitter {

if (transactionSecurityCheckEnabled) {
try {
const { flagAsDangerous } = await securityProviderCheck(
const securityProviderResponse = await securityProviderCheck(
requestData,
methodName,
chainId,
currentLocale,
);
return flagAsDangerous;

return securityProviderResponse;
} catch (err) {
log.error(err.message);
throw err;
Expand Down

0 comments on commit 1ba6012

Please sign in to comment.