aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/actions/tx_test.js2
-rw-r--r--test/unit/currency-controller-test.js1
-rw-r--r--test/unit/infura-controller-test.js2
-rw-r--r--test/unit/metamask-controller-test.js412
-rw-r--r--test/unit/nameForAccount_test.js2
-rw-r--r--test/unit/pending-tx-test.js2
-rw-r--r--test/unit/reducers/unlock_vault_test.js2
-rw-r--r--test/unit/util_test.js2
8 files changed, 416 insertions, 9 deletions
diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js
index b6a691860..c110f71fc 100644
--- a/test/unit/actions/tx_test.js
+++ b/test/unit/actions/tx_test.js
@@ -9,7 +9,7 @@ var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'redu
describe('tx confirmation screen', function () {
beforeEach(function () {
- this.sinon = sinon.sandbox.create()
+ this.sinon = sinon.createSandbox()
})
afterEach(function () {
diff --git a/test/unit/currency-controller-test.js b/test/unit/currency-controller-test.js
index 63ab60f9e..73a97d120 100644
--- a/test/unit/currency-controller-test.js
+++ b/test/unit/currency-controller-test.js
@@ -45,7 +45,6 @@ describe('currency-controller', function () {
currencyController.updateConversionRate()
.then(function () {
var result = currencyController.getConversionRate()
- console.log('currencyController.getConversionRate:', result)
assert.equal(typeof result, 'number')
done()
}).catch(function (err) {
diff --git a/test/unit/infura-controller-test.js b/test/unit/infura-controller-test.js
index 605305efa..c9f0e7587 100644
--- a/test/unit/infura-controller-test.js
+++ b/test/unit/infura-controller-test.js
@@ -8,7 +8,7 @@ describe('infura-controller', function () {
before(async function () {
infuraController = new InfuraController()
- sandbox = sinon.sandbox.create()
+ sandbox = sinon.createSandbox()
sinon.stub(infuraController, 'checkInfuraNetworkStatus').resolves(response)
networkStatus = await infuraController.checkInfuraNetworkStatus()
})
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index adeca9b5f..c9d041f01 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -6,10 +6,12 @@ const MetaMaskController = require('../../app/scripts/metamask-controller')
const blacklistJSON = require('../stub/blacklist')
const firstTimeState = require('../../app/scripts/first-time-state')
+const currentNetworkId = 42
+
describe('MetaMaskController', function () {
let metamaskController
- const sandbox = sinon.sandbox.create()
- const noop = () => { }
+ const sandbox = sinon.createSandbox()
+ const noop = () => {}
beforeEach(function () {
@@ -19,12 +21,21 @@ describe('MetaMaskController', function () {
.reply(200, blacklistJSON)
nock('https://api.infura.io')
+ .get('/v1/ticker/ethusd')
+ .reply(200, '{"base": "ETH", "quote": "USD", "bid": 288.45, "ask": 288.46, "volume": 112888.17569277, "exchange": "bitfinex", "total_volume": 272175.00106721005, "num_exchanges": 8, "timestamp": 1506444677}')
+
+ nock('https://api.infura.io')
+ .get('/v1/ticker/ethjpy')
+ .reply(200, '{"base": "ETH", "quote": "JPY", "bid": 32300.0, "ask": 32400.0, "volume": 247.4616071, "exchange": "kraken", "total_volume": 247.4616071, "num_exchanges": 1, "timestamp": 1506444676}')
+
+ nock('https://api.infura.io')
.persist()
.get(/.*/)
.reply(200)
metamaskController = new MetaMaskController({
showUnapprovedTx: noop,
+ showUnconfirmedMessage: noop,
encryptor: {
encrypt: function (password, object) {
this.object = object
@@ -46,6 +57,7 @@ describe('MetaMaskController', function () {
})
describe('#getGasPrice', function () {
+
it('gives the 50th percentile lowest accepted gas price from recentBlocksController', async function () {
const realRecentBlocksController = metamaskController.recentBlocksController
metamaskController.recentBlocksController = {
@@ -100,4 +112,400 @@ describe('MetaMaskController', function () {
assert(metamaskController.keyringController.createNewVaultAndRestore.calledTwice)
})
})
+
+ describe('#getApi', function () {
+ let getApi, state
+
+ beforeEach(function () {
+ getApi = metamaskController.getApi()
+ })
+
+ it('getState', function (done) {
+ getApi.getState((err, res) => {
+ if (err) {
+ done(err)
+ } else {
+ state = res
+ }
+ })
+ assert.deepEqual(state, metamaskController.getState())
+ done()
+ })
+
+ })
+
+ describe('preferencesController', function () {
+
+ it('defaults useBlockie to false', function () {
+ assert.equal(metamaskController.preferencesController.store.getState().useBlockie, false)
+ })
+
+ it('setUseBlockie to true', function () {
+ metamaskController.setUseBlockie(true, noop)
+ assert.equal(metamaskController.preferencesController.store.getState().useBlockie, true)
+ })
+
+ })
+
+ describe('#selectFirstIdentity', function () {
+ let identities, address
+
+ beforeEach(function () {
+ address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
+ identities = {
+ identities: {
+ '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
+ 'address': '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
+ 'name': 'Account 1',
+ },
+ },
+ }
+ metamaskController.selectFirstIdentity(identities)
+ })
+
+ it('changes preferences controller select address', function () {
+ const preferenceControllerState = metamaskController.preferencesController.store.getState()
+ assert.equal(preferenceControllerState.selectedAddress, address)
+ })
+
+ it('changes metamask controller selected address', function () {
+ const metamaskState = metamaskController.getState()
+ assert.equal(metamaskState.selectedAddress, address)
+ })
+ })
+
+ describe('#setCustomRpc', function () {
+ const customRPC = 'https://custom.rpc/'
+ let rpcTarget
+
+ beforeEach(function () {
+
+ nock('https://custom.rpc')
+ .post('/')
+ .reply(200)
+
+ rpcTarget = metamaskController.setCustomRpc(customRPC)
+ })
+
+ it('returns custom RPC that when called', async function () {
+ assert.equal(await rpcTarget, customRPC)
+ })
+
+ it('changes the network controller rpc', function () {
+ const networkControllerState = metamaskController.networkController.store.getState()
+ assert.equal(networkControllerState.provider.rpcTarget, customRPC)
+ })
+ })
+
+ describe('#setCurrentCurrency', function () {
+ let defaultMetaMaskCurrency
+
+ beforeEach(function () {
+ defaultMetaMaskCurrency = metamaskController.currencyController.getCurrentCurrency()
+ })
+
+ it('defaults to usd', function () {
+ assert.equal(defaultMetaMaskCurrency, 'usd')
+ })
+
+ it('sets currency to JPY', function () {
+ metamaskController.setCurrentCurrency('JPY', noop)
+ assert.equal(metamaskController.currencyController.getCurrentCurrency(), 'JPY')
+ })
+ })
+
+ describe('#createShapeshifttx', function () {
+ let depositAddress, depositType, shapeShiftTxList
+
+ beforeEach(function () {
+ nock('https://shapeshift.io')
+ .get('/txStat/3EevLFfB4H4XMWQwYCgjLie1qCAGpd2WBc')
+ .reply(200, '{"status": "no_deposits", "address": "3EevLFfB4H4XMWQwYCgjLie1qCAGpd2WBc"}')
+
+ depositAddress = '3EevLFfB4H4XMWQwYCgjLie1qCAGpd2WBc'
+ depositType = 'ETH'
+ shapeShiftTxList = metamaskController.shapeshiftController.store.getState().shapeShiftTxList
+ })
+
+ it('creates a shapeshift tx', async function () {
+ metamaskController.createShapeShiftTx(depositAddress, depositType)
+ assert.equal(shapeShiftTxList[0].depositAddress, depositAddress)
+ })
+
+ })
+
+ describe('#addNewAccount', function () {
+ let addNewAccount
+
+ beforeEach(function () {
+ addNewAccount = metamaskController.addNewAccount()
+ })
+
+ it('errors when an primary keyring is does not exist', async function () {
+ try {
+ await addNewAccount
+ assert.equal(1 === 0)
+ } catch (e) {
+ assert.equal(e.message, 'MetamaskController - No HD Key Tree found')
+ }
+ })
+ })
+
+ describe('#verifyseedPhrase', function () {
+ let seedPhrase, getConfigSeed
+
+ it('errors when no keying is provided', async function () {
+ try {
+ await metamaskController.verifySeedPhrase()
+ } catch (error) {
+ assert.equal(error.message, 'MetamaskController - No HD Key Tree found')
+ }
+ })
+
+ beforeEach(async function () {
+ await metamaskController.createNewVaultAndKeychain('password')
+ seedPhrase = await metamaskController.verifySeedPhrase()
+ })
+
+ it('#placeSeedWords should match the initially created vault seed', function () {
+
+ metamaskController.placeSeedWords((err, result) => {
+ if (err) {
+ console.log(err)
+ } else {
+ getConfigSeed = metamaskController.configManager.getSeedWords()
+ assert.equal(result, seedPhrase)
+ assert.equal(result, getConfigSeed)
+ }
+ })
+ assert.equal(getConfigSeed, undefined)
+ })
+
+ it('#addNewAccount', async function () {
+ await metamaskController.addNewAccount()
+ const getAccounts = await metamaskController.keyringController.getAccounts()
+ assert.equal(getAccounts.length, 2)
+ })
+ })
+
+ describe('#resetAccount', function () {
+
+ beforeEach(function () {
+ const selectedAddressStub = sinon.stub(metamaskController.preferencesController, 'getSelectedAddress')
+ const getNetworkstub = sinon.stub(metamaskController.txController.txStateManager, 'getNetwork')
+
+ selectedAddressStub.returns('0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
+ getNetworkstub.returns(42)
+
+ metamaskController.txController.txStateManager._saveTxList([
+ { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'} },
+ { id: 2, status: 'rejected', metamaskNetworkId: 32, txParams: {} },
+ { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4'} },
+ ])
+ })
+
+ it('wipes transactions from only the correct network id and with the selected address', async function () {
+ await metamaskController.resetAccount()
+ assert.equal(metamaskController.txController.txStateManager.getTx(1), undefined)
+ })
+ })
+
+ describe('#clearSeedWordCache', function () {
+
+ it('should have set seed words', function () {
+ metamaskController.configManager.setSeedWords('test words')
+ const getConfigSeed = metamaskController.configManager.getSeedWords()
+ assert.equal(getConfigSeed, 'test words')
+ })
+
+ it('should clear config seed phrase', function () {
+ metamaskController.configManager.setSeedWords('test words')
+ metamaskController.clearSeedWordCache((err, result) => {
+ if (err) console.log(err)
+ })
+ const getConfigSeed = metamaskController.configManager.getSeedWords()
+ assert.equal(getConfigSeed, null)
+ })
+
+ })
+
+ describe('#setCurrentLocale', function () {
+
+ it('checks the default currentLocale', function () {
+ const preferenceCurrentLocale = metamaskController.preferencesController.store.getState().currentLocale
+ assert.equal(preferenceCurrentLocale, undefined)
+ })
+
+ it('sets current locale in preferences controller', function () {
+ metamaskController.setCurrentLocale('ja', noop)
+ const preferenceCurrentLocale = metamaskController.preferencesController.store.getState().currentLocale
+ assert.equal(preferenceCurrentLocale, 'ja')
+ })
+
+ })
+
+ describe('#newUnsignedMessage', function () {
+
+ let msgParams, metamaskMsgs, messages, msgId
+
+ const address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
+ const data = '0x43727970746f6b697474696573'
+
+ beforeEach(function () {
+
+ msgParams = {
+ 'from': address,
+ 'data': data,
+ }
+
+ metamaskController.newUnsignedMessage(msgParams, noop)
+ metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
+ messages = metamaskController.messageManager.messages
+ msgId = Object.keys(metamaskMsgs)[0]
+ })
+
+ it('persists address from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.from, address)
+ })
+
+ it('persists data from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.data, data)
+ })
+
+ it('sets the status to unapproved', function () {
+ assert.equal(metamaskMsgs[msgId].status, 'unapproved')
+ })
+
+ it('sets the type to eth_sign', function () {
+ assert.equal(metamaskMsgs[msgId].type, 'eth_sign')
+ })
+
+ it('rejects the message', function () {
+ const msgIdInt = parseInt(msgId)
+ metamaskController.cancelMessage(msgIdInt, noop)
+ assert.equal(messages[0].status, 'rejected')
+ })
+ })
+
+ describe('#newUnsignedPersonalMessage', function () {
+
+ it('errors with no from in msgParams', function () {
+ const msgParams = {
+ 'data': data,
+ }
+ metamaskController.newUnsignedPersonalMessage(msgParams, function (error) {
+ assert.equal(error.message, 'MetaMask Message Signature: from field is required.')
+ })
+ })
+
+ let msgParams, metamaskMsgs, messages, msgId
+
+ const address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
+ const data = '0x43727970746f6b697474696573'
+
+ beforeEach(function () {
+
+ msgParams = {
+ 'from': address,
+ 'data': data,
+ }
+
+ metamaskController.newUnsignedPersonalMessage(msgParams, noop)
+ metamaskMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
+ messages = metamaskController.personalMessageManager.messages
+ msgId = Object.keys(metamaskMsgs)[0]
+ })
+
+ it('persists address from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.from, address)
+ })
+
+ it('persists data from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.data, data)
+ })
+
+ it('sets the status to unapproved', function () {
+ assert.equal(metamaskMsgs[msgId].status, 'unapproved')
+ })
+
+ it('sets the type to personal_sign', function () {
+ assert.equal(metamaskMsgs[msgId].type, 'personal_sign')
+ })
+
+ it('rejects the message', function () {
+ const msgIdInt = parseInt(msgId)
+ metamaskController.cancelPersonalMessage(msgIdInt, noop)
+ assert.equal(messages[0].status, 'rejected')
+ })
+ })
+
+ describe('#approvePersonalMessage', function () {
+
+ it('errors with no from in msgParams', function () {
+ const msgParams = {
+ 'data': data,
+ }
+ metamaskController.approvePersonalMessage(msgParams, function (error) {
+ assert.equal(error.message, 'MetaMask Message Signature: from field is required.')
+ })
+ })
+
+ let msgParams, metamaskMsgs, msgId
+
+ const address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
+ const data = '0x43727970746f6b697474696573'
+
+ beforeEach(function () {
+
+ msgParams = {
+ 'from': address,
+ 'data': data,
+ }
+
+ metamaskController.approvePersonalMessage(msgParams, noop)
+ metamaskMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
+ msgId = Object.keys(metamaskMsgs)[0]
+ })
+
+ it('persists address from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.from, address)
+ })
+
+ it('persists data from msg params', function () {
+ assert.equal(metamaskMsgs[msgId].msgParams.data, data)
+ })
+
+ it('sets the status to unapproved', function () {
+ assert.equal(metamaskMsgs[msgId].status, 'unapproved')
+ })
+
+ it('sets the type to personal_sign', function () {
+ assert.equal(metamaskMsgs[msgId].type, 'personal_sign')
+ })
+ })
+
+ describe('#markAccountsFound', function () {
+ it('adds lost accounts to config manager data', function () {
+ metamaskController.markAccountsFound(noop)
+ const configManagerData = metamaskController.configManager.getData()
+ assert.deepEqual(configManagerData.lostAccounts, [])
+ })
+ })
+
+ describe('#markPasswordForgotten', function () {
+ it('adds and sets forgottenPassword to config data to true', function () {
+ metamaskController.markPasswordForgotten(noop)
+ const configManagerData = metamaskController.configManager.getData()
+ assert.equal(configManagerData.forgottenPassword, true)
+ })
+ })
+
+ describe('#unMarkPasswordForgotten', function () {
+ it('adds and sets forgottenPassword to config data to false', function () {
+ metamaskController.unMarkPasswordForgotten(noop)
+ const configManagerData = metamaskController.configManager.getData()
+ assert.equal(configManagerData.forgottenPassword, false)
+ })
+ })
+
})
diff --git a/test/unit/nameForAccount_test.js b/test/unit/nameForAccount_test.js
index 32af49e9d..9bb02c6bc 100644
--- a/test/unit/nameForAccount_test.js
+++ b/test/unit/nameForAccount_test.js
@@ -6,7 +6,7 @@ var contractNamer = require(path.join(__dirname, '..', '..', 'old-ui', 'lib', 'c
describe('contractNamer', function () {
beforeEach(function () {
- this.sinon = sinon.sandbox.create()
+ this.sinon = sinon.createSandbox()
})
afterEach(function () {
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index f0b4e3bfc..62f4f28a8 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -294,7 +294,7 @@ describe('PendingTransactionTracker', function () {
})
afterEach(() => {
- pendingTxTracker.publishTransaction.reset()
+ pendingTxTracker.publishTransaction.restore()
})
it('should publish the transaction', function (done) {
diff --git a/test/unit/reducers/unlock_vault_test.js b/test/unit/reducers/unlock_vault_test.js
index 2b7d70b2c..d66e8edbb 100644
--- a/test/unit/reducers/unlock_vault_test.js
+++ b/test/unit/reducers/unlock_vault_test.js
@@ -10,7 +10,7 @@ var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'redu
describe('#unlockMetamask(selectedAccount)', function () {
beforeEach(function () {
// sinon allows stubbing methods that are easily verified
- this.sinon = sinon.sandbox.create()
+ this.sinon = sinon.createSandbox()
})
afterEach(function () {
diff --git a/test/unit/util_test.js b/test/unit/util_test.js
index 59048975a..39473854f 100644
--- a/test/unit/util_test.js
+++ b/test/unit/util_test.js
@@ -10,7 +10,7 @@ describe('util', function () {
for (var i = 0; i < 18; i++) { ethInWei += '0' }
beforeEach(function () {
- this.sinon = sinon.sandbox.create()
+ this.sinon = sinon.createSandbox()
})
afterEach(function () {