Setting tx param type before signing transactions (#11497)

Fixes MetaMask/metamask-extension#11491
feature/default_network_editable
ryanml 3 years ago committed by GitHub
parent 9416d1ca71
commit 07601f4a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/scripts/controllers/transactions/index.js
  2. 53
      app/scripts/controllers/transactions/index.test.js

@ -24,6 +24,7 @@ import { hexWEIToDecGWEI } from '../../../../ui/helpers/utils/conversions.util';
import {
TRANSACTION_STATUSES,
TRANSACTION_TYPES,
TRANSACTION_ENVELOPE_TYPES,
} from '../../../../shared/constants/transaction';
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
import { GAS_LIMITS } from '../../../../shared/constants/gas';
@ -727,7 +728,11 @@ export default class TransactionController extends EventEmitter {
const txMeta = this.txStateManager.getTransaction(txId);
// add network/chain id
const chainId = this.getChainId();
const type = isEIP1559Transaction(txMeta)
? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET
: TRANSACTION_ENVELOPE_TYPES.LEGACY;
const txParams = {
type,
...txMeta.txParams,
chainId,
gasLimit: txMeta.txParams.gas,

@ -773,6 +773,59 @@ describe('Transaction Controller', function () {
});
});
describe('#signTransaction', function () {
let fromTxDataSpy;
beforeEach(function () {
fromTxDataSpy = sinon.spy(TransactionFactory, 'fromTxData');
});
afterEach(function () {
fromTxDataSpy.restore();
});
it('sets txParams.type to 0x0 (non-EIP-1559)', async function () {
txController.txStateManager._addTransactionsToState([
{
status: TRANSACTION_STATUSES.UNAPPROVED,
id: 1,
metamaskNetworkId: currentNetworkId,
history: [{}],
txParams: {
from: VALID_ADDRESS_TWO,
to: VALID_ADDRESS,
gasPrice: '0x77359400',
gas: '0x7b0d',
nonce: '0x4b',
},
},
]);
await txController.signTransaction('1');
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x0');
});
it('sets txParams.type to 0x2 (EIP-1559)', async function () {
txController.txStateManager._addTransactionsToState([
{
status: TRANSACTION_STATUSES.UNAPPROVED,
id: 2,
metamaskNetworkId: currentNetworkId,
history: [{}],
txParams: {
from: VALID_ADDRESS_TWO,
to: VALID_ADDRESS,
maxFeePerGas: '0x77359400',
maxPriorityFeePerGas: '0x77359400',
gas: '0x7b0d',
nonce: '0x4b',
},
},
]);
await txController.signTransaction('2');
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x2');
});
});
describe('#publishTransaction', function () {
let hash, txMeta, trackTransactionMetricsEventSpy;

Loading…
Cancel
Save