aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-02 23:34:45 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-02 23:34:45 +0800
commit21e76484d628d7861b09f013116121101e67334c (patch)
tree660ac0a79a528bd1d59ce7c3d115df298b1a4038 /test
parent432f516ab005dd2b4eb4b2e8766ed30216386d98 (diff)
downloadtangerine-wallet-browser-21e76484d628d7861b09f013116121101e67334c.tar.gz
tangerine-wallet-browser-21e76484d628d7861b09f013116121101e67334c.tar.zst
tangerine-wallet-browser-21e76484d628d7861b09f013116121101e67334c.zip
add test for addTxDefaults
Diffstat (limited to 'test')
-rw-r--r--test/unit/tx-controller-test.js35
1 files changed, 30 insertions, 5 deletions
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 6e42e8e68..fc70da9a2 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -5,12 +5,13 @@ const ObservableStore = require('obs-store')
const clone = require('clone')
const sinon = require('sinon')
const TransactionController = require('../../app/scripts/controllers/transactions')
+const TxProvideUtils = require('../../app/scripts/lib/tx-utils')
const noop = () => true
const currentNetworkId = 42
const otherNetworkId = 36
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
-describe.only('Transaction Controller', function () {
+describe('Transaction Controller', function () {
let txController
beforeEach(function () {
@@ -26,19 +27,19 @@ describe.only('Transaction Controller', function () {
}),
})
txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
- const queryStubResult = {}
txController.query = new Proxy({}, {
- get: (_, key) => {
+ get: (queryStubResult, key) => {
if (key === 'stubResult') {
return function (method, ...args) {
queryStubResult[method] = args
}
} else {
- returnValue = queryStubResult[key]
- return () => Promise.resolve(...returnValue)
+ const returnValues = queryStubResult[key]
+ return () => Promise.resolve(...returnValues)
}
},
})
+ txController.txProviderUtils = new TxProvideUtils(txController.query)
})
describe('#addUnapprovedTransaction', function () {
@@ -60,6 +61,30 @@ describe.only('Transaction Controller', function () {
})
})
+ describe('#addTxDefaults', function () {
+ it('should add the tx defaults if their are none', function (done) {
+ let txMeta = {
+ 'txParams': {
+ 'from':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ 'to':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ },
+ }
+
+ txController.query.stubResult('gasPrice', '0x4a817c800')
+ txController.query.stubResult('getBlockByNumber', { gasLimit: '0x47b784' })
+ txController.query.stubResult('estimateGas', '0x5209')
+
+ txController.addTxDefaults(txMeta)
+ .then((txMetaWithDefaults) => {
+ assert(txMetaWithDefaults.txParams.value, '0x0','should have added 0x0 as the value')
+ assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price')
+ assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field')
+ done()
+ })
+ .catch(done)
+ })
+ })
+
describe('#validateTxParams', function () {
it('does not throw for positive values', function (done) {
var sample = {