1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

fix: minimise public api of tx controller (#20361)

This commit is contained in:
OGPoyraz 2023-08-03 13:42:44 +02:00 committed by GitHub
parent 8c46f85764
commit e351a6bbe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 599 additions and 603 deletions

File diff suppressed because it is too large Load Diff

View File

@ -750,11 +750,11 @@ describe('Transaction Controller', function () {
providerResultStub.eth_estimateGas = '0x5209';
signStub = sinon
.stub(txController, 'signTransaction')
.stub(txController, '_signTransaction')
.callsFake(() => Promise.resolve());
const pubStub = sinon
.stub(txController, 'publishTransaction')
.stub(txController, '_publishTransaction')
.callsFake(() => {
const txId = getLastTxMeta().id;
txController.setTxHash(txId, originalValue);
@ -1212,7 +1212,7 @@ describe('Transaction Controller', function () {
});
});
describe('#addTxGasDefaults', function () {
describe('_addTxGasDefaults', function () {
it('should add the tx defaults if their are none', async function () {
txController.txStateManager._addTransactionsToState([
{
@ -1238,7 +1238,7 @@ describe('Transaction Controller', function () {
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
providerResultStub.eth_estimateGas = '5209';
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
const txMetaWithDefaults = await txController._addTxGasDefaults(txMeta);
assert.ok(
txMetaWithDefaults.txParams.gasPrice,
'should have added the gas price',
@ -1254,7 +1254,7 @@ describe('Transaction Controller', function () {
const TEST_MAX_PRIORITY_FEE_PER_GAS = '0x77359400';
const stub1 = sinon
.stub(txController, 'getEIP1559Compatibility')
.stub(txController, '_getEIP1559Compatibility')
.returns(true);
const stub2 = sinon
@ -1287,7 +1287,7 @@ describe('Transaction Controller', function () {
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
providerResultStub.eth_estimateGas = '5209';
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
const txMetaWithDefaults = await txController._addTxGasDefaults(txMeta);
assert.equal(
txMetaWithDefaults.txParams.maxFeePerGas,
@ -1307,7 +1307,7 @@ describe('Transaction Controller', function () {
const TEST_GASPRICE = '0x12a05f200';
const stub1 = sinon
.stub(txController, 'getEIP1559Compatibility')
.stub(txController, '_getEIP1559Compatibility')
.returns(true);
const stub2 = sinon
@ -1337,7 +1337,7 @@ describe('Transaction Controller', function () {
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
providerResultStub.eth_estimateGas = '5209';
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
const txMetaWithDefaults = await txController._addTxGasDefaults(txMeta);
assert.equal(
txMetaWithDefaults.txParams.maxFeePerGas,
@ -1357,7 +1357,7 @@ describe('Transaction Controller', function () {
const TEST_GASPRICE = '0x12a05f200';
const stub1 = sinon
.stub(txController, 'getEIP1559Compatibility')
.stub(txController, '_getEIP1559Compatibility')
.returns(true);
const stub2 = sinon
@ -1389,7 +1389,7 @@ describe('Transaction Controller', function () {
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
providerResultStub.eth_estimateGas = '5209';
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
const txMetaWithDefaults = await txController._addTxGasDefaults(txMeta);
assert.equal(
txMetaWithDefaults.txParams.maxFeePerGas,
@ -1411,7 +1411,7 @@ describe('Transaction Controller', function () {
const TEST_MAX_PRIORITY_FEE_PER_GAS = '0x77359400';
const stub1 = sinon
.stub(txController, 'getEIP1559Compatibility')
.stub(txController, '_getEIP1559Compatibility')
.returns(true);
const stub2 = sinon
@ -1443,7 +1443,7 @@ describe('Transaction Controller', function () {
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' };
providerResultStub.eth_estimateGas = '5209';
const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta);
const txMetaWithDefaults = await txController._addTxGasDefaults(txMeta);
assert.equal(
txMetaWithDefaults.txParams.maxFeePerGas,
@ -1547,27 +1547,27 @@ describe('Transaction Controller', function () {
},
noop,
);
const rawTx = await txController.signTransaction('1');
const rawTx = await txController._signTransaction('1');
const ethTx = TransactionFactory.fromSerializedData(toBuffer(rawTx));
assert.equal(Number(ethTx.common.chainId()), 5);
});
});
describe('#getChainId', function () {
describe('_getChainId', function () {
it('returns the chain ID of the network when it is available', function () {
networkStatusStore.putState(NetworkStatus.Available);
assert.equal(txController.getChainId(), 5);
assert.equal(txController._getChainId(), 5);
});
it('returns 0 when the network is not available', function () {
networkStatusStore.putState('asdflsfadf');
assert.equal(txController.getChainId(), 0);
networkStatusStore.putState('NOT_INTEGER');
assert.equal(txController._getChainId(), 0);
});
it('returns 0 when the chain ID cannot be parsed as a hex string', function () {
networkStatusStore.putState(NetworkStatus.Available);
getCurrentChainId.returns('$fdsjfldf');
assert.equal(txController.getChainId(), 0);
getCurrentChainId.returns('NOT_INTEGER');
assert.equal(txController._getChainId(), 0);
});
});
@ -1795,13 +1795,13 @@ describe('Transaction Controller', function () {
},
},
]);
await txController.signTransaction('1');
await txController._signTransaction('1');
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x0');
});
it('sets txParams.type to 0x2 (EIP-1559)', async function () {
const eip1559CompatibilityStub = sinon
.stub(txController, 'getEIP1559Compatibility')
.stub(txController, '_getEIP1559Compatibility')
.returns(true);
txController.txStateManager._addTransactionsToState([
{
@ -1819,13 +1819,13 @@ describe('Transaction Controller', function () {
},
},
]);
await txController.signTransaction('2');
await txController._signTransaction('2');
assert.equal(fromTxDataSpy.getCall(0).args[0].type, '0x2');
eip1559CompatibilityStub.restore();
});
});
describe('#publishTransaction', function () {
describe('_publishTransaction', function () {
let hash, txMeta, trackTransactionMetricsEventSpy;
beforeEach(function () {
@ -1856,7 +1856,7 @@ describe('Transaction Controller', function () {
const rawTx =
'0x477b2e6553c917af0db0388ae3da62965ff1a184558f61b749d1266b2e6d024c';
txController.txStateManager.addTransaction(txMeta);
await txController.publishTransaction(txMeta.id, rawTx);
await txController._publishTransaction(txMeta.id, rawTx);
const publishedTx = txController.txStateManager.getTransaction(1);
assert.equal(publishedTx.hash, hash);
assert.equal(publishedTx.status, TransactionStatus.submitted);
@ -1869,7 +1869,7 @@ describe('Transaction Controller', function () {
const rawTx =
'0xf86204831e848082520894f231d46dd78806e1dd93442cf33c7671f853874880802ca05f973e540f2d3c2f06d3725a626b75247593cb36477187ae07ecfe0a4db3cf57a00259b52ee8c58baaa385fb05c3f96116e58de89bcc165cb3bfdfc708672fed8a';
txController.txStateManager.addTransaction(txMeta);
await txController.publishTransaction(txMeta.id, rawTx);
await txController._publishTransaction(txMeta.id, rawTx);
const publishedTx = txController.txStateManager.getTransaction(1);
assert.equal(
publishedTx.hash,
@ -1882,7 +1882,7 @@ describe('Transaction Controller', function () {
const rawTx =
'0x477b2e6553c917af0db0388ae3da62965ff1a184558f61b749d1266b2e6d024c';
txController.txStateManager.addTransaction(txMeta);
await txController.publishTransaction(txMeta.id, rawTx);
await txController._publishTransaction(txMeta.id, rawTx);
assert.equal(trackTransactionMetricsEventSpy.callCount, 1);
assert.deepEqual(
trackTransactionMetricsEventSpy.getCall(0).args[0],