aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/helper.js8
-rw-r--r--test/integration/helpers.js4
-rw-r--r--test/integration/index.js8
-rw-r--r--test/integration/lib/first-time.js2
-rw-r--r--test/lib/migrations/001.json15
-rw-r--r--test/lib/mock-config-manager.js7
-rw-r--r--test/lib/mock-encryptor.js12
-rw-r--r--test/lib/mock-simple-keychain.js14
-rw-r--r--test/lib/mock-store.js18
-rw-r--r--test/unit/account-link-test.js8
-rw-r--r--test/unit/actions/config_test.js23
-rw-r--r--test/unit/actions/save_account_label_test.js21
-rw-r--r--test/unit/actions/set_selected_account_test.js23
-rw-r--r--test/unit/actions/tx_test.js92
-rw-r--r--test/unit/actions/view_info_test.js15
-rw-r--r--test/unit/actions/warning_test.js13
-rw-r--r--test/unit/address-book-controller.js16
-rw-r--r--test/unit/components/binary-renderer-test.js10
-rw-r--r--test/unit/components/bn-as-decimal-input-test.js51
-rw-r--r--test/unit/components/pending-tx-test.js77
-rw-r--r--test/unit/config-manager-test.js42
-rw-r--r--test/unit/currency-controller-test.js43
-rw-r--r--test/unit/explorer-link-test.js8
-rw-r--r--test/unit/keyring-controller-test.js61
-rw-r--r--test/unit/linting_test.js6
-rw-r--r--test/unit/message-manager-test.js41
-rw-r--r--test/unit/metamask-controller-test.js16
-rw-r--r--test/unit/migrations-test.js10
-rw-r--r--test/unit/migrator-test.js41
-rw-r--r--test/unit/nameForAccount_test.js17
-rw-r--r--test/unit/network-contoller-test.js77
-rw-r--r--test/unit/nodeify-test.js8
-rw-r--r--test/unit/notice-controller-test.js71
-rw-r--r--test/unit/personal-message-manager-test.js47
-rw-r--r--test/unit/reducers/unlock_vault_test.js27
-rw-r--r--test/unit/tx-controller-test.js323
-rw-r--r--test/unit/tx-manager-test.js241
-rw-r--r--test/unit/tx-utils-test.js32
-rw-r--r--test/unit/util_test.js119
39 files changed, 987 insertions, 680 deletions
diff --git a/test/helper.js b/test/helper.js
index aaac7580e..1c5934a89 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -20,14 +20,12 @@ window.localStorage = {}
if (!window.crypto) window.crypto = {}
if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
-
-
-function enableFailureOnUnhandledPromiseRejection() {
+function enableFailureOnUnhandledPromiseRejection () {
// overwrite node's promise with the stricter Bluebird promise
global.Promise = require('bluebird')
// modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
-
+
// rethrow unhandledRejections
if (typeof process !== 'undefined') {
process.on('unhandledRejection', function (reason) {
@@ -51,4 +49,4 @@ function enableFailureOnUnhandledPromiseRejection() {
typeof (console.error || console.log) === 'function') {
(console.error || console.log)('Unhandled rejections will be ignored!')
}
-} \ No newline at end of file
+}
diff --git a/test/integration/helpers.js b/test/integration/helpers.js
index eede103b4..10cd74e64 100644
--- a/test/integration/helpers.js
+++ b/test/integration/helpers.js
@@ -1,6 +1,6 @@
function wait(time) {
- return new Promise(function(resolve, reject) {
- setTimeout(function() {
+ return new Promise(function (resolve, reject) {
+ setTimeout(function () {
resolve()
}, time * 3 || 1500)
})
diff --git a/test/integration/index.js b/test/integration/index.js
index ff6d1baf8..f2d656b0b 100644
--- a/test/integration/index.js
+++ b/test/integration/index.js
@@ -1,10 +1,10 @@
var fs = require('fs')
var path = require('path')
-var browserify = require('browserify');
+var browserify = require('browserify')
var tests = fs.readdirSync(path.join(__dirname, 'lib'))
var bundlePath = path.join(__dirname, 'bundle.js')
-var b = browserify();
+var b = browserify()
// Remove old bundle
try {
@@ -13,9 +13,9 @@ try {
var writeStream = fs.createWriteStream(bundlePath)
-tests.forEach(function(fileName) {
+tests.forEach(function (fileName) {
b.add(path.join(__dirname, 'lib', fileName))
})
-b.bundle().pipe(writeStream);
+b.bundle().pipe(writeStream)
diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js
index dbb88a3da..6c8cedbac 100644
--- a/test/integration/lib/first-time.js
+++ b/test/integration/lib/first-time.js
@@ -11,7 +11,7 @@ QUnit.test('render init screen', function (assert) {
const recurseNotices = function () {
let button = app.find('button')
- if (button.html() === 'Continue') {
+ if (button.html() === 'Accept') {
let termsPage = app.find('.markdown')[0]
termsPage.scrollTop = termsPage.scrollHeight
return wait().then(() => {
diff --git a/test/lib/migrations/001.json b/test/lib/migrations/001.json
index 2fe6dd836..7bd55a50e 100644
--- a/test/lib/migrations/001.json
+++ b/test/lib/migrations/001.json
@@ -1 +1,14 @@
-{"version":0,"data":{"wallet":"{\"encSeed\":{\"encStr\":\"rT1C1jjkFRfmrwefscFcwZohl4f+HfIFlBZ9AM4ZD8atJmfKDIQCVK11NYDKYv8ZMIY03f3t8MuoZvfzBL8IJsWnZUhpzVTNNiARQJD2WpGA19eNBzgZm4vd0GwkIUruUDeJXu0iv2j9wU8hOQUqPbOePPy2Am5ro97iuvMAroRTnEKD60qFVg==\",\"nonce\":\"YUY2mwNq2v3FV0Fi94QnSiKFOLYfDR95\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"Iyi7ft4JQ9UtwrSXRT6ZIHPtZqJhe99rh0uWhNc6QLan6GanY2ZQeU0tt76CBealEWJyrJReSxGQdqDmSDYjpjH3m4JO5l0DfPLPseCqzXV/W+dzM0ubJ8lztLwpwi0L+vULNMqCx4dQtoNbNBq1QZUnjtpm6O8mWpScspboww==\",\"nonce\":\"Z7RqtjNjC6FrLUj5wVW1+HkjOW6Hib6K\"},\"hdIndex\":3,\"encPrivKeys\":{\"edb81c10122f34040cc4bef719a272fbbb1cf897\":{\"key\":\"8ab81tKBd4+CLAbzvS7SBFRTd6VWXBs86uBE43lgcmBu2U7UB22xdH64Q2hUf9eB\",\"nonce\":\"aGUEqI033FY39zKjWmZSI6PQrCLvkiRP\"},\"8bd7d5c000cf05284e98356370dc5ccaa3dbfc38\":{\"key\":\"+i3wmf4b+B898QtlOBfL0Ixirjg59/LLPX61vQ2L0xRPjXzNog0O4Wn15RemM5mY\",\"nonce\":\"imKrlkuoC5uuFkzJBbuDBluGCPJXNTKm\"},\"2340695474656e3124b8eba1172fbfb00eeac8f8\":{\"key\":\"pi+H9D8LYKsdCQKrfaJtsGFjE+X9s74xN675tsoIKrbPXhtpxMLOIQVtSqYveF62\",\"nonce\":\"49g80wDTovHwbguVVYf2FsYbp7Db5OAR\"}},\"addresses\":[\"edb81c10122f34040cc4bef719a272fbbb1cf897\",\"8bd7d5c000cf05284e98356370dc5ccaa3dbfc38\",\"2340695474656e3124b8eba1172fbfb00eeac8f8\"]}},\"version\":2}","config":{"provider":{"type":"etherscan"}}},"meta":{"version":0}} \ No newline at end of file
+{
+ "version": 0,
+ "data": {
+ "wallet": "{\"encSeed\":{\"encStr\":\"rT1C1jjkFRfmrwefscFcwZohl4f+HfIFlBZ9AM4ZD8atJmfKDIQCVK11NYDKYv8ZMIY03f3t8MuoZvfzBL8IJsWnZUhpzVTNNiARQJD2WpGA19eNBzgZm4vd0GwkIUruUDeJXu0iv2j9wU8hOQUqPbOePPy2Am5ro97iuvMAroRTnEKD60qFVg==\",\"nonce\":\"YUY2mwNq2v3FV0Fi94QnSiKFOLYfDR95\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"Iyi7ft4JQ9UtwrSXRT6ZIHPtZqJhe99rh0uWhNc6QLan6GanY2ZQeU0tt76CBealEWJyrJReSxGQdqDmSDYjpjH3m4JO5l0DfPLPseCqzXV/W+dzM0ubJ8lztLwpwi0L+vULNMqCx4dQtoNbNBq1QZUnjtpm6O8mWpScspboww==\",\"nonce\":\"Z7RqtjNjC6FrLUj5wVW1+HkjOW6Hib6K\"},\"hdIndex\":3,\"encPrivKeys\":{\"edb81c10122f34040cc4bef719a272fbbb1cf897\":{\"key\":\"8ab81tKBd4+CLAbzvS7SBFRTd6VWXBs86uBE43lgcmBu2U7UB22xdH64Q2hUf9eB\",\"nonce\":\"aGUEqI033FY39zKjWmZSI6PQrCLvkiRP\"},\"8bd7d5c000cf05284e98356370dc5ccaa3dbfc38\":{\"key\":\"+i3wmf4b+B898QtlOBfL0Ixirjg59/LLPX61vQ2L0xRPjXzNog0O4Wn15RemM5mY\",\"nonce\":\"imKrlkuoC5uuFkzJBbuDBluGCPJXNTKm\"},\"2340695474656e3124b8eba1172fbfb00eeac8f8\":{\"key\":\"pi+H9D8LYKsdCQKrfaJtsGFjE+X9s74xN675tsoIKrbPXhtpxMLOIQVtSqYveF62\",\"nonce\":\"49g80wDTovHwbguVVYf2FsYbp7Db5OAR\"}},\"addresses\":[\"edb81c10122f34040cc4bef719a272fbbb1cf897\",\"8bd7d5c000cf05284e98356370dc5ccaa3dbfc38\",\"2340695474656e3124b8eba1172fbfb00eeac8f8\"]}},\"version\":2}",
+ "config": {
+ "provider": {
+ "type": "etherscan"
+ }
+ }
+ },
+ "meta": {
+ "version": 0
+ }
+} \ No newline at end of file
diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js
index 72be86ed1..0cc6953bb 100644
--- a/test/lib/mock-config-manager.js
+++ b/test/lib/mock-config-manager.js
@@ -2,9 +2,8 @@ const ObservableStore = require('obs-store')
const clone = require('clone')
const ConfigManager = require('../../app/scripts/lib/config-manager')
const firstTimeState = require('../../app/scripts/first-time-state')
-const STORAGE_KEY = 'metamask-config'
-module.exports = function() {
- let store = new ObservableStore(clone(firstTimeState))
+module.exports = function () {
+ const store = new ObservableStore(clone(firstTimeState))
return new ConfigManager({ store })
-} \ No newline at end of file
+}
diff --git a/test/lib/mock-encryptor.js b/test/lib/mock-encryptor.js
index 09bbf7ad5..cdf13c507 100644
--- a/test/lib/mock-encryptor.js
+++ b/test/lib/mock-encryptor.js
@@ -4,28 +4,28 @@ let cacheVal
module.exports = {
- encrypt(password, dataObj) {
+ encrypt (password, dataObj) {
cacheVal = dataObj
return Promise.resolve(mockHex)
},
- decrypt(password, text) {
+ decrypt (password, text) {
return Promise.resolve(cacheVal || {})
},
- encryptWithKey(key, dataObj) {
+ encryptWithKey (key, dataObj) {
return this.encrypt(key, dataObj)
},
- decryptWithKey(key, text) {
+ decryptWithKey (key, text) {
return this.decrypt(key, text)
},
- keyFromPassword(password) {
+ keyFromPassword (password) {
return Promise.resolve(mockKey)
},
- generateSalt() {
+ generateSalt () {
return 'WHADDASALT!'
},
diff --git a/test/lib/mock-simple-keychain.js b/test/lib/mock-simple-keychain.js
index 615b3e537..d3addc3e8 100644
--- a/test/lib/mock-simple-keychain.js
+++ b/test/lib/mock-simple-keychain.js
@@ -6,32 +6,32 @@ const type = 'Simple Key Pair'
module.exports = class MockSimpleKeychain {
- static type() { return type }
+ static type () { return type }
- constructor(opts) {
+ constructor (opts) {
this.type = type
this.opts = opts || {}
this.wallets = []
}
- serialize() {
+ serialize () {
return [ fakeWallet.privKey ]
}
- deserialize(data) {
+ deserialize (data) {
if (!Array.isArray(data)) {
throw new Error('Simple keychain deserialize requires a privKey array.')
}
this.wallets = [ fakeWallet ]
}
- addAccounts(n = 1) {
- for(var i = 0; i < n; i++) {
+ addAccounts (n = 1) {
+ for (var i = 0; i < n; i++) {
this.wallets.push(fakeWallet)
}
}
- getAccounts() {
+ getAccounts () {
return this.wallets.map(w => w.address)
}
diff --git a/test/lib/mock-store.js b/test/lib/mock-store.js
new file mode 100644
index 000000000..0d50e2d9c
--- /dev/null
+++ b/test/lib/mock-store.js
@@ -0,0 +1,18 @@
+const createStore = require('redux').createStore
+const applyMiddleware = require('redux').applyMiddleware
+const thunkMiddleware = require('redux-thunk')
+const createLogger = require('redux-logger')
+const rootReducer = function () {}
+
+module.exports = configureStore
+
+const loggerMiddleware = createLogger()
+
+const createStoreWithMiddleware = applyMiddleware(
+ thunkMiddleware,
+ loggerMiddleware
+)(createStore)
+
+function configureStore (initialState) {
+ return createStoreWithMiddleware(rootReducer, initialState)
+}
diff --git a/test/unit/account-link-test.js b/test/unit/account-link-test.js
index 803a70f37..47a961d1f 100644
--- a/test/unit/account-link-test.js
+++ b/test/unit/account-link-test.js
@@ -1,18 +1,16 @@
var assert = require('assert')
var linkGen = require('../../ui/lib/account-link')
-describe('account-link', function() {
-
- it('adds ropsten prefix to ropsten test network', function() {
+describe('account-link', function () {
+ it('adds ropsten prefix to ropsten test network', function () {
var result = linkGen('account', '3')
assert.notEqual(result.indexOf('ropsten'), -1, 'ropsten included')
assert.notEqual(result.indexOf('account'), -1, 'account included')
})
- it('adds kovan prefix to kovan test network', function() {
+ it('adds kovan prefix to kovan test network', function () {
var result = linkGen('account', '42')
assert.notEqual(result.indexOf('kovan'), -1, 'kovan included')
assert.notEqual(result.indexOf('account'), -1, 'account included')
})
-
})
diff --git a/test/unit/actions/config_test.js b/test/unit/actions/config_test.js
index 14198fa8a..648f456fb 100644
--- a/test/unit/actions/config_test.js
+++ b/test/unit/actions/config_test.js
@@ -1,36 +1,34 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-
-describe ('config view actions', function() {
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+describe('config view actions', function () {
var initialState = {
metamask: {
rpcTarget: 'foo',
- frequentRpcList: []
+ frequentRpcList: [],
},
appState: {
currentView: {
name: 'accounts',
- }
- }
+ },
+ },
}
freeze(initialState)
- describe('SHOW_CONFIG_PAGE', function() {
- it('should set appState.currentView.name to config', function() {
+ describe('SHOW_CONFIG_PAGE', function () {
+ it('should set appState.currentView.name to config', function () {
var result = reducers(initialState, actions.showConfigPage())
assert.equal(result.appState.currentView.name, 'config')
})
})
- describe('SET_RPC_TARGET', function() {
-
- it('sets the state.metamask.rpcTarget property of the state to the action.value', function() {
+ describe('SET_RPC_TARGET', function () {
+ it('sets the state.metamask.rpcTarget property of the state to the action.value', function () {
const action = {
type: actions.SET_RPC_TARGET,
value: 'foo',
@@ -41,5 +39,4 @@ describe ('config view actions', function() {
assert.equal(result.metamask.provider.rpcTarget, 'foo')
})
})
-
})
diff --git a/test/unit/actions/save_account_label_test.js b/test/unit/actions/save_account_label_test.js
index 1df428b1d..c5ffd6cbf 100644
--- a/test/unit/actions/save_account_label_test.js
+++ b/test/unit/actions/save_account_label_test.js
@@ -1,22 +1,21 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('SAVE_ACCOUNT_LABEL', function() {
-
- it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function() {
+describe('SAVE_ACCOUNT_LABEL', function () {
+ it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () {
var initialState = {
metamask: {
identities: {
foo: {
- name: 'bar'
- }
+ name: 'bar',
+ },
},
- }
+ },
}
freeze(initialState)
@@ -24,13 +23,13 @@ describe('SAVE_ACCOUNT_LABEL', function() {
type: actions.SAVE_ACCOUNT_LABEL,
value: {
account: 'foo',
- label: 'baz'
+ label: 'baz',
},
}
freeze(action)
var resultingState = reducers(initialState, action)
assert.equal(resultingState.metamask.identities.foo.name, action.value.label)
- });
-});
+ })
+})
diff --git a/test/unit/actions/set_selected_account_test.js b/test/unit/actions/set_selected_account_test.js
index 2dc42d2ec..28b47d09d 100644
--- a/test/unit/actions/set_selected_account_test.js
+++ b/test/unit/actions/set_selected_account_test.js
@@ -1,18 +1,17 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('SET_SELECTED_ACCOUNT', function() {
-
- it('sets the state.appState.activeAddress property of the state to the action.value', function() {
+describe('SET_SELECTED_ACCOUNT', function () {
+ it('sets the state.appState.activeAddress property of the state to the action.value', function () {
var initialState = {
appState: {
activeAddress: 'foo',
- }
+ },
}
freeze(initialState)
@@ -24,15 +23,15 @@ describe('SET_SELECTED_ACCOUNT', function() {
var resultingState = reducers(initialState, action)
assert.equal(resultingState.appState.activeAddress, action.value)
- });
-});
+ })
+})
-describe('SHOW_ACCOUNT_DETAIL', function() {
- it('updates metamask state', function() {
+describe('SHOW_ACCOUNT_DETAIL', function () {
+ it('updates metamask state', function () {
var initialState = {
metamask: {
- selectedAddress: 'foo'
- }
+ selectedAddress: 'foo',
+ },
}
freeze(initialState)
diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js
index bd72a666e..0ea1bfdc7 100644
--- a/test/unit/actions/tx_test.js
+++ b/test/unit/actions/tx_test.js
@@ -1,29 +1,27 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var sinon = require('sinon')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('tx confirmation screen', function() {
-
- beforeEach(function() {
- this.sinon = sinon.sandbox.create();
- });
+describe('tx confirmation screen', function () {
+ beforeEach(function () {
+ this.sinon = sinon.sandbox.create()
+ })
- afterEach(function(){
- this.sinon.restore();
- });
+ afterEach(function () {
+ this.sinon.restore()
+ })
var initialState, result
- describe('when there is only one tx', function() {
+ describe('when there is only one tx', function () {
var firstTxId = 1457634084250832
- beforeEach(function() {
-
+ beforeEach(function () {
initialState = {
appState: {
currentView: {
@@ -34,70 +32,66 @@ describe('tx confirmation screen', function() {
unapprovedTxs: {
'1457634084250832': {
id: 1457634084250832,
- status: "unconfirmed",
+ status: 'unconfirmed',
time: 1457634084250,
- }
+ },
},
- }
+ },
}
freeze(initialState)
})
- describe('cancelTx', function() {
-
- before(function(done) {
+ describe('cancelTx', function () {
+ before(function (done) {
actions._setBackgroundConnection({
- approveTransaction(txId, cb) { cb('An error!') },
- cancelTransaction(txId) { /* noop */ },
- clearSeedWordCache(cb) { cb() },
+ approveTransaction (txId, cb) { cb('An error!') },
+ cancelTransaction (txId) { /* noop */ },
+ clearSeedWordCache (cb) { cb() },
})
- let action = actions.cancelTx({value: firstTxId})
+ const action = actions.cancelTx({value: firstTxId})
result = reducers(initialState, action)
done()
})
- it('should transition to the account detail view', function() {
+ it('should transition to the account detail view', function () {
assert.equal(result.appState.currentView.name, 'accountDetail')
})
- it('should have no unconfirmed txs remaining', function() {
+ it('should have no unconfirmed txs remaining', function () {
var count = getUnconfirmedTxCount(result)
assert.equal(count, 0)
})
})
- describe('sendTx', function() {
+ describe('sendTx', function () {
var result
- describe('when there is an error', function() {
-
- before(function(done) {
- alert = () => {/* noop */}
-
+ describe('when there is an error', function () {
+ before(function (done) {
actions._setBackgroundConnection({
- approveTransaction(txId, cb) { cb({message: 'An error!'}) },
+ approveTransaction (txId, cb) { cb({message: 'An error!'}) },
})
- actions.sendTx({id: firstTxId})(function(action) {
+ actions.sendTx({id: firstTxId})(function (action) {
result = reducers(initialState, action)
done()
})
})
- it('should stay on the page', function() {
+ it('should stay on the page', function () {
assert.equal(result.appState.currentView.name, 'confTx')
})
- it('should set errorMessage on the currentView', function() {
+ it('should set errorMessage on the currentView', function () {
assert(result.appState.currentView.errorMessage)
})
})
- describe('when there is success', function() {
- it('should complete tx and go home', function() {
+ describe('when there is success', function () {
+ it('should complete tx and go home', function () {
actions._setBackgroundConnection({
- approveTransaction(txId, cb) { cb() },
+ approveTransaction (txId, cb) { cb() },
})
var dispatchExpect = sinon.mock()
@@ -108,10 +102,10 @@ describe('tx confirmation screen', function() {
})
})
- describe('when there are two pending txs', function() {
+ describe('when there are two pending txs', function () {
var firstTxId = 1457634084250832
var result, initialState
- before(function(done) {
+ before(function (done) {
initialState = {
appState: {
currentView: {
@@ -122,42 +116,42 @@ describe('tx confirmation screen', function() {
unapprovedTxs: {
'1457634084250832': {
id: firstTxId,
- status: "unconfirmed",
+ status: 'unconfirmed',
time: 1457634084250,
},
'1457634084250833': {
id: 1457634084250833,
- status: "unconfirmed",
+ status: 'unconfirmed',
time: 1457634084255,
},
},
- }
+ },
}
freeze(initialState)
// Mocking a background connection:
actions._setBackgroundConnection({
- approveTransaction(firstTxId, cb) { cb() },
+ approveTransaction (firstTxId, cb) { cb() },
})
- let action = actions.sendTx({id: firstTxId})(function(action) {
+ actions.sendTx({id: firstTxId})(function (action) {
result = reducers(initialState, action)
})
done()
})
- it('should stay on the confTx view', function() {
+ it('should stay on the confTx view', function () {
assert.equal(result.appState.currentView.name, 'confTx')
})
- it('should transition to the first tx', function() {
+ it('should transition to the first tx', function () {
assert.equal(result.appState.currentView.context, 0)
})
})
})
-});
+})
-function getUnconfirmedTxCount(state) {
+function getUnconfirmedTxCount (state) {
var txs = state.metamask.unapprovedTxs
var count = Object.keys(txs).length
return count
diff --git a/test/unit/actions/view_info_test.js b/test/unit/actions/view_info_test.js
index 0558c6e42..69895d801 100644
--- a/test/unit/actions/view_info_test.js
+++ b/test/unit/actions/view_info_test.js
@@ -1,23 +1,22 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('SHOW_INFO_PAGE', function() {
-
- it('sets the state.appState.currentView.name property to info', function() {
+describe('SHOW_INFO_PAGE', function () {
+ it('sets the state.appState.currentView.name property to info', function () {
var initialState = {
appState: {
activeAddress: 'foo',
- }
+ },
}
freeze(initialState)
const action = actions.showInfoPage()
var resultingState = reducers(initialState, action)
assert.equal(resultingState.appState.currentView.name, 'info')
- });
-});
+ })
+})
diff --git a/test/unit/actions/warning_test.js b/test/unit/actions/warning_test.js
index 37be9ee85..28b565499 100644
--- a/test/unit/actions/warning_test.js
+++ b/test/unit/actions/warning_test.js
@@ -1,14 +1,13 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
var freeze = require('deep-freeze-strict')
var path = require('path')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('action DISPLAY_WARNING', function() {
-
- it('sets appState.warning to provided value', function() {
+describe('action DISPLAY_WARNING', function () {
+ it('sets appState.warning to provided value', function () {
var initialState = {
appState: {},
}
@@ -20,5 +19,5 @@ describe('action DISPLAY_WARNING', function() {
const resultingState = reducers(initialState, action)
assert.equal(resultingState.appState.warning, warningText, 'warning text set')
- });
-});
+ })
+})
diff --git a/test/unit/address-book-controller.js b/test/unit/address-book-controller.js
index f345b0328..655c9022c 100644
--- a/test/unit/address-book-controller.js
+++ b/test/unit/address-book-controller.js
@@ -1,5 +1,4 @@
const assert = require('assert')
-const extend = require('xtend')
const AddressBookController = require('../../app/scripts/controllers/address-book')
const mockKeyringController = {
@@ -7,21 +6,20 @@ const mockKeyringController = {
getState: function () {
return {
identities: {
- '0x0aaa' : {
+ '0x0aaa': {
address: '0x0aaa',
name: 'owned',
- }
- }
+ },
+ },
}
- }
- }
+ },
+ },
}
-
-describe('address-book-controller', function() {
+describe('address-book-controller', function () {
var addressBookController
- beforeEach(function() {
+ beforeEach(function () {
addressBookController = new AddressBookController({}, mockKeyringController)
})
diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js
index 3264faddc..ee2fa8b60 100644
--- a/test/unit/components/binary-renderer-test.js
+++ b/test/unit/components/binary-renderer-test.js
@@ -1,24 +1,22 @@
var assert = require('assert')
var BinaryRenderer = require('../../../ui/app/components/binary-renderer')
-describe('BinaryRenderer', function() {
-
+describe('BinaryRenderer', function () {
let binaryRenderer
const message = 'Hello, world!'
const buffer = new Buffer(message, 'utf8')
const hex = buffer.toString('hex')
- beforeEach(function() {
+ beforeEach(function () {
binaryRenderer = new BinaryRenderer()
})
- it('recovers message', function() {
+ it('recovers message', function () {
const result = binaryRenderer.hexToText(hex)
assert.equal(result, message)
})
-
- it('recovers message with hex prefix', function() {
+ it('recovers message with hex prefix', function () {
const result = binaryRenderer.hexToText('0x' + hex)
assert.equal(result, message)
})
diff --git a/test/unit/components/bn-as-decimal-input-test.js b/test/unit/components/bn-as-decimal-input-test.js
new file mode 100644
index 000000000..106b3a871
--- /dev/null
+++ b/test/unit/components/bn-as-decimal-input-test.js
@@ -0,0 +1,51 @@
+var assert = require('assert')
+
+const additions = require('react-testutils-additions')
+const h = require('react-hyperscript')
+const ReactTestUtils = require('react-addons-test-utils')
+const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
+
+var BnInput = require('../../../ui/app/components/bn-as-decimal-input')
+
+describe('BnInput', function () {
+ it('can tolerate a gas decimal number at a high precision', function (done) {
+ const renderer = ReactTestUtils.createRenderer()
+
+ let valueStr = '20'
+ while (valueStr.length < 20) {
+ valueStr += '0'
+ }
+ const value = new BN(valueStr, 10)
+
+ const inputStr = '2.3'
+
+ let targetStr = '23'
+ while (targetStr.length < 19) {
+ targetStr += '0'
+ }
+ const target = new BN(targetStr, 10)
+
+ const precision = 18 // ether precision
+ const scale = 18
+
+ const props = {
+ value,
+ scale,
+ precision,
+ onChange: (newBn) => {
+ assert.equal(newBn.toString(), target.toString(), 'should tolerate increase')
+ done()
+ },
+ }
+
+ const inputComponent = h(BnInput, props)
+ const component = additions.renderIntoDocument(inputComponent)
+ renderer.render(inputComponent)
+ const input = additions.find(component, 'input.hex-input')[0]
+ ReactTestUtils.Simulate.change(input, { preventDefault () {}, target: {
+ value: inputStr,
+ checkValidity () { return true } },
+ })
+ })
+})
diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js
new file mode 100644
index 000000000..22a98bc93
--- /dev/null
+++ b/test/unit/components/pending-tx-test.js
@@ -0,0 +1,77 @@
+const assert = require('assert')
+const additions = require('react-testutils-additions')
+const h = require('react-hyperscript')
+const PendingTx = require('../../../ui/app/components/pending-tx')
+const ReactTestUtils = require('react-addons-test-utils')
+const ethUtil = require('ethereumjs-util')
+
+describe('PendingTx', function () {
+ const identities = {
+ '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': {
+ name: 'Main Account 1',
+ balance: '0x00000000000000056bc75e2d63100000',
+ },
+ }
+
+ const gasPrice = '0x4A817C800' // 20 Gwei
+ const txData = {
+ 'id': 5021615666270214,
+ 'time': 1494458763011,
+ 'status': 'unapproved',
+ 'metamaskNetworkId': '1494442339676',
+ 'txParams': {
+ 'from': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b826',
+ 'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
+ 'value': '0xde0b6b3a7640000',
+ gasPrice,
+ 'gas': '0x7b0c'},
+ 'gasLimitSpecified': false,
+ 'estimatedGas': '0x5208',
+ }
+
+
+ it('should use updated values when edited.', function (done) {
+ const renderer = ReactTestUtils.createRenderer()
+ const newGasPrice = '0x77359400'
+
+ const props = {
+ identities,
+ accounts: identities,
+ txData,
+ sendTransaction: (txMeta, event) => {
+ // Assert changes:
+ const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice)
+ assert.notEqual(result, gasPrice, 'gas price should change')
+ assert.equal(result, newGasPrice, 'gas price assigned.')
+ done()
+ },
+ }
+
+ const pendingTxComponent = h(PendingTx, props)
+ const component = additions.renderIntoDocument(pendingTxComponent)
+ renderer.render(pendingTxComponent)
+ const result = renderer.getRenderOutput()
+ assert.equal(result.type, 'div', 'should create a div')
+
+ try {
+ const input = additions.find(component, '.cell.row input[type="number"]')[1]
+ ReactTestUtils.Simulate.change(input, {
+ target: {
+ value: 2,
+ checkValidity () { return true },
+ },
+ })
+
+ const form = additions.find(component, 'form')[0]
+ form.checkValidity = () => true
+ form.getFormEl = () => { return { checkValidity () { return true } } }
+ ReactTestUtils.Simulate.submit(form, { preventDefault () {}, target: { checkValidity () {
+ return true
+ } } })
+ } catch (e) {
+ console.log('WHAAAA')
+ console.error(e)
+ }
+ })
+})
+
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index 05324e741..b710e2dfb 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -2,26 +2,22 @@
global.fetch = global.fetch || require('isomorphic-fetch')
const assert = require('assert')
-const extend = require('xtend')
-const rp = require('request-promise')
-const nock = require('nock')
const configManagerGen = require('../lib/mock-config-manager')
-describe('config-manager', function() {
+describe('config-manager', function () {
var configManager
- beforeEach(function() {
+ beforeEach(function () {
configManager = configManagerGen()
})
- describe('#setConfig', function() {
-
+ describe('#setConfig', function () {
it('should set the config key', function () {
var testConfig = {
provider: {
type: 'rpc',
- rpcTarget: 'foobar'
- }
+ rpcTarget: 'foobar',
+ },
}
configManager.setConfig(testConfig)
var result = configManager.getData()
@@ -30,17 +26,17 @@ describe('config-manager', function() {
assert.equal(result.config.provider.rpcTarget, testConfig.provider.rpcTarget)
})
- it('setting wallet should not overwrite config', function() {
+ it('setting wallet should not overwrite config', function () {
var testConfig = {
provider: {
type: 'rpc',
- rpcTarget: 'foobar'
+ rpcTarget: 'foobar',
},
}
configManager.setConfig(testConfig)
var testWallet = {
- name: 'this is my fake wallet'
+ name: 'this is my fake wallet',
}
configManager.setWallet(testWallet)
@@ -58,13 +54,13 @@ describe('config-manager', function() {
})
})
- describe('wallet nicknames', function() {
- it('should return null when no nicknames are saved', function() {
+ describe('wallet nicknames', function () {
+ it('should return null when no nicknames are saved', function () {
var nick = configManager.nicknameForWallet('0x0')
assert.equal(nick, null, 'no nickname returned')
})
- it('should persist nicknames', function() {
+ it('should persist nicknames', function () {
var account = '0x0'
var nick1 = 'foo'
var nick2 = 'bar'
@@ -79,8 +75,8 @@ describe('config-manager', function() {
})
})
- describe('rpc manipulations', function() {
- it('changing rpc should return a different rpc', function() {
+ describe('rpc manipulations', function () {
+ it('changing rpc should return a different rpc', function () {
var firstRpc = 'first'
var secondRpc = 'second'
@@ -94,21 +90,21 @@ describe('config-manager', function() {
})
})
- describe('transactions', function() {
- beforeEach(function() {
+ describe('transactions', function () {
+ beforeEach(function () {
configManager.setTxList([])
})
- describe('#getTxList', function() {
- it('when new should return empty array', function() {
+ describe('#getTxList', function () {
+ it('when new should return empty array', function () {
var result = configManager.getTxList()
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
})
- describe('#setTxList', function() {
- it('saves the submitted data to the tx list', function() {
+ describe('#setTxList', function () {
+ it('saves the submitted data to the tx list', function () {
var target = [{ foo: 'bar' }]
configManager.setTxList(target)
var result = configManager.getTxList()
diff --git a/test/unit/currency-controller-test.js b/test/unit/currency-controller-test.js
index 079f8b488..5eeaf9bcc 100644
--- a/test/unit/currency-controller-test.js
+++ b/test/unit/currency-controller-test.js
@@ -2,26 +2,23 @@
global.fetch = global.fetch || require('isomorphic-fetch')
const assert = require('assert')
-const extend = require('xtend')
-const rp = require('request-promise')
const nock = require('nock')
const CurrencyController = require('../../app/scripts/controllers/currency')
-describe('currency-controller', function() {
+describe('currency-controller', function () {
var currencyController
- beforeEach(function() {
+ beforeEach(function () {
currencyController = new CurrencyController()
})
- describe('currency conversions', function() {
-
- describe('#setCurrentCurrency', function() {
- it('should return USD as default', function() {
+ describe('currency conversions', function () {
+ describe('#setCurrentCurrency', function () {
+ it('should return USD as default', function () {
assert.equal(currencyController.getCurrentCurrency(), 'USD')
})
- it('should be able to set to other currency', function() {
+ it('should be able to set to other currency', function () {
assert.equal(currencyController.getCurrentCurrency(), 'USD')
currencyController.setCurrentCurrency('JPY')
var result = currencyController.getCurrentCurrency()
@@ -29,39 +26,38 @@ describe('currency-controller', function() {
})
})
- describe('#getConversionRate', function() {
- it('should return undefined if non-existent', function() {
+ describe('#getConversionRate', function () {
+ it('should return undefined if non-existent', function () {
var result = currencyController.getConversionRate()
assert.ok(!result)
})
})
- describe('#updateConversionRate', function() {
- it('should retrieve an update for ETH to USD and set it in memory', function(done) {
+ describe('#updateConversionRate', function () {
+ it('should retrieve an update for ETH to USD and set it in memory', function (done) {
this.timeout(15000)
- var usdMock = nock('https://www.cryptonator.com')
+ nock('https://api.cryptonator.com')
.get('/api/ticker/eth-USD')
.reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}')
assert.equal(currencyController.getConversionRate(), 0)
currencyController.setCurrentCurrency('USD')
currencyController.updateConversionRate()
- .then(function() {
+ .then(function () {
var result = currencyController.getConversionRate()
console.log('currencyController.getConversionRate:', result)
assert.equal(typeof result, 'number')
done()
- }).catch(function(err) {
+ }).catch(function (err) {
done(err)
})
-
})
- it('should work for JPY as well.', function() {
+ it('should work for JPY as well.', function () {
this.timeout(15000)
assert.equal(currencyController.getConversionRate(), 0)
- var jpyMock = nock('https://www.cryptonator.com')
+ nock('https://api.cryptonator.com')
.get('/api/ticker/eth-JPY')
.reply(200, '{"ticker":{"base":"ETH","target":"JPY","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}')
@@ -69,19 +65,18 @@ describe('currency-controller', function() {
var promise = new Promise(
function (resolve, reject) {
currencyController.setCurrentCurrency('JPY')
- currencyController.updateConversionRate().then(function() {
+ currencyController.updateConversionRate().then(function () {
resolve()
})
- })
+ })
- promise.then(function() {
+ promise.then(function () {
var result = currencyController.getConversionRate()
assert.equal(typeof result, 'number')
- }).catch(function(err) {
+ }).catch(function (done, err) {
done(err)
})
})
})
})
-
})
diff --git a/test/unit/explorer-link-test.js b/test/unit/explorer-link-test.js
index 4f0230c2c..a02564509 100644
--- a/test/unit/explorer-link-test.js
+++ b/test/unit/explorer-link-test.js
@@ -1,16 +1,14 @@
var assert = require('assert')
var linkGen = require('../../ui/lib/explorer-link')
-describe('explorer-link', function() {
-
- it('adds ropsten prefix to ropsten test network', function() {
+describe('explorer-link', function () {
+ it('adds ropsten prefix to ropsten test network', function () {
var result = linkGen('hash', '3')
assert.notEqual(result.indexOf('ropsten'), -1, 'ropsten injected')
})
- it('adds kovan prefix to kovan test network', function() {
+ it('adds kovan prefix to kovan test network', function () {
var result = linkGen('hash', '42')
assert.notEqual(result.indexOf('kovan'), -1, 'kovan injected')
})
-
})
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index efd0a3546..2d9a53723 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -3,21 +3,18 @@ const KeyringController = require('../../app/scripts/keyring-controller')
const configManagerGen = require('../lib/mock-config-manager')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
-const async = require('async')
const mockEncryptor = require('../lib/mock-encryptor')
-const MockSimpleKeychain = require('../lib/mock-simple-keychain')
const sinon = require('sinon')
-describe('KeyringController', function() {
+describe('KeyringController', function () {
+ let keyringController
+ const password = 'password123'
+ const seedWords = 'puzzle seed penalty soldier say clay field arctic metal hen cage runway'
+ const addresses = ['eF35cA8EbB9669A35c31b5F6f249A9941a812AC1'.toLowerCase()]
+ const accounts = []
+ // let originalKeystore
- let keyringController, state
- let password = 'password123'
- let seedWords = 'puzzle seed penalty soldier say clay field arctic metal hen cage runway'
- let addresses = ['eF35cA8EbB9669A35c31b5F6f249A9941a812AC1'.toLowerCase()]
- let accounts = []
- let originalKeystore
-
- beforeEach(function(done) {
+ beforeEach(function (done) {
this.sinon = sinon.sandbox.create()
window.localStorage = {} // Hacking localStorage support into JSDom
@@ -25,10 +22,10 @@ describe('KeyringController', function() {
configManager: configManagerGen(),
txManager: {
getTxList: () => [],
- getUnapprovedTxList: () => []
+ getUnapprovedTxList: () => [],
},
ethStore: {
- addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
+ addAccount (acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
})
@@ -38,7 +35,7 @@ describe('KeyringController', function() {
keyringController.createNewVaultAndKeychain(password)
.then(function (newState) {
- state = newState
+ newState
done()
})
.catch((err) => {
@@ -46,7 +43,7 @@ describe('KeyringController', function() {
})
})
- afterEach(function() {
+ afterEach(function () {
// Cleanup mocks
this.sinon.restore()
})
@@ -54,7 +51,7 @@ describe('KeyringController', function() {
describe('#createNewVaultAndKeychain', function () {
this.timeout(10000)
- it('should set a vault on the configManager', function(done) {
+ it('should set a vault on the configManager', function (done) {
keyringController.store.updateState({ vault: null })
assert(!keyringController.store.getState().vault, 'no previous vault')
keyringController.createNewVaultAndKeychain(password)
@@ -69,15 +66,14 @@ describe('KeyringController', function() {
})
})
- describe('#restoreKeyring', function() {
-
- it(`should pass a keyring's serialized data back to the correct type.`, function(done) {
+ describe('#restoreKeyring', function () {
+ it(`should pass a keyring's serialized data back to the correct type.`, function (done) {
const mockSerialized = {
type: 'HD Key Tree',
data: {
mnemonic: seedWords,
numberOfAccounts: 1,
- }
+ },
}
const mock = this.sinon.mock(keyringController)
@@ -100,8 +96,8 @@ describe('KeyringController', function() {
})
})
- describe('#createNickname', function() {
- it('should add the address to the identities hash', function() {
+ describe('#createNickname', function () {
+ it('should add the address to the identities hash', function () {
const fakeAddress = '0x12345678'
keyringController.createNickname(fakeAddress)
const identities = keyringController.memStore.getState().identities
@@ -110,8 +106,8 @@ describe('KeyringController', function() {
})
})
- describe('#saveAccountLabel', function() {
- it ('sets the nickname', function(done) {
+ describe('#saveAccountLabel', function () {
+ it('sets the nickname', function (done) {
const account = addresses[0]
var nick = 'Test nickname'
const identities = keyringController.memStore.getState().identities
@@ -134,31 +130,30 @@ describe('KeyringController', function() {
})
})
- describe('#getAccounts', function() {
- it('returns the result of getAccounts for each keyring', function(done) {
+ describe('#getAccounts', function () {
+ it('returns the result of getAccounts for each keyring', function (done) {
keyringController.keyrings = [
- { getAccounts() { return Promise.resolve([1,2,3]) } },
- { getAccounts() { return Promise.resolve([4,5,6]) } },
+ { getAccounts () { return Promise.resolve([1, 2, 3]) } },
+ { getAccounts () { return Promise.resolve([4, 5, 6]) } },
]
keyringController.getAccounts()
.then((result) => {
- assert.deepEqual(result, [1,2,3,4,5,6])
+ assert.deepEqual(result, [1, 2, 3, 4, 5, 6])
done()
})
})
})
- describe('#addGasBuffer', function() {
- it('adds 100k gas buffer to estimates', function() {
-
+ describe('#addGasBuffer', function () {
+ it('adds 100k gas buffer to estimates', function () {
const gas = '0x04ee59' // Actual estimated gas example
const tooBigOutput = '0x80674f9' // Actual bad output
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const correctBuffer = new BN('100000', 10)
const correct = bnGas.add(correctBuffer)
- const tooBig = new BN(tooBigOutput, 16)
+ // const tooBig = new BN(tooBigOutput, 16)
const result = keyringController.addGasBuffer(gas)
const bnResult = new BN(ethUtil.stripHexPrefix(result), 16)
diff --git a/test/unit/linting_test.js b/test/unit/linting_test.js
index 75d90652d..45578fc36 100644
--- a/test/unit/linting_test.js
+++ b/test/unit/linting_test.js
@@ -1,9 +1,9 @@
// LINTING:
-const lint = require('mocha-eslint');
-const lintPaths = ['app/**/*.js', 'ui/**/*.js', '!node_modules/**', '!dist/**', '!docs/**', '!app/scripts/chromereload.js']
+const lint = require('mocha-eslint')
+const lintPaths = ['app/**/*.js', 'ui/**/*.js', 'test/**/*.js', '!node_modules/**', '!dist/**', '!docs/**', '!app/scripts/chromereload.js']
const lintOptions = {
strict: false,
}
-lint(lintPaths, lintOptions) \ No newline at end of file
+lint(lintPaths, lintOptions)
diff --git a/test/unit/message-manager-test.js b/test/unit/message-manager-test.js
index faf7429d4..30cb4f067 100644
--- a/test/unit/message-manager-test.js
+++ b/test/unit/message-manager-test.js
@@ -1,29 +1,26 @@
const assert = require('assert')
-const extend = require('xtend')
-const EventEmitter = require('events')
-
const MessageManger = require('../../app/scripts/lib/message-manager')
-describe('Transaction Manager', function() {
+describe('Transaction Manager', function () {
let messageManager
- beforeEach(function() {
- messageManager = new MessageManger ()
+ beforeEach(function () {
+ messageManager = new MessageManger()
})
- describe('#getMsgList', function() {
- it('when new should return empty array', function() {
+ describe('#getMsgList', function () {
+ it('when new should return empty array', function () {
var result = messageManager.messages
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
- it('should also return transactions from local storage if any', function() {
+ it('should also return transactions from local storage if any', function () {
})
})
- describe('#addMsg', function() {
- it('adds a Msg returned in getMsgList', function() {
+ describe('#addMsg', function () {
+ it('adds a Msg returned in getMsgList', function () {
var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
var result = messageManager.messages
@@ -33,8 +30,8 @@ describe('Transaction Manager', function() {
})
})
- describe('#setMsgStatusApproved', function() {
- it('sets the Msg status to approved', function() {
+ describe('#setMsgStatusApproved', function () {
+ it('sets the Msg status to approved', function () {
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.setMsgStatusApproved(1)
@@ -45,8 +42,8 @@ describe('Transaction Manager', function() {
})
})
- describe('#rejectMsg', function() {
- it('sets the Msg status to rejected', function() {
+ describe('#rejectMsg', function () {
+ it('sets the Msg status to rejected', function () {
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.rejectMsg(1)
@@ -57,8 +54,8 @@ describe('Transaction Manager', function() {
})
})
- describe('#_updateMsg', function() {
- it('replaces the Msg with the same id', function() {
+ describe('#_updateMsg', function () {
+ it('replaces the Msg with the same id', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
messageManager._updateMsg({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' })
@@ -67,19 +64,19 @@ describe('Transaction Manager', function() {
})
})
- describe('#getUnapprovedMsgs', function() {
- it('returns unapproved Msgs in a hash', function() {
+ describe('#getUnapprovedMsgs', function () {
+ it('returns unapproved Msgs in a hash', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
- let result = messageManager.getUnapprovedMsgs()
+ const result = messageManager.getUnapprovedMsgs()
assert.equal(typeof result, 'object')
assert.equal(result['1'].status, 'unapproved')
assert.equal(result['2'], undefined)
})
})
- describe('#getMsg', function() {
- it('returns a Msg with the requested id', function() {
+ describe('#getMsg', function () {
+ it('returns a Msg with the requested id', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
assert.equal(messageManager.getMsg('1').status, 'unapproved')
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index 78b9e9df7..5ee0a6c84 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -4,11 +4,9 @@ const clone = require('clone')
const MetaMaskController = require('../../app/scripts/metamask-controller')
const firstTimeState = require('../../app/scripts/first-time-state')
-const STORAGE_KEY = 'metamask-config'
-
-describe('MetaMaskController', function() {
+describe('MetaMaskController', function () {
const noop = () => {}
- let controller = new MetaMaskController({
+ const metamaskController = new MetaMaskController({
showUnconfirmedMessage: noop,
unlockAccountMessage: noop,
showUnapprovedTx: noop,
@@ -16,14 +14,18 @@ describe('MetaMaskController', function() {
initState: clone(firstTimeState),
})
- beforeEach(function() {
+ beforeEach(function () {
// sinon allows stubbing methods that are easily verified
this.sinon = sinon.sandbox.create()
})
- afterEach(function() {
+ afterEach(function () {
// sinon requires cleanup otherwise it will overwrite context
this.sinon.restore()
})
-}) \ No newline at end of file
+ describe('Metamask Controller', function () {
+ assert(metamaskController)
+ })
+})
+
diff --git a/test/unit/migrations-test.js b/test/unit/migrations-test.js
index ccd1477b0..5bad25a45 100644
--- a/test/unit/migrations-test.js
+++ b/test/unit/migrations-test.js
@@ -3,7 +3,7 @@ const path = require('path')
const wallet1 = require(path.join('..', 'lib', 'migrations', '001.json'))
const vault4 = require(path.join('..', 'lib', 'migrations', '004.json'))
-let vault5, vault6, vault7, vault8, vault9, vault10, vault11
+let vault5, vault6, vault7, vault8, vault9 // vault10, vault11
const migration2 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '002'))
const migration3 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '003'))
@@ -16,6 +16,7 @@ const migration9 = require(path.join('..', '..', 'app', 'scripts', 'migrations',
const migration10 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '010'))
const migration11 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '011'))
const migration12 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '012'))
+const migration13 = require(path.join('..', '..', 'app', 'scripts', 'migrations', '013'))
const oldTestRpc = 'https://rawtestrpc.metamask.io/'
@@ -23,7 +24,6 @@ const newTestRpc = 'https://testrpc.metamask.io/'
describe('wallet1 is migrated successfully', () => {
it('should convert providers', () => {
-
wallet1.data.config.provider = { type: 'etherscan', rpcTarget: null }
return migration2.migrate(wallet1)
@@ -98,7 +98,11 @@ describe('wallet1 is migrated successfully', () => {
}).then((twelfthResult) => {
assert.equal(twelfthResult.data.NoticeController.noticesList[0].body, '', 'notices that have been read should have an empty body.')
assert.equal(twelfthResult.data.NoticeController.noticesList[1].body, 'nonempty', 'notices that have not been read should not have an empty body.')
- })
+ assert.equal(twelfthResult.data.config.provider.type, 'testnet', 'network is originally testnet.')
+ return migration13.migrate(twelfthResult)
+ }).then((thirteenthResult) => {
+ assert.equal(thirteenthResult.data.config.provider.type, 'ropsten', 'network has been changed to ropsten.')
+ })
})
})
diff --git a/test/unit/migrator-test.js b/test/unit/migrator-test.js
new file mode 100644
index 000000000..16066fefe
--- /dev/null
+++ b/test/unit/migrator-test.js
@@ -0,0 +1,41 @@
+const assert = require('assert')
+const clone = require('clone')
+const Migrator = require('../../app/scripts/lib/migrator/')
+const migrations = [
+ {
+ version: 1,
+ migrate: (data) => {
+ // clone the data just like we do in migrations
+ const clonedData = clone(data)
+ clonedData.meta.version = 1
+ return Promise.resolve(clonedData)
+ },
+ },
+ {
+ version: 2,
+ migrate: (data) => {
+ const clonedData = clone(data)
+ clonedData.meta.version = 2
+ return Promise.resolve(clonedData)
+ },
+ },
+ {
+ version: 3,
+ migrate: (data) => {
+ const clonedData = clone(data)
+ clonedData.meta.version = 3
+ return Promise.resolve(clonedData)
+ },
+ },
+]
+const versionedData = {meta: {version: 0}, data: {hello: 'world'}}
+describe('Migrator', () => {
+ const migrator = new Migrator({ migrations })
+ it('migratedData version should be version 3', (done) => {
+ migrator.migrateData(versionedData)
+ .then((migratedData) => {
+ assert.equal(migratedData.meta.version, migrations[2].version)
+ done()
+ }).catch(done)
+ })
+})
diff --git a/test/unit/nameForAccount_test.js b/test/unit/nameForAccount_test.js
index 6839d40f8..e7c0b18b4 100644
--- a/test/unit/nameForAccount_test.js
+++ b/test/unit/nameForAccount_test.js
@@ -4,25 +4,23 @@ var sinon = require('sinon')
var path = require('path')
var contractNamer = require(path.join(__dirname, '..', '..', 'ui', 'lib', 'contract-namer.js'))
-describe('contractNamer', function() {
-
- beforeEach(function() {
+describe('contractNamer', function () {
+ beforeEach(function () {
this.sinon = sinon.sandbox.create()
})
- afterEach(function() {
+ afterEach(function () {
this.sinon.restore()
})
- describe('naming a contract', function() {
-
- it('should return nothing for an unknown random account', function() {
+ describe('naming a contract', function () {
+ it('should return nothing for an unknown random account', function () {
const input = '0x2386F26FC10000'
const output = contractNamer(input)
assert.deepEqual(output, null)
})
- it('should accept identities as an optional second parameter', function() {
+ it('should accept identities as an optional second parameter', function () {
const input = '0x2386F26FC10000'.toLowerCase()
const expected = 'bar'
const identities = {}
@@ -31,7 +29,7 @@ describe('contractNamer', function() {
assert.deepEqual(output, expected)
})
- it('should check for identities case insensitively', function() {
+ it('should check for identities case insensitively', function () {
const input = '0x2386F26FC10000'.toLowerCase()
const expected = 'bar'
const identities = {}
@@ -39,6 +37,5 @@ describe('contractNamer', function() {
const output = contractNamer(input.toUpperCase(), identities)
assert.deepEqual(output, expected)
})
-
})
})
diff --git a/test/unit/network-contoller-test.js b/test/unit/network-contoller-test.js
new file mode 100644
index 000000000..0c7ee9d70
--- /dev/null
+++ b/test/unit/network-contoller-test.js
@@ -0,0 +1,77 @@
+const assert = require('assert')
+const NetworkController = require('../../app/scripts/controllers/network')
+
+describe('# Network Controller', function () {
+ let networkController
+
+ beforeEach(function () {
+ networkController = new NetworkController({
+ provider: {
+ type: 'rinkeby',
+ },
+ })
+ // stub out provider
+ networkController._provider = new Proxy({}, {
+ get: (obj, name) => {
+ return () => {}
+ },
+ })
+ networkController.providerInit = {
+ getAccounts: () => {},
+ }
+
+ networkController.ethQuery = new Proxy({}, {
+ get: (obj, name) => {
+ return () => {}
+ },
+ })
+ })
+ describe('network', function () {
+ describe('#provider', function () {
+ it('provider should be updatable without reassignment', function () {
+ networkController.initializeProvider(networkController.providerInit)
+ const provider = networkController.provider
+ networkController._provider = {test: true}
+ assert.ok(provider.test)
+ })
+ })
+ describe('#getNetworkState', function () {
+ it('should return loading when new', function () {
+ const networkState = networkController.getNetworkState()
+ assert.equal(networkState, 'loading', 'network is loading')
+ })
+ })
+
+ describe('#setNetworkState', function () {
+ it('should update the network', function () {
+ networkController.setNetworkState(1)
+ const networkState = networkController.getNetworkState()
+ assert.equal(networkState, 1, 'network is 1')
+ })
+ })
+
+ describe('#getRpcAddressForType', function () {
+ it('should return the right rpc address', function () {
+ const rpcTarget = networkController.getRpcAddressForType('mainnet')
+ assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress')
+ })
+ })
+ describe('#setProviderType', function () {
+ it('should update provider.type', function () {
+ networkController.setProviderType('mainnet')
+ const type = networkController.getProviderConfig().type
+ assert.equal(type, 'mainnet', 'provider type is updated')
+ })
+ it('should set the network to loading', function () {
+ networkController.setProviderType('mainnet')
+ const loading = networkController.isNetworkLoading()
+ assert.ok(loading, 'network is loading')
+ })
+ it('should set the right rpcTarget', function () {
+ networkController.setProviderType('mainnet')
+ const rpcTarget = networkController.getProviderConfig().rpcTarget
+ assert.equal(rpcTarget, 'https://mainnet.infura.io/metamask', 'returns the right rpcAddress')
+ })
+ })
+ })
+})
diff --git a/test/unit/nodeify-test.js b/test/unit/nodeify-test.js
index a14d34338..5aed758fa 100644
--- a/test/unit/nodeify-test.js
+++ b/test/unit/nodeify-test.js
@@ -1,22 +1,20 @@
const assert = require('assert')
const nodeify = require('../../app/scripts/lib/nodeify')
-describe('nodeify', function() {
-
+describe('nodeify', function () {
var obj = {
foo: 'bar',
promiseFunc: function (a) {
var solution = this.foo + a
return Promise.resolve(solution)
- }
+ },
}
- it('should retain original context', function(done) {
+ it('should retain original context', function (done) {
var nodified = nodeify(obj.promiseFunc).bind(obj)
nodified('baz', function (err, res) {
assert.equal(res, 'barbaz')
done()
})
})
-
})
diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js
index ea37108bb..09eeda15c 100644
--- a/test/unit/notice-controller-test.js
+++ b/test/unit/notice-controller-test.js
@@ -1,42 +1,38 @@
const assert = require('assert')
-const extend = require('xtend')
-const rp = require('request-promise')
-const nock = require('nock')
const configManagerGen = require('../lib/mock-config-manager')
const NoticeController = require('../../app/scripts/notice-controller')
-const STORAGE_KEY = 'metamask-persistence-key'
-describe('notice-controller', function() {
+describe('notice-controller', function () {
var noticeController
- beforeEach(function() {
+ beforeEach(function () {
// simple localStorage polyfill
- let configManager = configManagerGen()
+ const configManager = configManagerGen()
noticeController = new NoticeController({
configManager: configManager,
})
})
- describe('notices', function() {
- describe('#getNoticesList', function() {
- it('should return an empty array when new', function(done) {
- var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
- }]
+ describe('notices', function () {
+ describe('#getNoticesList', function () {
+ it('should return an empty array when new', function (done) {
+ // const testList = [{
+ // id: 0,
+ // read: false,
+ // title: 'Futuristic Notice',
+ // }]
var result = noticeController.getNoticesList()
assert.equal(result.length, 0)
done()
})
})
- describe('#setNoticesList', function() {
+ describe('#setNoticesList', function () {
it('should set data appropriately', function (done) {
var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
+ id: 0,
+ read: false,
+ title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
var testListId = noticeController.getNoticesList()[0].id
@@ -45,12 +41,12 @@ describe('notice-controller', function() {
})
})
- describe('#updateNoticeslist', function() {
- it('should integrate the latest changes from the source', function(done) {
+ describe('#updateNoticeslist', function () {
+ it('should integrate the latest changes from the source', function (done) {
var testList = [{
- id:55,
- read:false,
- title:"Futuristic Notice"
+ id: 55,
+ read: false,
+ title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
noticeController.updateNoticesList().then(() => {
@@ -62,14 +58,14 @@ describe('notice-controller', function() {
})
it('should not overwrite any existing fields', function (done) {
var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
+ id: 0,
+ read: false,
+ title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
var newList = noticeController.getNoticesList()
assert.equal(newList[0].id, 0)
- assert.equal(newList[0].title, "Futuristic Notice")
+ assert.equal(newList[0].title, 'Futuristic Notice')
assert.equal(newList.length, 1)
done()
})
@@ -78,9 +74,9 @@ describe('notice-controller', function() {
describe('#markNoticeRead', function () {
it('should mark a notice as read', function (done) {
var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
+ id: 0,
+ read: false,
+ title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
noticeController.markNoticeRead(testList[0])
@@ -93,9 +89,9 @@ describe('notice-controller', function() {
describe('#getLatestUnreadNotice', function () {
it('should retrieve the latest unread notice', function (done) {
var testList = [
- {id:0,read:true,title:"Past Notice"},
- {id:1,read:false,title:"Current Notice"},
- {id:2,read:false,title:"Future Notice"},
+ {id: 0, read: true, title: 'Past Notice'},
+ {id: 1, read: false, title: 'Current Notice'},
+ {id: 2, read: false, title: 'Future Notice'},
]
noticeController.setNoticesList(testList)
var latestUnread = noticeController.getLatestUnreadNotice()
@@ -104,9 +100,9 @@ describe('notice-controller', function() {
})
it('should return undefined if no unread notices exist.', function (done) {
var testList = [
- {id:0,read:true,title:"Past Notice"},
- {id:1,read:true,title:"Current Notice"},
- {id:2,read:true,title:"Future Notice"},
+ {id: 0, read: true, title: 'Past Notice'},
+ {id: 1, read: true, title: 'Current Notice'},
+ {id: 2, read: true, title: 'Future Notice'},
]
noticeController.setNoticesList(testList)
var latestUnread = noticeController.getLatestUnreadNotice()
@@ -115,5 +111,4 @@ describe('notice-controller', function() {
})
})
})
-
})
diff --git a/test/unit/personal-message-manager-test.js b/test/unit/personal-message-manager-test.js
index f2c01392c..ec2f9a4d1 100644
--- a/test/unit/personal-message-manager-test.js
+++ b/test/unit/personal-message-manager-test.js
@@ -1,29 +1,27 @@
const assert = require('assert')
-const extend = require('xtend')
-const EventEmitter = require('events')
const PersonalMessageManager = require('../../app/scripts/lib/personal-message-manager')
-describe('Personal Message Manager', function() {
+describe('Personal Message Manager', function () {
let messageManager
- beforeEach(function() {
+ beforeEach(function () {
messageManager = new PersonalMessageManager()
})
- describe('#getMsgList', function() {
- it('when new should return empty array', function() {
+ describe('#getMsgList', function () {
+ it('when new should return empty array', function () {
var result = messageManager.messages
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
- it('should also return transactions from local storage if any', function() {
+ it('should also return transactions from local storage if any', function () {
})
})
- describe('#addMsg', function() {
- it('adds a Msg returned in getMsgList', function() {
+ describe('#addMsg', function () {
+ it('adds a Msg returned in getMsgList', function () {
var Msg = { id: 1, status: 'approved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
var result = messageManager.messages
@@ -33,8 +31,8 @@ describe('Personal Message Manager', function() {
})
})
- describe('#setMsgStatusApproved', function() {
- it('sets the Msg status to approved', function() {
+ describe('#setMsgStatusApproved', function () {
+ it('sets the Msg status to approved', function () {
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.setMsgStatusApproved(1)
@@ -45,8 +43,8 @@ describe('Personal Message Manager', function() {
})
})
- describe('#rejectMsg', function() {
- it('sets the Msg status to rejected', function() {
+ describe('#rejectMsg', function () {
+ it('sets the Msg status to rejected', function () {
var Msg = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
messageManager.addMsg(Msg)
messageManager.rejectMsg(1)
@@ -57,8 +55,8 @@ describe('Personal Message Manager', function() {
})
})
- describe('#_updateMsg', function() {
- it('replaces the Msg with the same id', function() {
+ describe('#_updateMsg', function () {
+ it('replaces the Msg with the same id', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
messageManager._updateMsg({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' })
@@ -67,19 +65,19 @@ describe('Personal Message Manager', function() {
})
})
- describe('#getUnapprovedMsgs', function() {
- it('returns unapproved Msgs in a hash', function() {
+ describe('#getUnapprovedMsgs', function () {
+ it('returns unapproved Msgs in a hash', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
- let result = messageManager.getUnapprovedMsgs()
+ const result = messageManager.getUnapprovedMsgs()
assert.equal(typeof result, 'object')
assert.equal(result['1'].status, 'unapproved')
assert.equal(result['2'], undefined)
})
})
- describe('#getMsg', function() {
- it('returns a Msg with the requested id', function() {
+ describe('#getMsg', function () {
+ it('returns a Msg with the requested id', function () {
messageManager.addMsg({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' })
messageManager.addMsg({ id: '2', status: 'approved', metamaskNetworkId: 'unit test' })
assert.equal(messageManager.getMsg('1').status, 'unapproved')
@@ -87,24 +85,23 @@ describe('Personal Message Manager', function() {
})
})
- describe('#normalizeMsgData', function() {
- it('converts text to a utf8 hex string', function() {
+ describe('#normalizeMsgData', function () {
+ it('converts text to a utf8 hex string', function () {
var input = 'hello'
var output = messageManager.normalizeMsgData(input)
assert.equal(output, '0x68656c6c6f', 'predictably hex encoded')
})
- it('tolerates a hex prefix', function() {
+ it('tolerates a hex prefix', function () {
var input = '0x12'
var output = messageManager.normalizeMsgData(input)
assert.equal(output, '0x12', 'un modified')
})
- it('tolerates normal hex', function() {
+ it('tolerates normal hex', function () {
var input = '12'
var output = messageManager.normalizeMsgData(input)
assert.equal(output, '0x12', 'adds prefix')
})
})
-
})
diff --git a/test/unit/reducers/unlock_vault_test.js b/test/unit/reducers/unlock_vault_test.js
index b7540af08..2b7d70b2c 100644
--- a/test/unit/reducers/unlock_vault_test.js
+++ b/test/unit/reducers/unlock_vault_test.js
@@ -1,32 +1,31 @@
-var jsdom = require('mocha-jsdom')
+// var jsdom = require('mocha-jsdom')
var assert = require('assert')
-var freeze = require('deep-freeze-strict')
+// var freeze = require('deep-freeze-strict')
var path = require('path')
var sinon = require('sinon')
var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-describe('#unlockMetamask(selectedAccount)', function() {
-
- beforeEach(function() {
+describe('#unlockMetamask(selectedAccount)', function () {
+ beforeEach(function () {
// sinon allows stubbing methods that are easily verified
this.sinon = sinon.sandbox.create()
})
- afterEach(function() {
+ afterEach(function () {
// sinon requires cleanup otherwise it will overwrite context
this.sinon.restore()
})
- describe('after an error', function() {
- it('clears warning', function() {
+ describe('after an error', function () {
+ it('clears warning', function () {
const warning = 'this is the wrong warning'
const account = 'foo_account'
const initialState = {
appState: {
warning: warning,
- }
+ },
}
const resultState = reducers(initialState, actions.unlockMetamask(account))
@@ -34,14 +33,14 @@ describe('#unlockMetamask(selectedAccount)', function() {
})
})
- describe('going home after an error', function() {
- it('clears warning', function() {
+ describe('going home after an error', function () {
+ it('clears warning', function () {
const warning = 'this is the wrong warning'
- const account = 'foo_account'
+ // const account = 'foo_account'
const initialState = {
appState: {
warning: warning,
- }
+ },
}
const resultState = reducers(initialState, actions.goHome())
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
new file mode 100644
index 000000000..3954300a8
--- /dev/null
+++ b/test/unit/tx-controller-test.js
@@ -0,0 +1,323 @@
+const assert = require('assert')
+const EventEmitter = require('events')
+const ethUtil = require('ethereumjs-util')
+const EthTx = require('ethereumjs-tx')
+const EthQuery = require('eth-query')
+const ObservableStore = require('obs-store')
+const clone = require('clone')
+const sinon = require('sinon')
+const TransactionController = require('../../app/scripts/controllers/transactions')
+const noop = () => true
+const currentNetworkId = 42
+const otherNetworkId = 36
+const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
+
+describe('Transaction Controller', function () {
+ let txController
+
+ beforeEach(function () {
+ txController = new TransactionController({
+ networkStore: new ObservableStore(currentNetworkId),
+ txHistoryLimit: 10,
+ blockTracker: new EventEmitter(),
+ ethQuery: new EthQuery(new EventEmitter()),
+ signTransaction: (ethTx) => new Promise((resolve) => {
+ ethTx.sign(privKey)
+ resolve()
+ }),
+ })
+ })
+
+ describe('#validateTxParams', function () {
+ it('returns null for positive values', function () {
+ var sample = {
+ value: '0x01',
+ }
+ txController.txProviderUtils.validateTxParams(sample, (err) => {
+ assert.equal(err, null, 'no error')
+ })
+ })
+
+ it('returns error for negative values', function () {
+ var sample = {
+ value: '-0x01',
+ }
+ txController.txProviderUtils.validateTxParams(sample, (err) => {
+ assert.ok(err, 'error')
+ })
+ })
+ })
+
+ describe('#getTxList', function () {
+ it('when new should return empty array', function () {
+ var result = txController.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 0)
+ })
+ it('should also return transactions from local storage if any', function () {
+
+ })
+ })
+
+ describe('#addTx', function () {
+ it('adds a tx returned in getTxList', function () {
+ var tx = { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ var result = txController.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].id, 1)
+ })
+
+ it('does not override txs from other networks', function () {
+ var tx = { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
+ var tx2 = { id: 2, status: 'confirmed', metamaskNetworkId: otherNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ txController.addTx(tx2, noop)
+ var result = txController.getFullTxList()
+ var result2 = txController.getTxList()
+ assert.equal(result.length, 2, 'txs were deleted')
+ assert.equal(result2.length, 1, 'incorrect number of txs on network.')
+ })
+
+ it('cuts off early txs beyond a limit', function () {
+ const limit = txController.txHistoryLimit
+ for (let i = 0; i < limit + 1; i++) {
+ const tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ }
+ var result = txController.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 1, 'early txs truncted')
+ })
+
+ it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function () {
+ const limit = txController.txHistoryLimit
+ for (let i = 0; i < limit + 1; i++) {
+ const tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ }
+ var result = txController.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 1, 'early txs truncted')
+ })
+
+ it('cuts off early txs beyond a limit but does not cut unapproved txs', function () {
+ var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(unconfirmedTx, noop)
+ const limit = txController.txHistoryLimit
+ for (let i = 1; i < limit + 1; i++) {
+ const tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ }
+ var result = txController.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 0, 'first tx should still be there')
+ assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved')
+ assert.equal(result[1].id, 2, 'early txs truncted')
+ })
+ })
+
+ describe('#setTxStatusSigned', function () {
+ it('sets the tx status to signed', function () {
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx, noop)
+ txController.setTxStatusSigned(1)
+ var result = txController.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].status, 'signed')
+ })
+
+ it('should emit a signed event to signal the exciton of callback', (done) => {
+ this.timeout(10000)
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
+ const noop = function () {
+ assert(true, 'event listener has been triggered and noop executed')
+ done()
+ }
+ txController.addTx(tx)
+ txController.on('1:signed', noop)
+ txController.setTxStatusSigned(1)
+ })
+ })
+
+ describe('#setTxStatusRejected', function () {
+ it('sets the tx status to rejected', function () {
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx)
+ txController.setTxStatusRejected(1)
+ var result = txController.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].status, 'rejected')
+ })
+
+ it('should emit a rejected event to signal the exciton of callback', (done) => {
+ this.timeout(10000)
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
+ txController.addTx(tx)
+ const noop = function (err, txId) {
+ assert(true, 'event listener has been triggered and noop executed')
+ done()
+ }
+ txController.on('1:rejected', noop)
+ txController.setTxStatusRejected(1)
+ })
+ })
+
+ describe('#updateTx', function () {
+ it('replaces the tx with the same id', function () {
+ txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ txController.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ txController.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: currentNetworkId, txParams: {} })
+ var result = txController.getTx('1')
+ assert.equal(result.hash, 'foo')
+ })
+
+ it('updates gas price', function () {
+ const originalGasPrice = '0x01'
+ const desiredGasPrice = '0x02'
+
+ const txMeta = {
+ id: '1',
+ status: 'unapproved',
+ metamaskNetworkId: currentNetworkId,
+ txParams: {
+ gasPrice: originalGasPrice,
+ },
+ }
+
+ const updatedMeta = clone(txMeta)
+
+ txController.addTx(txMeta)
+ updatedMeta.txParams.gasPrice = desiredGasPrice
+ txController.updateTx(updatedMeta)
+ var result = txController.getTx('1')
+ assert.equal(result.txParams.gasPrice, desiredGasPrice, 'gas price updated')
+ })
+ })
+
+ describe('#getUnapprovedTxList', function () {
+ it('returns unapproved txs in a hash', function () {
+ txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ txController.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ const result = txController.getUnapprovedTxList()
+ assert.equal(typeof result, 'object')
+ assert.equal(result['1'].status, 'unapproved')
+ assert.equal(result['2'], undefined)
+ })
+ })
+
+ describe('#getTx', function () {
+ it('returns a tx with the requested id', function () {
+ txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ txController.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ assert.equal(txController.getTx('1').status, 'unapproved')
+ assert.equal(txController.getTx('2').status, 'confirmed')
+ })
+ })
+
+ describe('#getFilteredTxList', function () {
+ it('returns a tx with the requested data', function () {
+ const txMetas = [
+ { id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
+ { id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
+ { id: 2, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
+ { id: 3, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
+ { id: 4, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
+ { id: 5, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
+ { id: 6, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
+ { id: 7, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
+ { id: 8, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
+ { id: 9, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
+ ]
+ txMetas.forEach((txMeta) => txController.addTx(txMeta, noop))
+ let filterParams
+
+ filterParams = { status: 'unapproved', from: '0xaa' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'unapproved', to: '0xaa' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 2, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'confirmed', from: '0xbb' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'confirmed' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { from: '0xaa' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { to: '0xaa' }
+ assert.equal(txController.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ })
+ })
+
+ describe('#approveTransaction', function () {
+ let txMeta, originalValue
+
+ beforeEach(function () {
+ originalValue = '0x01'
+ txMeta = {
+ id: '1',
+ status: 'unapproved',
+ metamaskNetworkId: currentNetworkId,
+ txParams: {
+ nonce: originalValue,
+ gas: originalValue,
+ gasPrice: originalValue,
+ },
+ }
+ })
+
+
+ it('does not overwrite set values', function (done) {
+ const wrongValue = '0x05'
+
+ txController.addTx(txMeta)
+
+ const estimateStub = sinon.stub(txController.txProviderUtils.query, 'estimateGas')
+ .callsArgWith(1, null, wrongValue)
+
+ const priceStub = sinon.stub(txController.txProviderUtils.query, 'gasPrice')
+ .callsArgWith(0, null, wrongValue)
+
+ const nonceStub = sinon.stub(txController.txProviderUtils.query, 'getTransactionCount')
+ .callsArgWith(2, null, wrongValue)
+
+ const signStub = sinon.stub(txController, 'signTransaction')
+ .callsArgWith(1, null, noop)
+
+ const pubStub = sinon.stub(txController.txProviderUtils, 'publishTransaction')
+ .callsArgWith(1, null, originalValue)
+
+ txController.approveTransaction(txMeta.id, (err) => {
+ assert.ifError(err, 'should not error')
+
+ const result = txController.getTx(txMeta.id)
+ const params = result.txParams
+
+ assert.equal(params.gas, originalValue, 'gas unmodified')
+ assert.equal(params.gasPrice, originalValue, 'gas price unmodified')
+ assert.equal(params.nonce, originalValue, 'nonce unmodified')
+ assert.equal(result.hash, originalValue, 'hash was set')
+
+ estimateStub.restore()
+ priceStub.restore()
+ signStub.restore()
+ nonceStub.restore()
+ pubStub.restore()
+
+ done()
+ })
+ })
+ })
+
+ describe('#sign replay-protected tx', function () {
+ it('prepares a tx with the chainId set', function () {
+ txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
+ txController.signTransaction('1', (err, rawTx) => {
+ if (err) return assert.fail('it should not fail')
+ const ethTx = new EthTx(ethUtil.toBuffer(rawTx))
+ assert.equal(ethTx.getChainId(), currentNetworkId)
+ })
+ })
+ })
+})
diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js
deleted file mode 100644
index 21e94357b..000000000
--- a/test/unit/tx-manager-test.js
+++ /dev/null
@@ -1,241 +0,0 @@
-const assert = require('assert')
-const extend = require('xtend')
-const EventEmitter = require('events')
-const ethUtil = require('ethereumjs-util')
-const EthTx = require('ethereumjs-tx')
-const ObservableStore = require('obs-store')
-const STORAGE_KEY = 'metamask-persistance-key'
-const TransactionManager = require('../../app/scripts/transaction-manager')
-const noop = () => true
-const currentNetworkId = 42
-const otherNetworkId = 36
-const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
-
-describe('Transaction Manager', function() {
- let txManager
-
- beforeEach(function() {
- txManager = new TransactionManager({
- networkStore: new ObservableStore({ network: currentNetworkId }),
- txHistoryLimit: 10,
- blockTracker: new EventEmitter(),
- signTransaction: (ethTx) => new Promise((resolve) => {
- ethTx.sign(privKey)
- resolve()
- })
- })
- })
-
- describe('#validateTxParams', function () {
- it('returns null for positive values', function() {
- var sample = {
- value: '0x01'
- }
- var res = txManager.txProviderUtils.validateTxParams(sample, (err) => {
- assert.equal(err, null, 'no error')
- })
- })
-
- it('returns error for negative values', function() {
- var sample = {
- value: '-0x01'
- }
- var res = txManager.txProviderUtils.validateTxParams(sample, (err) => {
- assert.ok(err, 'error')
- })
- })
- })
-
- describe('#getTxList', function() {
- it('when new should return empty array', function() {
- var result = txManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 0)
- })
- it('should also return transactions from local storage if any', function() {
-
- })
- })
-
- describe('#addTx', function() {
- it('adds a tx returned in getTxList', function() {
- var tx = { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- var result = txManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].id, 1)
- })
-
- it('does not override txs from other networks', function() {
- var tx = { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
- var tx2 = { id: 2, status: 'confirmed', metamaskNetworkId: otherNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- txManager.addTx(tx2, noop)
- var result = txManager.getFullTxList()
- var result2 = txManager.getTxList()
- assert.equal(result.length, 2, 'txs were deleted')
- assert.equal(result2.length, 1, 'incorrect number of txs on network.')
- })
-
- it('cuts off early txs beyond a limit', function() {
- const limit = txManager.txHistoryLimit
- for (let i = 0; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- }
- var result = txManager.getTxList()
- assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
- assert.equal(result[0].id, 1, 'early txs truncted')
- })
-
- it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function() {
- const limit = txManager.txHistoryLimit
- for (let i = 0; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- }
- var result = txManager.getTxList()
- assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
- assert.equal(result[0].id, 1, 'early txs truncted')
- })
-
- it('cuts off early txs beyond a limit but does not cut unapproved txs', function() {
- var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(unconfirmedTx, noop)
- const limit = txManager.txHistoryLimit
- for (let i = 1; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- }
- var result = txManager.getTxList()
- assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
- assert.equal(result[0].id, 0, 'first tx should still be there')
- assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved')
- assert.equal(result[1].id, 2, 'early txs truncted')
- })
- })
-
- describe('#setTxStatusSigned', function() {
- it('sets the tx status to signed', function() {
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx, noop)
- txManager.setTxStatusSigned(1)
- var result = txManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].status, 'signed')
- })
-
- it('should emit a signed event to signal the exciton of callback', (done) => {
- this.timeout(10000)
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
- let noop = function () {
- assert(true, 'event listener has been triggered and noop executed')
- done()
- }
- txManager.addTx(tx)
- txManager.on('1:signed', noop)
- txManager.setTxStatusSigned(1)
- })
- })
-
- describe('#setTxStatusRejected', function() {
- it('sets the tx status to rejected', function() {
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx)
- txManager.setTxStatusRejected(1)
- var result = txManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].status, 'rejected')
- })
-
- it('should emit a rejected event to signal the exciton of callback', (done) => {
- this.timeout(10000)
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
- txManager.addTx(tx)
- let noop = function (err, txId) {
- assert(true, 'event listener has been triggered and noop executed')
- done()
- }
- txManager.on('1:rejected', noop)
- txManager.setTxStatusRejected(1)
- })
-
- })
-
- describe('#updateTx', function() {
- it('replaces the tx with the same id', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: currentNetworkId, txParams: {} })
- var result = txManager.getTx('1')
- assert.equal(result.hash, 'foo')
- })
- })
-
- describe('#getUnapprovedTxList', function() {
- it('returns unapproved txs in a hash', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- let result = txManager.getUnapprovedTxList()
- assert.equal(typeof result, 'object')
- assert.equal(result['1'].status, 'unapproved')
- assert.equal(result['2'], undefined)
- })
- })
-
- describe('#getTx', function() {
- it('returns a tx with the requested id', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- assert.equal(txManager.getTx('1').status, 'unapproved')
- assert.equal(txManager.getTx('2').status, 'confirmed')
- })
- })
-
- describe('#getFilteredTxList', function() {
- it('returns a tx with the requested data', function() {
- let txMetas = [
- { id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
- { id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
- { id: 2, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
- { id: 3, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
- { id: 4, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
- { id: 5, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
- { id: 6, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
- { id: 7, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
- { id: 8, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
- { id: 9, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: currentNetworkId },
- ]
- txMetas.forEach((txMeta) => txManager.addTx(txMeta, noop))
- let filterParams
-
- filterParams = { status: 'unapproved', from: '0xaa' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- filterParams = { status: 'unapproved', to: '0xaa' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 2, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- filterParams = { status: 'confirmed', from: '0xbb' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- filterParams = { status: 'confirmed' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- filterParams = { from: '0xaa' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- filterParams = { to: '0xaa' }
- assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
- })
- })
-
- describe('#sign replay-protected tx', function() {
- it('prepares a tx with the chainId set', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txManager.signTransaction('1', (err, rawTx) => {
- if (err) return assert.fail('it should not fail')
- const ethTx = new EthTx(ethUtil.toBuffer(rawTx))
- assert.equal(ethTx.getChainId(), currentNetworkId)
- })
- })
- })
-
-})
diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js
index 93e9e4134..7ace1f587 100644
--- a/test/unit/tx-utils-test.js
+++ b/test/unit/tx-utils-test.js
@@ -5,15 +5,19 @@ const BN = ethUtil.BN
const TxUtils = require('../../app/scripts/lib/tx-utils')
-describe('txUtils', function() {
+describe('txUtils', function () {
let txUtils
- before(function() {
- txUtils = new TxUtils()
+ before(function () {
+ txUtils = new TxUtils(new Proxy({}, {
+ get: (obj, name) => {
+ return () => {}
+ },
+ }))
})
- describe('chain Id', function() {
- it('prepares a transaction with the provided chainId', function() {
+ describe('chain Id', function () {
+ it('prepares a transaction with the provided chainId', function () {
const txParams = {
to: '0x70ad465e0bab6504002ad58c744ed89c7da38524',
from: '0x69ad465e0bab6504002ad58c744ed89c7da38525',
@@ -29,8 +33,8 @@ describe('txUtils', function() {
})
})
- describe('addGasBuffer', function() {
- it('multiplies by 1.5, when within block gas limit', function() {
+ describe('addGasBuffer', function () {
+ it('multiplies by 1.5, when within block gas limit', function () {
// naive estimatedGas: 0x16e360 (1.5 mil)
const inputHex = '0x16e360'
// dummy gas limit: 0x3d4c52 (4 mil)
@@ -41,20 +45,20 @@ describe('txUtils', function() {
const expectedBn = inputBn.muln(1.5)
assert(outputBn.eq(expectedBn), 'returns 1.5 the input value')
})
-
- it('uses original estimatedGas, when above block gas limit', function() {
+
+ it('uses original estimatedGas, when above block gas limit', function () {
// naive estimatedGas: 0x16e360 (1.5 mil)
const inputHex = '0x16e360'
// dummy gas limit: 0x0f4240 (1 mil)
const blockGasLimitHex = '0x0f4240'
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
- const inputBn = hexToBn(inputHex)
+ // const inputBn = hexToBn(inputHex)
const outputBn = hexToBn(output)
const expectedBn = hexToBn(inputHex)
assert(outputBn.eq(expectedBn), 'returns the original estimatedGas value')
})
- it('buffers up to reccomend gas limit reccomended ceiling', function() {
+ it('buffers up to reccomend gas limit reccomended ceiling', function () {
// naive estimatedGas: 0x16e360 (1.5 mil)
const inputHex = '0x16e360'
// dummy gas limit: 0x1e8480 (2 mil)
@@ -72,10 +76,10 @@ describe('txUtils', function() {
// util
-function hexToBn(inputHex) {
+function hexToBn (inputHex) {
return new BN(ethUtil.stripHexPrefix(inputHex), 16)
}
-function bnToHex(inputBn) {
+function bnToHex (inputBn) {
return ethUtil.addHexPrefix(inputBn.toString(16))
-} \ No newline at end of file
+}
diff --git a/test/unit/util_test.js b/test/unit/util_test.js
index 00528b905..3a8b6bdfd 100644
--- a/test/unit/util_test.js
+++ b/test/unit/util_test.js
@@ -5,96 +5,96 @@ const ethUtil = require('ethereumjs-util')
var path = require('path')
var util = require(path.join(__dirname, '..', '..', 'ui', 'app', 'util.js'))
-describe('util', function() {
+describe('util', function () {
var ethInWei = '1'
- for (var i = 0; i < 18; i++ ) { ethInWei += '0' }
+ for (var i = 0; i < 18; i++) { ethInWei += '0' }
- beforeEach(function() {
+ beforeEach(function () {
this.sinon = sinon.sandbox.create()
})
- afterEach(function() {
+ afterEach(function () {
this.sinon.restore()
})
- describe('#parseBalance', function() {
- it('should render 0.01 eth correctly', function() {
+ describe('#parseBalance', function () {
+ it('should render 0.01 eth correctly', function () {
const input = '0x2386F26FC10000'
const output = util.parseBalance(input)
assert.deepEqual(output, ['0', '01'])
})
- it('should render 12.023 eth correctly', function() {
+ it('should render 12.023 eth correctly', function () {
const input = 'A6DA46CCA6858000'
const output = util.parseBalance(input)
assert.deepEqual(output, ['12', '023'])
})
- it('should render 0.0000000342422 eth correctly', function() {
+ it('should render 0.0000000342422 eth correctly', function () {
const input = '0x7F8FE81C0'
const output = util.parseBalance(input)
assert.deepEqual(output, ['0', '0000000342422'])
})
- it('should render 0 eth correctly', function() {
+ it('should render 0 eth correctly', function () {
const input = '0x0'
const output = util.parseBalance(input)
assert.deepEqual(output, ['0', '0'])
})
})
- describe('#addressSummary', function() {
- it('should add case-sensitive checksum', function() {
+ describe('#addressSummary', function () {
+ it('should add case-sensitive checksum', function () {
var address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825'
var result = util.addressSummary(address)
assert.equal(result, '0xFDEa65C8...b825')
})
- it('should accept arguments for firstseg, lastseg, and keepPrefix', function() {
+ it('should accept arguments for firstseg, lastseg, and keepPrefix', function () {
var address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825'
var result = util.addressSummary(address, 4, 4, false)
assert.equal(result, 'FDEa...b825')
})
})
- describe('#isValidAddress', function() {
- it('should allow 40-char non-prefixed hex', function() {
+ describe('#isValidAddress', function () {
+ it('should allow 40-char non-prefixed hex', function () {
var address = 'fdea65c8e26263f6d9a1b5de9555d2931a33b825'
var result = util.isValidAddress(address)
assert.ok(result)
})
- it('should allow 42-char non-prefixed hex', function() {
+ it('should allow 42-char non-prefixed hex', function () {
var address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825'
var result = util.isValidAddress(address)
assert.ok(result)
})
- it('should not allow less non hex-prefixed', function() {
+ it('should not allow less non hex-prefixed', function () {
var address = 'fdea65c8e26263f6d9a1b5de9555d2931a33b85'
var result = util.isValidAddress(address)
assert.ok(!result)
})
- it('should not allow less hex-prefixed', function() {
+ it('should not allow less hex-prefixed', function () {
var address = '0xfdea65ce26263f6d9a1b5de9555d2931a33b85'
var result = util.isValidAddress(address)
assert.ok(!result)
})
- it('should recognize correct capitalized checksum', function() {
+ it('should recognize correct capitalized checksum', function () {
var address = '0xFDEa65C8e26263F6d9A1B5de9555D2931A33b825'
var result = util.isValidAddress(address)
assert.ok(result)
})
- it('should recognize incorrect capitalized checksum', function() {
+ it('should recognize incorrect capitalized checksum', function () {
var address = '0xFDea65C8e26263F6d9A1B5de9555D2931A33b825'
var result = util.isValidAddress(address)
assert.ok(!result)
})
- it('should recognize this sample hashed address', function() {
+ it('should recognize this sample hashed address', function () {
const address = '0x5Fda30Bb72B8Dfe20e48A00dFc108d0915BE9Bb0'
const result = util.isValidAddress(address)
const hashed = ethUtil.toChecksumAddress(address.toLowerCase())
@@ -103,60 +103,57 @@ describe('util', function() {
})
})
- describe('#numericBalance', function() {
-
- it('should return a BN 0 if given nothing', function() {
+ describe('#numericBalance', function () {
+ it('should return a BN 0 if given nothing', function () {
var result = util.numericBalance()
assert.equal(result.toString(10), 0)
})
- it('should work with hex prefix', function() {
+ it('should work with hex prefix', function () {
var result = util.numericBalance('0x012')
assert.equal(result.toString(10), '18')
})
- it('should work with no hex prefix', function() {
+ it('should work with no hex prefix', function () {
var result = util.numericBalance('012')
assert.equal(result.toString(10), '18')
})
-
})
- describe('#formatBalance', function() {
-
- it('when given nothing', function() {
+ describe('#formatBalance', function () {
+ it('when given nothing', function () {
var result = util.formatBalance()
assert.equal(result, 'None', 'should return "None"')
})
- it('should return eth as string followed by ETH', function() {
+ it('should return eth as string followed by ETH', function () {
var input = new ethUtil.BN(ethInWei, 10).toJSON()
var result = util.formatBalance(input, 4)
assert.equal(result, '1.0000 ETH')
})
- it('should return eth as string followed by ETH', function() {
+ it('should return eth as string followed by ETH', function () {
var input = new ethUtil.BN(ethInWei, 10).div(new ethUtil.BN('2', 10)).toJSON()
var result = util.formatBalance(input, 3)
assert.equal(result, '0.500 ETH')
})
- it('should display specified decimal points', function() {
- var input = "0x128dfa6a90b28000"
+ it('should display specified decimal points', function () {
+ var input = '0x128dfa6a90b28000'
var result = util.formatBalance(input, 2)
assert.equal(result, '1.33 ETH')
})
- it('should default to 3 decimal points', function() {
- var input = "0x128dfa6a90b28000"
+ it('should default to 3 decimal points', function () {
+ var input = '0x128dfa6a90b28000'
var result = util.formatBalance(input)
assert.equal(result, '1.337 ETH')
})
- it('should show 2 significant digits for tiny balances', function() {
- var input = "0x1230fa6a90b28"
+ it('should show 2 significant digits for tiny balances', function () {
+ var input = '0x1230fa6a90b28'
var result = util.formatBalance(input)
assert.equal(result, '0.00032 ETH')
})
- it('should not parse the balance and return value with 2 decimal points with ETH at the end', function() {
+ it('should not parse the balance and return value with 2 decimal points with ETH at the end', function () {
var value = '1.2456789'
var needsParse = false
var result = util.formatBalance(value, 2, needsParse)
@@ -164,17 +161,16 @@ describe('util', function() {
})
})
- describe('normalizing values', function() {
-
- describe('#normalizeToWei', function() {
- it('should convert an eth to the appropriate equivalent values', function() {
+ 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',
+ wei: '1000000000000000000',
+ kwei: '1000000000000000',
+ mwei: '1000000000000',
+ gwei: '1000000000',
szabo: '1000000',
- finney:'1000',
+ finney: '1000',
ether: '1',
// kether:'0.001',
// mether:'0.000001',
@@ -185,8 +181,7 @@ describe('util', function() {
}
var oneEthBn = new ethUtil.BN(ethInWei, 10)
- for(var currency in valueTable) {
-
+ 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}`)
@@ -194,60 +189,58 @@ describe('util', function() {
})
})
- describe('#normalizeEthStringToWei', function() {
- it('should convert decimal eth to pure wei BN', function() {
+ describe('#normalizeEthStringToWei', function () {
+ it('should convert decimal eth to pure wei BN', function () {
var input = '1.23456789'
var output = util.normalizeEthStringToWei(input)
assert.equal(output.toString(10), '1234567890000000000')
})
- it('should convert 1 to expected wei', function() {
+ it('should convert 1 to expected wei', function () {
var input = '1'
var output = util.normalizeEthStringToWei(input)
assert.equal(output.toString(10), ethInWei)
})
})
- describe('#normalizeNumberToWei', function() {
-
- it('should handle a simple use case', function() {
+ describe('#normalizeNumberToWei', function () {
+ it('should handle a simple use case', function () {
var input = 0.0002
var output = util.normalizeNumberToWei(input, 'ether')
var str = output.toString(10)
assert.equal(str, '200000000000000')
})
- it('should convert a kwei number to the appropriate equivalent wei', 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() {
+ 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')
})
})
- describe('#isHex', function(){
- it('should return true when given a hex string', function() {
+ describe('#isHex', function () {
+ it('should return true when given a hex string', function () {
var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
assert(result)
})
- it('should return false when given a non-hex string', function() {
+ it('should return false when given a non-hex string', function () {
var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714imnotreal')
assert(!result)
})
- it('should return false when given a string containing a non letter/number character', function() {
+ it('should return false when given a string containing a non letter/number character', function () {
var result = util.isHex('c3ab8ff13720!8ad9047dd39466b3c%8974e592c2fa383d4a396071imnotreal')
assert(!result)
})
- it('should return true when given a hex string with hex-prefix', function() {
+ it('should return true when given a hex string with hex-prefix', function () {
var result = util.isHex('0xc3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
assert(result)
})
-
})
})
})