Skip to content

Commit 6157275

Browse files
committed
Ensure correct transaction category when sending to contracts but there is no txParams data
1 parent 8b5ac93 commit 6157275

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

app/scripts/controllers/transactions/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -603,21 +603,21 @@ class TransactionController extends EventEmitter {
603603
].find(tokenMethodName => tokenMethodName === name && name.toLowerCase())
604604

605605
let result
606-
let code
607-
if (!txParams.data) {
608-
result = SEND_ETHER_ACTION_KEY
609-
} else if (tokenMethodName) {
606+
if (txParams.data && tokenMethodName) {
610607
result = tokenMethodName
611-
} else if (!to) {
608+
} else if (txParams.data && !to) {
612609
result = DEPLOY_CONTRACT_ACTION_KEY
613-
} else {
610+
}
611+
612+
let code
613+
if (!result) {
614614
try {
615615
code = await this.query.getCode(to)
616616
} catch (e) {
617617
code = null
618618
log.warn(e)
619619
}
620-
// For an address with no code, geth will return '0x', and ganache-core v2.2.1 will return '0x0'
620+
621621
const codeIsEmpty = !code || code === '0x' || code === '0x0'
622622

623623
result = codeIsEmpty ? SEND_ETHER_ACTION_KEY : CONTRACT_INTERACTION_KEY

test/unit/app/controllers/transactions/tx-controller-test.js

+30
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,36 @@ describe('Transaction Controller', function () {
622622
})
623623
assert.deepEqual(result, { transactionCategory: CONTRACT_INTERACTION_KEY, getCodeResponse: '0x0a' })
624624
})
625+
626+
it('should return a contract interaction transactionCategory with the correct getCodeResponse when to is a contract address and data is falsey', async function () {
627+
const _providerResultStub = {
628+
// 1 gwei
629+
eth_gasPrice: '0x0de0b6b3a7640000',
630+
// by default, all accounts are external accounts (not contracts)
631+
eth_getCode: '0xa',
632+
}
633+
const _provider = createTestProviderTools({ scaffold: _providerResultStub }).provider
634+
const _fromAccount = getTestAccounts()[0]
635+
const _blockTrackerStub = new EventEmitter()
636+
_blockTrackerStub.getCurrentBlock = noop
637+
_blockTrackerStub.getLatestBlock = noop
638+
const _txController = new TransactionController({
639+
provider: _provider,
640+
getGasPrice: function () { return '0xee6b2800' },
641+
networkStore: new ObservableStore(currentNetworkId),
642+
txHistoryLimit: 10,
643+
blockTracker: _blockTrackerStub,
644+
signTransaction: (ethTx) => new Promise((resolve) => {
645+
ethTx.sign(_fromAccount.key)
646+
resolve()
647+
}),
648+
})
649+
const result = await _txController._determineTransactionCategory({
650+
to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9',
651+
data: '',
652+
})
653+
assert.deepEqual(result, { transactionCategory: CONTRACT_INTERACTION_KEY, getCodeResponse: '0x0a' })
654+
})
625655
})
626656

627657
describe('#getPendingTransactions', function () {

0 commit comments

Comments
 (0)