aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app/controllers/transactions/tx-controller-test.js
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2019-05-15 02:14:07 +0800
committerFrankie <frankie.diamond@gmail.com>2019-05-15 02:14:07 +0800
commitb81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0 (patch)
treef2deb9c7ebb567e02e6fed5f4510062e584f655e /test/unit/app/controllers/transactions/tx-controller-test.js
parent3b01ba8741543d54bd2c3aad6a8ea0ef352e8924 (diff)
downloadtangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar.gz
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar.bz2
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar.lz
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar.xz
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.tar.zst
tangerine-wallet-browser-b81c4e5c98cdf3f5e6ebb05e57c2be993cdf5da0.zip
Set a default value for code in _determineTransactionCategory (#6604)
* Set a default value for code in _determineTransactionCategory * Adds e2e tests that fail when token txs without gas param are not properly handled. * Adds unit tests for _determineTransactionCategory * Base error throwing and simple gas setting in estimateTxGas on transactionCategory
Diffstat (limited to 'test/unit/app/controllers/transactions/tx-controller-test.js')
-rw-r--r--test/unit/app/controllers/transactions/tx-controller-test.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js
index 9000cd364..8ff409207 100644
--- a/test/unit/app/controllers/transactions/tx-controller-test.js
+++ b/test/unit/app/controllers/transactions/tx-controller-test.js
@@ -8,6 +8,13 @@ const TransactionController = require('../../../../../app/scripts/controllers/tr
const {
TRANSACTION_TYPE_RETRY,
} = require('../../../../../app/scripts/controllers/transactions/enums')
+const {
+ TOKEN_METHOD_APPROVE,
+ TOKEN_METHOD_TRANSFER,
+ SEND_ETHER_ACTION_KEY,
+ DEPLOY_CONTRACT_ACTION_KEY,
+ CONTRACT_INTERACTION_KEY,
+} = require('../../../../../ui/app/helpers/constants/transactions.js')
const { createTestProviderTools, getTestAccounts } = require('../../../../stub/provider')
const noop = () => true
@@ -537,6 +544,86 @@ describe('Transaction Controller', function () {
})
})
+ describe('#_determineTransactionCategory', function () {
+ it('should return a simple send transactionCategory when to is truthy but data is falsey', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '0xabc',
+ data: '',
+ })
+ assert.deepEqual(result, { transactionCategory: SEND_ETHER_ACTION_KEY, getCodeResponse: undefined })
+ })
+
+ it('should return a token transfer transactionCategory when data is for the respective method call', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '0xabc',
+ data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
+ })
+ assert.deepEqual(result, { transactionCategory: TOKEN_METHOD_TRANSFER, getCodeResponse: undefined })
+ })
+
+ it('should return a token approve transactionCategory when data is for the respective method call', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '0xabc',
+ data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
+ })
+ assert.deepEqual(result, { transactionCategory: TOKEN_METHOD_APPROVE, getCodeResponse: undefined })
+ })
+
+ it('should return a contract deployment transactionCategory when to is falsey and there is data', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '',
+ data: '0xabd',
+ })
+ assert.deepEqual(result, { transactionCategory: DEPLOY_CONTRACT_ACTION_KEY, getCodeResponse: undefined })
+ })
+
+ it('should return a simple send transactionCategory with a 0x getCodeResponse when there is data and but the to address is not a contract address', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
+ data: '0xabd',
+ })
+ assert.deepEqual(result, { transactionCategory: SEND_ETHER_ACTION_KEY, getCodeResponse: '0x' })
+ })
+
+ it('should return a simple send transactionCategory with a null getCodeResponse when to is truthy and there is data and but getCode returns an error', async function () {
+ const result = await txController._determineTransactionCategory({
+ to: '0xabc',
+ data: '0xabd',
+ })
+ assert.deepEqual(result, { transactionCategory: SEND_ETHER_ACTION_KEY, getCodeResponse: null })
+ })
+
+ it('should return a contract interaction transactionCategory with the correct getCodeResponse when to is truthy and there is data and it is not a token transaction', async function () {
+ const _providerResultStub = {
+ // 1 gwei
+ eth_gasPrice: '0x0de0b6b3a7640000',
+ // by default, all accounts are external accounts (not contracts)
+ eth_getCode: '0xa',
+ }
+ const _provider = createTestProviderTools({ scaffold: _providerResultStub }).provider
+ const _fromAccount = getTestAccounts()[0]
+ const _blockTrackerStub = new EventEmitter()
+ _blockTrackerStub.getCurrentBlock = noop
+ _blockTrackerStub.getLatestBlock = noop
+ const _txController = new TransactionController({
+ provider: _provider,
+ getGasPrice: function () { return '0xee6b2800' },
+ networkStore: new ObservableStore(currentNetworkId),
+ txHistoryLimit: 10,
+ blockTracker: _blockTrackerStub,
+ signTransaction: (ethTx) => new Promise((resolve) => {
+ ethTx.sign(_fromAccount.key)
+ resolve()
+ }),
+ })
+ const result = await _txController._determineTransactionCategory({
+ to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
+ data: 'abd',
+ })
+ assert.deepEqual(result, { transactionCategory: CONTRACT_INTERACTION_KEY, getCodeResponse: '0x0a' })
+ })
+ })
+
describe('#getPendingTransactions', function () {
beforeEach(function () {
txController.txStateManager._saveTxList([