aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/tests
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-06-02 12:23:01 +0800
committerDan <danjm.com@gmail.com>2018-06-02 12:23:01 +0800
commit1b879f45bc0d53e8c0ffa9513b525e0055ed8f81 (patch)
treebee9cc6c9c0d22983ce462c597a87b45e89d4f49 /ui/app/components/send_/tests
parent701611e317d120d2c0530e4794bd498a74e233b2 (diff)
downloadtangerine-wallet-browser-1b879f45bc0d53e8c0ffa9513b525e0055ed8f81.tar.gz
tangerine-wallet-browser-1b879f45bc0d53e8c0ffa9513b525e0055ed8f81.tar.zst
tangerine-wallet-browser-1b879f45bc0d53e8c0ffa9513b525e0055ed8f81.zip
Fix calculation of data property for gas estimation on token transfers.
Diffstat (limited to 'ui/app/components/send_/tests')
-rw-r--r--ui/app/components/send_/tests/send-component.test.js2
-rw-r--r--ui/app/components/send_/tests/send-container.test.js7
-rw-r--r--ui/app/components/send_/tests/send-utils.test.js43
3 files changed, 30 insertions, 22 deletions
diff --git a/ui/app/components/send_/tests/send-component.test.js b/ui/app/components/send_/tests/send-component.test.js
index 2529d6e5f..4e33d8f63 100644
--- a/ui/app/components/send_/tests/send-component.test.js
+++ b/ui/app/components/send_/tests/send-component.test.js
@@ -34,7 +34,6 @@ describe('Send Component', function () {
amountConversionRate={'mockAmountConversionRate'}
blockGasLimit={'mockBlockGasLimit'}
conversionRate={10}
- data={'mockData'}
editingTransactionId={'mockEditingTransactionId'}
from={ { address: 'mockAddress', balance: 'mockBalance' } }
gasLimit={'mockGasLimit'}
@@ -210,7 +209,6 @@ describe('Send Component', function () {
propsMethodSpies.updateAndSetGasTotal.getCall(0).args[0],
{
blockGasLimit: 'mockBlockGasLimit',
- data: 'mockData',
editingTransactionId: 'mockEditingTransactionId',
gasLimit: 'mockGasLimit',
gasPrice: 'mockGasPrice',
diff --git a/ui/app/components/send_/tests/send-container.test.js b/ui/app/components/send_/tests/send-container.test.js
index d077ab4ee..056aad148 100644
--- a/ui/app/components/send_/tests/send-container.test.js
+++ b/ui/app/components/send_/tests/send-container.test.js
@@ -47,7 +47,6 @@ proxyquire('../send.container.js', {
'../../ducks/send.duck': duckActionSpies,
'./send.utils.js': {
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
- generateTokenTransferData: (a, b) => `mockData:${a + b}`,
},
})
@@ -61,7 +60,6 @@ describe('send container', () => {
amountConversionRate: 'mockAmountConversionRate:mockState',
blockGasLimit: 'mockBlockGasLimit:mockState',
conversionRate: 'mockConversionRate:mockState',
- data: 'mockData:mockSelectedAddress:mockStatemockSelectedToken:mockState',
editingTransactionId: 'mockEditingTransactionId:mockState',
from: 'mockFrom:mockState',
gasLimit: 'mockGasLimit:mockState',
@@ -92,7 +90,6 @@ describe('send container', () => {
describe('updateAndSetGasTotal()', () => {
const mockProps = {
blockGasLimit: 'mockBlockGasLimit',
- data: '0x1',
editingTransactionId: '0x2',
gasLimit: '0x3',
gasPrice: '0x4',
@@ -113,14 +110,14 @@ describe('send container', () => {
})
it('should dispatch an updateGasData action when editingTransactionId is falsy', () => {
- const { selectedAddress, selectedToken, data, recentBlocks, blockGasLimit, to, value } = mockProps
+ const { selectedAddress, selectedToken, recentBlocks, blockGasLimit, to, value } = mockProps
mapDispatchToPropsObject.updateAndSetGasTotal(
Object.assign({}, mockProps, {editingTransactionId: false})
)
assert(dispatchSpy.calledOnce)
assert.deepEqual(
actionSpies.updateGasData.getCall(0).args[0],
- { selectedAddress, selectedToken, data, recentBlocks, blockGasLimit, to, value }
+ { selectedAddress, selectedToken, recentBlocks, blockGasLimit, to, value }
)
})
})
diff --git a/ui/app/components/send_/tests/send-utils.test.js b/ui/app/components/send_/tests/send-utils.test.js
index 14125d7a6..b3f6372ef 100644
--- a/ui/app/components/send_/tests/send-utils.test.js
+++ b/ui/app/components/send_/tests/send-utils.test.js
@@ -106,11 +106,23 @@ describe('send utils', () => {
describe('generateTokenTransferData()', () => {
it('should return undefined if not passed a selected token', () => {
- assert.equal(generateTokenTransferData('mockAddress', false), undefined)
+ assert.equal(generateTokenTransferData({ toAddress: 'mockAddress', amount: '0xa', selectedToken: false}), undefined)
+ })
+
+ it('should call abi.rawEncode with the correct params', () => {
+ stubs.rawEncode.resetHistory()
+ generateTokenTransferData({ toAddress: 'mockAddress', amount: 'ab', selectedToken: true})
+ assert.deepEqual(
+ stubs.rawEncode.getCall(0).args,
+ [['address', 'uint256'], ['mockAddress', '0xab']]
+ )
})
it('should return encoded token transfer data', () => {
- assert.equal(generateTokenTransferData('mockAddress', true), '104c')
+ assert.equal(
+ generateTokenTransferData({ toAddress: 'mockAddress', amount: '0xa', selectedToken: true}),
+ '0xa9059cbb104c'
+ )
})
})
@@ -276,22 +288,17 @@ describe('send utils', () => {
assert.equal(result, 'mockToString:16')
})
- it('should call ethQuery.estimateGas with a value of 0x0 if the passed selectedToken has a symbol', async () => {
- const result = await estimateGas(Object.assign({ selectedToken: { symbol: true } }, baseMockParams))
+ it('should call ethQuery.estimateGas with a value of 0x0 and the expected data and to if passed a selectedToken', async () => {
+ const result = await estimateGas(Object.assign({ data: 'mockData', selectedToken: { address: 'mockAddress' } }, baseMockParams))
assert.equal(baseMockParams.estimateGasMethod.callCount, 1)
assert.deepEqual(
baseMockParams.estimateGasMethod.getCall(0).args[0],
- Object.assign({ gasPrice: undefined, value: '0x0' }, baseExpectedCall)
- )
- assert.equal(result, 'mockToString:16')
- })
-
- it('should call ethQuery.estimateGas with data if data is passed', async () => {
- const result = await estimateGas(Object.assign({ data: 'mockData' }, baseMockParams))
- assert.equal(baseMockParams.estimateGasMethod.callCount, 1)
- assert.deepEqual(
- baseMockParams.estimateGasMethod.getCall(0).args[0],
- Object.assign({ gasPrice: undefined, value: undefined, data: 'mockData' }, baseExpectedCall)
+ Object.assign({}, baseExpectedCall, {
+ gasPrice: undefined,
+ value: '0x0',
+ data: '0xa9059cbb104c',
+ to: 'mockAddress',
+ })
)
assert.equal(result, 'mockToString:16')
})
@@ -302,6 +309,12 @@ describe('send utils', () => {
assert.equal(result, SIMPLE_GAS_COST)
})
+ it(`should not return ${SIMPLE_GAS_COST} if passed a selectedToken`, async () => {
+ assert.equal(baseMockParams.estimateGasMethod.callCount, 0)
+ const result = await estimateGas(Object.assign({}, baseMockParams, { to: '0x123', selectedToken: { address: '' } }))
+ assert.notEqual(result, SIMPLE_GAS_COST)
+ })
+
it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async () => {
const result = await estimateGas(Object.assign({}, baseMockParams, {
to: 'isContract willFailBecauseOf:Transaction execution error.',