From 901d23a02904a859901ca4f0bf5a6e42684567ec Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Apr 2016 17:32:09 -0700 Subject: Add extra tx methods to configManager --- test/unit/config-manager-test.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/unit') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 84632b0ea..a5ddf78a4 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -126,6 +126,16 @@ describe('config-manager', function() { }) }) + describe('#updateTx', function() { + it('replaces the tx with the same id', function() { + configManager.addTx({ id: '1', status: 'unconfirmed' }) + configManager.addTx({ id: '2', status: 'confirmed' }) + configManager.updateTx({ id: '1', status: 'blah', hash: 'foo' }) + var result = configManager.getTx('1') + assert.equal(result.hash, 'foo') + }) + }) + describe('#unconfirmedTxs', function() { it('returns unconfirmed txs in a hash', function() { configManager.addTx({ id: '1', status: 'unconfirmed' }) @@ -146,5 +156,31 @@ describe('config-manager', function() { assert.equal(configManager.getTx('2').status, 'confirmed') }) }) + + describe('#getTxWithParams', function() { + it('returns a tx with the matching params', function() { + configManager.addTx({ id: '1', status: 'unconfirmed', txParams: { + from: 'from', + to: 'to', + data: 'data', + value: 'value', + } + }) + configManager.addTx({ id: '2', status: 'unconfirmed', txParams: { + from: 'from1', + to: 'to', + data: 'data', + value: 'value', + } + }) + var result = configManager.getTxWithParams({ + from: 'from', + to: 'to', + data: 'data', + value: 'value', + }) + assert.equal(result.id, '1') + }) + }) }) }) -- cgit v1.2.3 From d6ab6bb4fa506c5fb9479b6e534ab74632c1b819 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Apr 2016 18:56:22 -0700 Subject: Fix floating point input bug When sending a transaction, we were converting to BN before handling decimals, which meant we were losing any precision past a decimal point, since BN does not handle decimals! Put this numeric normalization into a utility function with a test around it and got it working. --- test/unit/util_test.js | 68 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'test/unit') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 7f8103d3b..3f46d4e9b 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -82,33 +82,47 @@ describe('util', function() { }) - describe('#normalizeToWei', function() { - it('should convert an eth to the appropriate equivalent values', function() { - var valueTable = { - wei: '1000000000000000000', - kwei: '1000000000000000', - mwei: '1000000000000', - gwei: '1000000000', - szabo: '1000000', - finney:'1000', - ether: '1', - kether:'0.001', - mether:'0.000001', - // AUDIT: We're getting BN numbers on these ones. - // I think they're big enough to ignore for now. - // gether:'0.000000001', - // tether:'0.000000000001', - } - var oneEthBn = new ethUtil.BN(ethInWei, 10) - - for(var currency in valueTable) { - - var value = new ethUtil.BN(valueTable[currency], 10) - var output = util.normalizeToWei(value, currency) - assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`) - - } + describe('normalizing values', function() { + + describe('#normalizeToWei', function() { + it('should convert an eth to the appropriate equivalent values', function() { + var valueTable = { + wei: '1000000000000000000', + kwei: '1000000000000000', + mwei: '1000000000000', + gwei: '1000000000', + szabo: '1000000', + finney:'1000', + ether: '1', + // kether:'0.001', + // mether:'0.000001', + // AUDIT: We're getting BN numbers on these ones. + // I think they're big enough to ignore for now. + // gether:'0.000000001', + // tether:'0.000000000001', + } + var oneEthBn = new ethUtil.BN(ethInWei, 10) + + for(var currency in valueTable) { + + var value = new ethUtil.BN(valueTable[currency], 10) + var output = util.normalizeToWei(value, currency) + assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`) + } + }) }) - }) + describe('#normalizeNumberToWei', function() { + + it('should convert a kwei number to the appropriate equivalent wei', function() { + var result = util.normalizeNumberToWei(1.111, 'kwei') + assert.equal(result.toString(10), '1111', 'accepts decimals') + }) + + it('should convert a ether number to the appropriate equivalent wei', function() { + var result = util.normalizeNumberToWei(1.111, 'ether') + assert.equal(result.toString(10), '1111000000000000000', 'accepts decimals') + }) + }) + }) }) -- cgit v1.2.3 From 532edf670e8c30db958765141974f3fb0f5ec44c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 20 Apr 2016 09:29:37 -0700 Subject: Store metamaskId on metaTx instead of getTxWithParams method. --- test/unit/config-manager-test.js | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'test/unit') diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index a5ddf78a4..e414ecb9e 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -156,31 +156,5 @@ describe('config-manager', function() { assert.equal(configManager.getTx('2').status, 'confirmed') }) }) - - describe('#getTxWithParams', function() { - it('returns a tx with the matching params', function() { - configManager.addTx({ id: '1', status: 'unconfirmed', txParams: { - from: 'from', - to: 'to', - data: 'data', - value: 'value', - } - }) - configManager.addTx({ id: '2', status: 'unconfirmed', txParams: { - from: 'from1', - to: 'to', - data: 'data', - value: 'value', - } - }) - var result = configManager.getTxWithParams({ - from: 'from', - to: 'to', - data: 'data', - value: 'value', - }) - assert.equal(result.id, '1') - }) - }) }) }) -- cgit v1.2.3