mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Setting tx param type before signing transactions (#11497)
Fixes MetaMask/metamask-extension#11491
This commit is contained in:
parent
9416d1ca71
commit
07601f4a90
@ -24,6 +24,7 @@ import { hexWEIToDecGWEI } from '../../../../ui/helpers/utils/conversions.util';
|
|||||||
import {
|
import {
|
||||||
TRANSACTION_STATUSES,
|
TRANSACTION_STATUSES,
|
||||||
TRANSACTION_TYPES,
|
TRANSACTION_TYPES,
|
||||||
|
TRANSACTION_ENVELOPE_TYPES,
|
||||||
} from '../../../../shared/constants/transaction';
|
} from '../../../../shared/constants/transaction';
|
||||||
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
|
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
|
||||||
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
import { GAS_LIMITS } from '../../../../shared/constants/gas';
|
||||||
@ -727,7 +728,11 @@ export default class TransactionController extends EventEmitter {
|
|||||||
const txMeta = this.txStateManager.getTransaction(txId);
|
const txMeta = this.txStateManager.getTransaction(txId);
|
||||||
// add network/chain id
|
// add network/chain id
|
||||||
const chainId = this.getChainId();
|
const chainId = this.getChainId();
|
||||||
|
const type = isEIP1559Transaction(txMeta)
|
||||||
|
? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET
|
||||||
|
: TRANSACTION_ENVELOPE_TYPES.LEGACY;
|
||||||
const txParams = {
|
const txParams = {
|
||||||
|
type,
|
||||||
...txMeta.txParams,
|
...txMeta.txParams,
|
||||||
chainId,
|
chainId,
|
||||||
gasLimit: txMeta.txParams.gas,
|
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 () {
|
describe('#publishTransaction', function () {
|
||||||
let hash, txMeta, trackTransactionMetricsEventSpy;
|
let hash, txMeta, trackTransactionMetricsEventSpy;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user