|
|
|
@ -10,6 +10,7 @@ import { |
|
|
|
|
RINKEBY_CHAIN_ID, |
|
|
|
|
KOVAN_NETWORK_ID, |
|
|
|
|
} from '../../../../shared/constants/network'; |
|
|
|
|
import { GAS_LIMITS } from '../../../../shared/constants/gas'; |
|
|
|
|
import TxStateManager from './tx-state-manager'; |
|
|
|
|
import { snapshotFromTxMeta } from './lib/tx-state-history-helpers'; |
|
|
|
|
|
|
|
|
@ -1074,6 +1075,136 @@ describe('TransactionStateManager', function () { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('#generateTxMeta', function () { |
|
|
|
|
it('generates a txMeta object when supplied no parameters', function () { |
|
|
|
|
// There are currently not safety checks for missing 'opts' but we should
|
|
|
|
|
// at least enforce txParams. This is done in the transaction controller
|
|
|
|
|
// before *calling* this method, but we should perhaps ensure that
|
|
|
|
|
// txParams is provided and validated in this method.
|
|
|
|
|
// TODO: this test should fail.
|
|
|
|
|
const generatedTransaction = txStateManager.generateTxMeta(); |
|
|
|
|
assert.ok(generatedTransaction); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('generates a txMeta object with txParams specified', function () { |
|
|
|
|
const txParams = { |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
gasPrice: '0x0', |
|
|
|
|
}; |
|
|
|
|
const generatedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams, |
|
|
|
|
}); |
|
|
|
|
assert.ok(generatedTransaction); |
|
|
|
|
assert.strictEqual(generatedTransaction.txParams, txParams); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('generates a txMeta object with txParams specified using EIP-1559 fields', function () { |
|
|
|
|
const txParams = { |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
maxFeePerGas: '0x0', |
|
|
|
|
maxPriorityFeePerGas: '0x0', |
|
|
|
|
}; |
|
|
|
|
const generatedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams, |
|
|
|
|
}); |
|
|
|
|
assert.ok(generatedTransaction); |
|
|
|
|
assert.strictEqual(generatedTransaction.txParams, txParams); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('records dappSuggestedGasFees when origin is provided and is not "metamask"', function () { |
|
|
|
|
const eip1559GasFeeFields = { |
|
|
|
|
maxFeePerGas: '0x0', |
|
|
|
|
maxPriorityFeePerGas: '0x0', |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const legacyGasFeeFields = { |
|
|
|
|
gasPrice: '0x0', |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const eip1559TxParams = { |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
...eip1559GasFeeFields, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const legacyTxParams = { |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
...legacyGasFeeFields, |
|
|
|
|
}; |
|
|
|
|
const eip1559GeneratedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams: eip1559TxParams, |
|
|
|
|
origin: 'adappt.com', |
|
|
|
|
}); |
|
|
|
|
const legacyGeneratedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams: legacyTxParams, |
|
|
|
|
origin: 'adappt.com', |
|
|
|
|
}); |
|
|
|
|
assert.ok( |
|
|
|
|
eip1559GeneratedTransaction, |
|
|
|
|
'generated EIP1559 transaction should be truthy', |
|
|
|
|
); |
|
|
|
|
assert.deepStrictEqual( |
|
|
|
|
eip1559GeneratedTransaction.dappSuggestedGasFees, |
|
|
|
|
eip1559GasFeeFields, |
|
|
|
|
'generated EIP1559 transaction should have appropriate dappSuggestedGasFees', |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
|
legacyGeneratedTransaction, |
|
|
|
|
'generated legacy transaction should be truthy', |
|
|
|
|
); |
|
|
|
|
assert.deepStrictEqual( |
|
|
|
|
legacyGeneratedTransaction.dappSuggestedGasFees, |
|
|
|
|
legacyGasFeeFields, |
|
|
|
|
'generated legacy transaction should have appropriate dappSuggestedGasFees', |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('does not record dappSuggestedGasFees when transaction origin is "metamask"', function () { |
|
|
|
|
const txParams = { |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
maxFeePerGas: '0x0', |
|
|
|
|
maxPriorityFeePerGas: '0x0', |
|
|
|
|
}; |
|
|
|
|
const generatedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams, |
|
|
|
|
origin: 'metamask', |
|
|
|
|
}); |
|
|
|
|
assert.ok(generatedTransaction); |
|
|
|
|
assert.strictEqual(generatedTransaction.dappSuggestedGasFees, null); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('does not record dappSuggestedGasFees when transaction origin is not provided', function () { |
|
|
|
|
const txParams = { |
|
|
|
|
gas: GAS_LIMITS.SIMPLE, |
|
|
|
|
from: '0x0000', |
|
|
|
|
to: '0x000', |
|
|
|
|
value: '0x0', |
|
|
|
|
maxFeePerGas: '0x0', |
|
|
|
|
maxPriorityFeePerGas: '0x0', |
|
|
|
|
}; |
|
|
|
|
const generatedTransaction = txStateManager.generateTxMeta({ |
|
|
|
|
txParams, |
|
|
|
|
}); |
|
|
|
|
assert.ok(generatedTransaction); |
|
|
|
|
assert.strictEqual(generatedTransaction.dappSuggestedGasFees, null); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('#clearUnapprovedTxs', function () { |
|
|
|
|
it('removes unapproved transactions', function () { |
|
|
|
|
const txMetas = [ |
|
|
|
|