aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/app')
-rw-r--r--test/unit/app/cleanErrorStack.spec.js33
-rw-r--r--test/unit/app/controllers/blacklist-controller-test.js15
-rw-r--r--test/unit/app/controllers/currency-controller-test.js3
-rw-r--r--test/unit/app/controllers/detect-tokens-test.js51
-rw-r--r--test/unit/app/controllers/metamask-controller-test.js248
-rw-r--r--test/unit/app/controllers/network-contoller-test.js7
-rw-r--r--test/unit/app/controllers/notice-controller-test.js7
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js140
-rw-r--r--test/unit/app/controllers/transactions/nonce-tracker-test.js9
-rw-r--r--test/unit/app/controllers/transactions/pending-tx-test.js78
-rw-r--r--test/unit/app/controllers/transactions/tx-controller-test.js100
11 files changed, 497 insertions, 194 deletions
diff --git a/test/unit/app/cleanErrorStack.spec.js b/test/unit/app/cleanErrorStack.spec.js
new file mode 100644
index 000000000..7a1ab1ed8
--- /dev/null
+++ b/test/unit/app/cleanErrorStack.spec.js
@@ -0,0 +1,33 @@
+const assert = require('assert')
+const cleanErrorStack = require('../../../app/scripts/lib/cleanErrorStack')
+
+describe('Clean Error Stack', () => {
+
+ const testMessage = 'Test Message'
+ const testError = new Error(testMessage)
+ const undefinedErrorName = new Error(testMessage)
+ const blankErrorName = new Error(testMessage)
+ const blankMsgError = new Error()
+
+ beforeEach(() => {
+ undefinedErrorName.name = undefined
+ blankErrorName.name = ''
+ })
+
+ it('tests error with message', () => {
+ assert.equal(cleanErrorStack(testError), 'Error: Test Message')
+ })
+
+ it('tests error with undefined name', () => {
+ assert.equal(cleanErrorStack(undefinedErrorName).toString(), 'Error: Test Message')
+ })
+
+ it('tests error with blank name', () => {
+ assert.equal(cleanErrorStack(blankErrorName).toString(), 'Test Message')
+ })
+
+ it('tests error with blank message', () => {
+ assert.equal(cleanErrorStack(blankMsgError), 'Error')
+ })
+
+})
diff --git a/test/unit/app/controllers/blacklist-controller-test.js b/test/unit/app/controllers/blacklist-controller-test.js
index 085641777..7a14c02cc 100644
--- a/test/unit/app/controllers/blacklist-controller-test.js
+++ b/test/unit/app/controllers/blacklist-controller-test.js
@@ -8,6 +8,16 @@ describe('blacklist controller', function () {
blacklistController = new BlacklistController()
})
+ describe('whitelistDomain', function () {
+ it('should add hostname to the runtime whitelist', function () {
+ blacklistController.whitelistDomain('foo.com')
+ assert.deepEqual(blacklistController.store.getState().whitelist, ['foo.com'])
+
+ blacklistController.whitelistDomain('bar.com')
+ assert.deepEqual(blacklistController.store.getState().whitelist, ['bar.com', 'foo.com'])
+ })
+ })
+
describe('checkForPhishing', function () {
it('should not flag whitelisted values', function () {
const result = blacklistController.checkForPhishing('www.metamask.io')
@@ -37,5 +47,10 @@ describe('blacklist controller', function () {
const result = blacklistController.checkForPhishing('zero-faucet.metamask.io')
assert.equal(result, false)
})
+ it('should not flag whitelisted domain', function () {
+ blacklistController.whitelistDomain('metamask.com')
+ const result = blacklistController.checkForPhishing('metamask.com')
+ assert.equal(result, false)
+ })
})
})
diff --git a/test/unit/app/controllers/currency-controller-test.js b/test/unit/app/controllers/currency-controller-test.js
index 1941d1c43..7c4644d9f 100644
--- a/test/unit/app/controllers/currency-controller-test.js
+++ b/test/unit/app/controllers/currency-controller-test.js
@@ -1,6 +1,3 @@
-// polyfill fetch
-global.fetch = global.fetch || require('isomorphic-fetch')
-
const assert = require('assert')
const nock = require('nock')
const CurrencyController = require('../../../../app/scripts/controllers/currency')
diff --git a/test/unit/app/controllers/detect-tokens-test.js b/test/unit/app/controllers/detect-tokens-test.js
index d6c3fad8a..2acc53e92 100644
--- a/test/unit/app/controllers/detect-tokens-test.js
+++ b/test/unit/app/controllers/detect-tokens-test.js
@@ -1,4 +1,5 @@
const assert = require('assert')
+const nock = require('nock')
const sinon = require('sinon')
const ObservableStore = require('obs-store')
const DetectTokensController = require('../../../../app/scripts/controllers/detect-tokens')
@@ -6,15 +7,34 @@ const NetworkController = require('../../../../app/scripts/controllers/network/n
const PreferencesController = require('../../../../app/scripts/controllers/preferences')
describe('DetectTokensController', () => {
- const sandbox = sinon.createSandbox()
- let clock, keyringMemStore, network, preferences
- beforeEach(async () => {
- keyringMemStore = new ObservableStore({ isUnlocked: false})
- network = new NetworkController({ provider: { type: 'mainnet' }})
- preferences = new PreferencesController({ network })
- })
- after(() => {
- sandbox.restore()
+ const sandbox = sinon.createSandbox()
+ let clock, keyringMemStore, network, preferences, controller
+
+ const noop = () => {}
+
+ const networkControllerProviderConfig = {
+ getAccounts: noop,
+ }
+
+ beforeEach(async () => {
+
+
+ nock('https://api.infura.io')
+ .get(/.*/)
+ .reply(200)
+
+ keyringMemStore = new ObservableStore({ isUnlocked: false})
+ network = new NetworkController()
+ preferences = new PreferencesController({ network })
+ controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
+
+ network.initializeProvider(networkControllerProviderConfig)
+
+ })
+
+ after(() => {
+ sandbox.restore()
+ nock.cleanAll()
})
it('should poll on correct interval', async () => {
@@ -26,7 +46,10 @@ describe('DetectTokensController', () => {
it('should be called on every polling period', async () => {
clock = sandbox.useFakeTimers()
+ const network = new NetworkController()
+ network.initializeProvider(networkControllerProviderConfig)
network.setProviderType('mainnet')
+ const preferences = new PreferencesController({ network })
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -44,8 +67,6 @@ describe('DetectTokensController', () => {
})
it('should not check tokens while in test network', async () => {
- network.setProviderType('rinkeby')
- const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -58,7 +79,6 @@ describe('DetectTokensController', () => {
})
it('should only check and add tokens while in main network', async () => {
- network.setProviderType('mainnet')
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
@@ -75,7 +95,6 @@ describe('DetectTokensController', () => {
})
it('should not detect same token while in main network', async () => {
- network.setProviderType('mainnet')
preferences.addToken('0x0d262e5dc4a06a0f1c90ce79c7a60c09dfc884e4', 'J8T', 8)
const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
@@ -93,8 +112,6 @@ describe('DetectTokensController', () => {
})
it('should trigger detect new tokens when change address', async () => {
- network.setProviderType('mainnet')
- const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = true
var stub = sandbox.stub(controller, 'detectNewTokens')
@@ -103,8 +120,6 @@ describe('DetectTokensController', () => {
})
it('should trigger detect new tokens when submit password', async () => {
- network.setProviderType('mainnet')
- const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.selectedAddress = '0x0'
var stub = sandbox.stub(controller, 'detectNewTokens')
@@ -113,8 +128,6 @@ describe('DetectTokensController', () => {
})
it('should not trigger detect new tokens when not open or not unlocked', async () => {
- network.setProviderType('mainnet')
- const controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })
controller.isOpen = true
controller.isUnlocked = false
var stub = sandbox.stub(controller, 'detectTokenBalance')
diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js
index 9f25cf376..17be2c028 100644
--- a/test/unit/app/controllers/metamask-controller-test.js
+++ b/test/unit/app/controllers/metamask-controller-test.js
@@ -3,16 +3,22 @@ const sinon = require('sinon')
const clone = require('clone')
const nock = require('nock')
const createThoughStream = require('through2').obj
-const MetaMaskController = require('../../../../app/scripts/metamask-controller')
const blacklistJSON = require('eth-phishing-detect/src/config')
-const firstTimeState = require('../../../../app/scripts/first-time-state')
+const MetaMaskController = require('../../../../app/scripts/metamask-controller')
+const firstTimeState = require('../../../unit/localhostState')
+const createTxMeta = require('../../../lib/createTxMeta')
+const EthQuery = require('eth-query')
const currentNetworkId = 42
const DEFAULT_LABEL = 'Account 1'
+const DEFAULT_LABEL_2 = 'Account 2'
const TEST_SEED = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'
const TEST_ADDRESS = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
+const TEST_ADDRESS_2 = '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b'
+const TEST_ADDRESS_3 = '0xeb9e64b93097bc15f01f13eae97015c57ab64823'
const TEST_SEED_ALT = 'setup olympic issue mobile velvet surge alcohol burger horse view reopen gentle'
const TEST_ADDRESS_ALT = '0xc42edfcc21ed14dda456aa0756c153f7985d8813'
+const CUSTOM_RPC_URL = 'http://localhost:8545'
describe('MetaMaskController', function () {
let metamaskController
@@ -110,7 +116,7 @@ describe('MetaMaskController', function () {
}
const gasPrice = metamaskController.getGasPrice()
- assert.equal(gasPrice, '0x3b9aca00', 'accurately estimates 50th percentile accepted gas price')
+ assert.equal(gasPrice, '0x174876e800', 'accurately estimates 65th percentile accepted gas price')
metamaskController.recentBlocksController = realRecentBlocksController
})
@@ -134,6 +140,9 @@ describe('MetaMaskController', function () {
describe('#createNewVaultAndRestore', function () {
it('should be able to call newVaultAndRestore despite a mistake.', async function () {
const password = 'what-what-what'
+ sandbox.stub(metamaskController, 'getBalance')
+ metamaskController.getBalance.callsFake(() => { return Promise.resolve('0x0') })
+
await metamaskController.createNewVaultAndRestore(password, TEST_SEED.slice(0, -1)).catch((e) => null)
await metamaskController.createNewVaultAndRestore(password, TEST_SEED)
@@ -141,6 +150,9 @@ describe('MetaMaskController', function () {
})
it('should clear previous identities after vault restoration', async () => {
+ sandbox.stub(metamaskController, 'getBalance')
+ metamaskController.getBalance.callsFake(() => { return Promise.resolve('0x0') })
+
await metamaskController.createNewVaultAndRestore('foobar1337', TEST_SEED)
assert.deepEqual(metamaskController.getState().identities, {
[TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL },
@@ -156,6 +168,54 @@ describe('MetaMaskController', function () {
[TEST_ADDRESS_ALT]: { address: TEST_ADDRESS_ALT, name: DEFAULT_LABEL },
})
})
+
+ it('should restore any consecutive accounts with balances', async () => {
+ sandbox.stub(metamaskController, 'getBalance')
+ metamaskController.getBalance.withArgs(TEST_ADDRESS).callsFake(() => {
+ return Promise.resolve('0x14ced5122ce0a000')
+ })
+ metamaskController.getBalance.withArgs(TEST_ADDRESS_2).callsFake(() => {
+ return Promise.resolve('0x0')
+ })
+ metamaskController.getBalance.withArgs(TEST_ADDRESS_3).callsFake(() => {
+ return Promise.resolve('0x14ced5122ce0a000')
+ })
+
+ await metamaskController.createNewVaultAndRestore('foobar1337', TEST_SEED)
+ assert.deepEqual(metamaskController.getState().identities, {
+ [TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL },
+ [TEST_ADDRESS_2]: { address: TEST_ADDRESS_2, name: DEFAULT_LABEL_2 },
+ })
+ })
+ })
+
+ describe('#getBalance', () => {
+ it('should return the balance known by accountTracker', async () => {
+ const accounts = {}
+ const balance = '0x14ced5122ce0a000'
+ accounts[TEST_ADDRESS] = { balance: balance }
+
+ metamaskController.accountTracker.store.putState({ accounts: accounts })
+
+ const gotten = await metamaskController.getBalance(TEST_ADDRESS)
+
+ assert.equal(balance, gotten)
+ })
+
+ it('should ask the network for a balance when not known by accountTracker', async () => {
+ const accounts = {}
+ const balance = '0x14ced5122ce0a000'
+ const ethQuery = new EthQuery()
+ sinon.stub(ethQuery, 'getBalance').callsFake((account, callback) => {
+ callback(undefined, balance)
+ })
+
+ metamaskController.accountTracker.store.putState({ accounts: accounts })
+
+ const gotten = await metamaskController.getBalance(TEST_ADDRESS, ethQuery)
+
+ assert.equal(balance, gotten)
+ })
})
describe('#getApi', function () {
@@ -360,29 +420,19 @@ describe('MetaMaskController', function () {
})
describe('#setCustomRpc', function () {
- const customRPC = 'https://custom.rpc/'
let rpcTarget
beforeEach(function () {
-
- nock('https://custom.rpc')
- .post('/')
- .reply(200)
-
- rpcTarget = metamaskController.setCustomRpc(customRPC)
- })
-
- afterEach(function () {
- nock.cleanAll()
+ rpcTarget = metamaskController.setCustomRpc(CUSTOM_RPC_URL)
})
it('returns custom RPC that when called', async function () {
- assert.equal(await rpcTarget, customRPC)
+ assert.equal(await rpcTarget, CUSTOM_RPC_URL)
})
it('changes the network controller rpc', function () {
const networkControllerState = metamaskController.networkController.store.getState()
- assert.equal(networkControllerState.provider.rpcTarget, customRPC)
+ assert.equal(networkControllerState.provider.rpcTarget, CUSTOM_RPC_URL)
})
})
@@ -487,9 +537,10 @@ describe('MetaMaskController', function () {
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'} },
+ createTxMeta({ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'} }),
+ createTxMeta({ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'} }),
+ createTxMeta({ id: 2, status: 'rejected', metamaskNetworkId: 32 }),
+ createTxMeta({ id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4'} }),
])
})
@@ -522,7 +573,7 @@ describe('MetaMaskController', function () {
assert(metamaskController.preferencesController.removeAddress.calledWith(addressToRemove))
})
it('should call accountTracker.removeAccount', async function () {
- assert(metamaskController.accountTracker.removeAccount.calledWith(addressToRemove))
+ assert(metamaskController.accountTracker.removeAccount.calledWith([addressToRemove]))
})
it('should call keyringController.removeAccount', async function () {
assert(metamaskController.keyringController.removeAccount.calledWith(addressToRemove))
@@ -533,22 +584,18 @@ describe('MetaMaskController', function () {
})
describe('#clearSeedWordCache', function () {
+ it('should set seed words to null', function (done) {
+ sandbox.stub(metamaskController.preferencesController, 'setSeedWords')
+ metamaskController.clearSeedWordCache((err) => {
+ if (err) {
+ done(err)
+ }
- 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)
+ assert.ok(metamaskController.preferencesController.setSeedWords.calledOnce)
+ assert.deepEqual(metamaskController.preferencesController.setSeedWords.args, [[null]])
+ done()
})
- const getConfigSeed = metamaskController.configManager.getSeedWords()
- assert.equal(getConfigSeed, null)
})
-
})
describe('#setCurrentLocale', function () {
@@ -566,14 +613,16 @@ describe('MetaMaskController', function () {
})
- describe('#newUnsignedMessage', function () {
+ describe('#newUnsignedMessage', () => {
let msgParams, metamaskMsgs, messages, msgId
const address = '0xc42edfcc21ed14dda456aa0756c153f7985d8813'
const data = '0x43727970746f6b697474696573'
- beforeEach(async function () {
+ beforeEach(async () => {
+ sandbox.stub(metamaskController, 'getBalance')
+ metamaskController.getBalance.callsFake(() => { return Promise.resolve('0x0') })
await metamaskController.createNewVaultAndRestore('foobar1337', TEST_SEED_ALT)
@@ -582,7 +631,10 @@ describe('MetaMaskController', function () {
'data': data,
}
- metamaskController.newUnsignedMessage(msgParams, noop)
+ const promise = metamaskController.newUnsignedMessage(msgParams)
+ // handle the promise so it doesn't throw an unhandledRejection
+ promise.then(noop).catch(noop)
+
metamaskMsgs = metamaskController.messageManager.getUnapprovedMsgs()
messages = metamaskController.messageManager.messages
msgId = Object.keys(metamaskMsgs)[0]
@@ -622,13 +674,16 @@ describe('MetaMaskController', function () {
describe('#newUnsignedPersonalMessage', function () {
- it('errors with no from in msgParams', function () {
+ it('errors with no from in msgParams', async () => {
const msgParams = {
'data': data,
}
- metamaskController.newUnsignedPersonalMessage(msgParams, function (error) {
+ try {
+ await metamaskController.newUnsignedPersonalMessage(msgParams)
+ assert.fail('should have thrown')
+ } catch (error) {
assert.equal(error.message, 'MetaMask Message Signature: from field is required.')
- })
+ }
})
let msgParams, metamaskPersonalMsgs, personalMessages, msgId
@@ -637,6 +692,8 @@ describe('MetaMaskController', function () {
const data = '0x43727970746f6b697474696573'
beforeEach(async function () {
+ sandbox.stub(metamaskController, 'getBalance')
+ metamaskController.getBalance.callsFake(() => { return Promise.resolve('0x0') })
await metamaskController.createNewVaultAndRestore('foobar1337', TEST_SEED_ALT)
@@ -645,7 +702,10 @@ describe('MetaMaskController', function () {
'data': data,
}
- metamaskController.newUnsignedPersonalMessage(msgParams, noop)
+ const promise = metamaskController.newUnsignedPersonalMessage(msgParams)
+ // handle the promise so it doesn't throw an unhandledRejection
+ promise.then(noop).catch(noop)
+
metamaskPersonalMsgs = metamaskController.personalMessageManager.getUnapprovedMsgs()
personalMessages = metamaskController.personalMessageManager.messages
msgId = Object.keys(metamaskPersonalMsgs)[0]
@@ -684,22 +744,27 @@ describe('MetaMaskController', function () {
describe('#setupUntrustedCommunication', function () {
let streamTest
- const phishingUrl = 'decentral.market'
+ const phishingUrl = 'myethereumwalletntw.com'
afterEach(function () {
streamTest.end()
})
- it('sets up phishing stream for untrusted communication ', async function () {
+ it('sets up phishing stream for untrusted communication ', async () => {
await metamaskController.blacklistController.updatePhishingList()
+ console.log(blacklistJSON.blacklist.includes(phishingUrl))
+
+ const { promise, resolve } = deferredPromise()
streamTest = createThoughStream((chunk, enc, cb) => {
- assert.equal(chunk.name, 'phishing')
+ if (chunk.name !== 'phishing') return cb()
assert.equal(chunk.data.hostname, phishingUrl)
- cb()
- })
- // console.log(streamTest)
- metamaskController.setupUntrustedCommunication(streamTest, phishingUrl)
+ resolve()
+ cb()
+ })
+ metamaskController.setupUntrustedCommunication(streamTest, phishingUrl)
+
+ await promise
})
})
@@ -724,25 +789,102 @@ describe('MetaMaskController', function () {
describe('#markAccountsFound', function () {
it('adds lost accounts to config manager data', function () {
metamaskController.markAccountsFound(noop)
- const configManagerData = metamaskController.configManager.getData()
- assert.deepEqual(configManagerData.lostAccounts, [])
+ const state = metamaskController.getState()
+ assert.deepEqual(state.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)
+ const state = metamaskController.getState()
+ assert.equal(state.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)
+ const state = metamaskController.getState()
+ assert.equal(state.forgottenPassword, false)
+ })
+ })
+
+ describe('#_onKeyringControllerUpdate', function () {
+ it('should do nothing if there are no keyrings in state', async function () {
+ const addAddresses = sinon.fake()
+ const syncWithAddresses = sinon.fake()
+ sandbox.replace(metamaskController, 'preferencesController', {
+ addAddresses,
+ })
+ sandbox.replace(metamaskController, 'accountTracker', {
+ syncWithAddresses,
+ })
+
+ const oldState = metamaskController.getState()
+ await metamaskController._onKeyringControllerUpdate({keyrings: []})
+
+ assert.ok(addAddresses.notCalled)
+ assert.ok(syncWithAddresses.notCalled)
+ assert.deepEqual(metamaskController.getState(), oldState)
+ })
+
+ it('should update selected address if keyrings was locked', async function () {
+ const addAddresses = sinon.fake()
+ const getSelectedAddress = sinon.fake.returns('0x42')
+ const setSelectedAddress = sinon.fake()
+ const syncWithAddresses = sinon.fake()
+ sandbox.replace(metamaskController, 'preferencesController', {
+ addAddresses,
+ getSelectedAddress,
+ setSelectedAddress,
+ })
+ sandbox.replace(metamaskController, 'accountTracker', {
+ syncWithAddresses,
+ })
+
+ const oldState = metamaskController.getState()
+ await metamaskController._onKeyringControllerUpdate({
+ isUnlocked: false,
+ keyrings: [{
+ accounts: ['0x1', '0x2'],
+ }],
+ })
+
+ assert.deepEqual(addAddresses.args, [[['0x1', '0x2']]])
+ assert.deepEqual(syncWithAddresses.args, [[['0x1', '0x2']]])
+ assert.deepEqual(setSelectedAddress.args, [['0x1']])
+ assert.deepEqual(metamaskController.getState(), oldState)
+ })
+
+ it('should NOT update selected address if already unlocked', async function () {
+ const addAddresses = sinon.fake()
+ const syncWithAddresses = sinon.fake()
+ sandbox.replace(metamaskController, 'preferencesController', {
+ addAddresses,
+ })
+ sandbox.replace(metamaskController, 'accountTracker', {
+ syncWithAddresses,
+ })
+
+ const oldState = metamaskController.getState()
+ await metamaskController._onKeyringControllerUpdate({
+ isUnlocked: true,
+ keyrings: [{
+ accounts: ['0x1', '0x2'],
+ }],
+ })
+
+ assert.deepEqual(addAddresses.args, [[['0x1', '0x2']]])
+ assert.deepEqual(syncWithAddresses.args, [[['0x1', '0x2']]])
+ assert.deepEqual(metamaskController.getState(), oldState)
})
})
})
+
+function deferredPromise () {
+ let resolve
+ const promise = new Promise(_resolve => { resolve = _resolve })
+ return { promise, resolve }
+}
diff --git a/test/unit/app/controllers/network-contoller-test.js b/test/unit/app/controllers/network-contoller-test.js
index e16fb104e..822311931 100644
--- a/test/unit/app/controllers/network-contoller-test.js
+++ b/test/unit/app/controllers/network-contoller-test.js
@@ -32,9 +32,10 @@ describe('# Network Controller', function () {
describe('#provider', function () {
it('provider should be updatable without reassignment', function () {
networkController.initializeProvider(networkControllerProviderConfig)
- const proxy = networkController._proxy
- proxy.setTarget({ test: true, on: () => {} })
- assert.ok(proxy.test)
+ const providerProxy = networkController.getProviderAndBlockTracker().provider
+ assert.equal(providerProxy.test, undefined)
+ providerProxy.setTarget({ test: true })
+ assert.equal(providerProxy.test, true)
})
})
describe('#getNetworkState', function () {
diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js
index b3ae75080..834c88f7b 100644
--- a/test/unit/app/controllers/notice-controller-test.js
+++ b/test/unit/app/controllers/notice-controller-test.js
@@ -1,16 +1,11 @@
const assert = require('assert')
-const configManagerGen = require('../../../lib/mock-config-manager')
const NoticeController = require('../../../../app/scripts/notice-controller')
describe('notice-controller', function () {
var noticeController
beforeEach(function () {
- // simple localStorage polyfill
- const configManager = configManagerGen()
- noticeController = new NoticeController({
- configManager: configManager,
- })
+ noticeController = new NoticeController()
})
describe('notices', function () {
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index 9b2c846bd..b5ccf3fb5 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -1,6 +1,7 @@
const assert = require('assert')
const ObservableStore = require('obs-store')
const PreferencesController = require('../../../../app/scripts/controllers/preferences')
+const sinon = require('sinon')
describe('preferences controller', function () {
let preferencesController
@@ -339,5 +340,144 @@ describe('preferences controller', function () {
assert.deepEqual(tokensSecond, initialTokensSecond, 'tokens equal for same network')
})
})
+
+ describe('on watchAsset', function () {
+ var stubNext, stubEnd, stubHandleWatchAssetERC20, asy, req, res
+ const sandbox = sinon.createSandbox()
+
+ beforeEach(() => {
+ req = {params: {}}
+ res = {}
+ asy = {next: () => {}, end: () => {}}
+ stubNext = sandbox.stub(asy, 'next')
+ stubEnd = sandbox.stub(asy, 'end').returns(0)
+ stubHandleWatchAssetERC20 = sandbox.stub(preferencesController, '_handleWatchAssetERC20')
+ })
+ after(() => {
+ sandbox.restore()
+ })
+
+ it('shouldn not do anything if method not corresponds', async function () {
+ const asy = {next: () => {}, end: () => {}}
+ var stubNext = sandbox.stub(asy, 'next')
+ var stubEnd = sandbox.stub(asy, 'end').returns(0)
+ req.method = 'metamask'
+ await preferencesController.requestWatchAsset(req, res, asy.next, asy.end)
+ sandbox.assert.notCalled(stubEnd)
+ sandbox.assert.called(stubNext)
+ })
+ it('should do something if method is supported', async function () {
+ const asy = {next: () => {}, end: () => {}}
+ var stubNext = sandbox.stub(asy, 'next')
+ var stubEnd = sandbox.stub(asy, 'end').returns(0)
+ req.method = 'metamask_watchAsset'
+ req.params.type = 'someasset'
+ await preferencesController.requestWatchAsset(req, res, asy.next, asy.end)
+ sandbox.assert.called(stubEnd)
+ sandbox.assert.notCalled(stubNext)
+ })
+ it('should through error if method is supported but asset type is not', async function () {
+ req.method = 'metamask_watchAsset'
+ req.params.type = 'someasset'
+ await preferencesController.requestWatchAsset(req, res, asy.next, asy.end)
+ sandbox.assert.called(stubEnd)
+ sandbox.assert.notCalled(stubHandleWatchAssetERC20)
+ sandbox.assert.notCalled(stubNext)
+ assert.deepEqual(res, {})
+ })
+ it('should trigger handle add asset if type supported', async function () {
+ const asy = {next: () => {}, end: () => {}}
+ req.method = 'metamask_watchAsset'
+ req.params.type = 'ERC20'
+ await preferencesController.requestWatchAsset(req, res, asy.next, asy.end)
+ sandbox.assert.called(stubHandleWatchAssetERC20)
+ })
+ })
+
+ describe('on watchAsset of type ERC20', function () {
+ var req
+
+ const sandbox = sinon.createSandbox()
+ beforeEach(() => {
+ req = {params: {type: 'ERC20'}}
+ })
+ after(() => {
+ sandbox.restore()
+ })
+
+ it('should add suggested token', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+ const image = 'someimage'
+ req.params.options = { address, symbol, decimals, image }
+
+ sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true)
+ preferencesController.showWatchAssetUi = async () => {}
+
+ await preferencesController._handleWatchAssetERC20(req.params.options)
+ const suggested = preferencesController.getSuggestedTokens()
+ assert.equal(Object.keys(suggested).length, 1, `one token added ${Object.keys(suggested)}`)
+
+ assert.equal(suggested[address].address, address, 'set address correctly')
+ assert.equal(suggested[address].symbol, symbol, 'set symbol correctly')
+ assert.equal(suggested[address].decimals, decimals, 'set decimals correctly')
+ assert.equal(suggested[address].image, image, 'set image correctly')
+ })
+
+ it('should add token correctly if user confirms', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+ const image = 'someimage'
+ req.params.options = { address, symbol, decimals, image }
+
+ sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true)
+ preferencesController.showWatchAssetUi = async () => {
+ await preferencesController.addToken(address, symbol, decimals, image)
+ }
+
+ await preferencesController._handleWatchAssetERC20(req.params.options)
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 1, `one token added`)
+ const added = tokens[0]
+ assert.equal(added.address, address, 'set address correctly')
+ assert.equal(added.symbol, symbol, 'set symbol correctly')
+ assert.equal(added.decimals, decimals, 'set decimals correctly')
+
+ const assetImages = preferencesController.getAssetImages()
+ assert.ok(assetImages[address], `set image correctly`)
+ })
+ })
+
+ describe('setPasswordForgotten', function () {
+ it('should default to false', function () {
+ const state = preferencesController.store.getState()
+ assert.equal(state.forgottenPassword, false)
+ })
+
+ it('should set the forgottenPassword property in state', function () {
+ assert.equal(preferencesController.store.getState().forgottenPassword, false)
+
+ preferencesController.setPasswordForgotten(true)
+
+ assert.equal(preferencesController.store.getState().forgottenPassword, true)
+ })
+ })
+
+ describe('setSeedWords', function () {
+ it('should default to null', function () {
+ const state = preferencesController.store.getState()
+ assert.equal(state.seedWords, null)
+ })
+
+ it('should set the seedWords property in state', function () {
+ assert.equal(preferencesController.store.getState().seedWords, null)
+
+ preferencesController.setSeedWords('foo bar baz')
+
+ assert.equal(preferencesController.store.getState().seedWords, 'foo bar baz')
+ })
+ })
})
diff --git a/test/unit/app/controllers/transactions/nonce-tracker-test.js b/test/unit/app/controllers/transactions/nonce-tracker-test.js
index 6c0ac759f..51ac390e9 100644
--- a/test/unit/app/controllers/transactions/nonce-tracker-test.js
+++ b/test/unit/app/controllers/transactions/nonce-tracker-test.js
@@ -224,14 +224,15 @@ function generateNonceTrackerWith (pending, confirmed, providerStub = '0x0') {
providerResultStub.result = providerStub
const provider = {
sendAsync: (_, cb) => { cb(undefined, providerResultStub) },
- _blockTracker: {
- getCurrentBlock: () => '0x11b568',
- },
+ }
+ const blockTracker = {
+ getCurrentBlock: () => '0x11b568',
+ getLatestBlock: async () => '0x11b568',
}
return new NonceTracker({
provider,
+ blockTracker,
getPendingTransactions,
getConfirmedTransactions,
})
}
-
diff --git a/test/unit/app/controllers/transactions/pending-tx-test.js b/test/unit/app/controllers/transactions/pending-tx-test.js
index 8bf2da6f8..ba15f1953 100644
--- a/test/unit/app/controllers/transactions/pending-tx-test.js
+++ b/test/unit/app/controllers/transactions/pending-tx-test.js
@@ -9,6 +9,7 @@ describe('PendingTransactionTracker', function () {
let pendingTxTracker, txMeta, txMetaNoHash, providerResultStub,
provider, txMeta3, txList, knownErrors
this.timeout(10000)
+
beforeEach(function () {
txMeta = {
id: 1,
@@ -40,7 +41,10 @@ describe('PendingTransactionTracker', function () {
getPendingTransactions: () => { return [] },
getCompletedTransactions: () => { return [] },
publishTransaction: () => {},
+ confirmTransaction: () => {},
})
+
+ pendingTxTracker._getBlock = (blockNumber) => { return {number: blockNumber, transactions: []} }
})
describe('_checkPendingTx state management', function () {
@@ -92,58 +96,6 @@ describe('PendingTransactionTracker', function () {
})
})
- describe('#checkForTxInBlock', function () {
- it('should return if no pending transactions', function () {
- // throw a type error if it trys to do anything on the block
- // thus failing the test
- const block = Proxy.revocable({}, {}).revoke()
- pendingTxTracker.checkForTxInBlock(block)
- })
- it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
- const block = Proxy.revocable({}, {}).revoke()
- pendingTxTracker.getPendingTransactions = () => [txMetaNoHash]
- pendingTxTracker.once('tx:failed', (txId, err) => {
- assert(txId, txMetaNoHash.id, 'should pass txId')
- done()
- })
- pendingTxTracker.checkForTxInBlock(block)
- })
- it('should emit \'txConfirmed\' if the tx is in the block', function (done) {
- const block = { transactions: [txMeta]}
- pendingTxTracker.getPendingTransactions = () => [txMeta]
- pendingTxTracker.once('tx:confirmed', (txId) => {
- assert(txId, txMeta.id, 'should pass txId')
- done()
- })
- pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
- pendingTxTracker.checkForTxInBlock(block)
- })
- })
- describe('#queryPendingTxs', function () {
- it('should call #_checkPendingTxs if their is no oldBlock', function (done) {
- let oldBlock
- const newBlock = { number: '0x01' }
- pendingTxTracker._checkPendingTxs = done
- pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
- })
- it('should call #_checkPendingTxs if oldBlock and the newBlock have a diff of greater then 1', function (done) {
- const oldBlock = { number: '0x01' }
- const newBlock = { number: '0x03' }
- pendingTxTracker._checkPendingTxs = done
- pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
- })
- it('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less', function (done) {
- const oldBlock = { number: '0x1' }
- const newBlock = { number: '0x2' }
- pendingTxTracker._checkPendingTxs = () => {
- const err = new Error('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less')
- done(err)
- }
- pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
- done()
- })
- })
-
describe('#_checkPendingTx', function () {
it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
pendingTxTracker.once('tx:failed', (txId, err) => {
@@ -157,16 +109,6 @@ describe('PendingTransactionTracker', function () {
providerResultStub.eth_getTransactionByHash = null
pendingTxTracker._checkPendingTx(txMeta)
})
-
- it('should emit \'txConfirmed\'', function (done) {
- providerResultStub.eth_getTransactionByHash = {blockNumber: '0x01'}
- pendingTxTracker.once('tx:confirmed', (txId) => {
- assert(txId, txMeta.id, 'should pass txId')
- done()
- })
- pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
- pendingTxTracker._checkPendingTx(txMeta)
- })
})
describe('#_checkPendingTxs', function () {
@@ -180,19 +122,19 @@ describe('PendingTransactionTracker', function () {
})
})
- it('should warp all txMeta\'s in #_checkPendingTx', function (done) {
+ it('should warp all txMeta\'s in #updatePendingTxs', function (done) {
pendingTxTracker.getPendingTransactions = () => txList
pendingTxTracker._checkPendingTx = (tx) => { tx.resolve(tx) }
Promise.all(txList.map((tx) => tx.processed))
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker._checkPendingTxs()
+ pendingTxTracker.updatePendingTxs()
})
})
describe('#resubmitPendingTxs', function () {
- const blockStub = { number: '0x0' }
+ const blockNumberStub = '0x0'
beforeEach(function () {
const txMeta2 = txMeta3 = txMeta
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
@@ -210,7 +152,7 @@ describe('PendingTransactionTracker', function () {
Promise.all(txList.map((tx) => tx.processed))
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs(blockStub)
+ pendingTxTracker.resubmitPendingTxs(blockNumberStub)
})
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
knownErrors = [
@@ -237,7 +179,7 @@ describe('PendingTransactionTracker', function () {
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs(blockStub)
+ pendingTxTracker.resubmitPendingTxs(blockNumberStub)
})
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
pendingTxTracker.once('tx:warning', (txMeta, err) => {
@@ -255,7 +197,7 @@ describe('PendingTransactionTracker', function () {
.then((txCompletedList) => done())
.catch(done)
- pendingTxTracker.resubmitPendingTxs(blockStub)
+ pendingTxTracker.resubmitPendingTxs(blockNumberStub)
})
})
describe('#_resubmitTx', function () {
diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js
index 26dc7b656..ea58aa560 100644
--- a/test/unit/app/controllers/transactions/tx-controller-test.js
+++ b/test/unit/app/controllers/transactions/tx-controller-test.js
@@ -1,4 +1,5 @@
const assert = require('assert')
+const EventEmitter = require('events')
const ethUtil = require('ethereumjs-util')
const EthTx = require('ethereumjs-tx')
const ObservableStore = require('obs-store')
@@ -22,12 +23,14 @@ describe('Transaction Controller', function () {
}
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
fromAccount = getTestAccounts()[0]
-
+ const blockTrackerStub = new EventEmitter()
+ blockTrackerStub.getCurrentBlock = noop
+ blockTrackerStub.getLatestBlock = noop
txController = new TransactionController({
provider,
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
- blockTracker: { getCurrentBlock: noop, on: noop, once: noop },
+ blockTracker: blockTrackerStub,
signTransaction: (ethTx) => new Promise((resolve) => {
ethTx.sign(fromAccount.key)
resolve()
@@ -49,9 +52,9 @@ describe('Transaction Controller', function () {
describe('#getUnapprovedTxCount', function () {
it('should return the number of unapproved txs', function () {
txController.txStateManager._saveTxList([
- { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
+ { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
+ { id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
+ { id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
])
const unapprovedTxCount = txController.getUnapprovedTxCount()
assert.equal(unapprovedTxCount, 3, 'should be 3')
@@ -61,9 +64,9 @@ describe('Transaction Controller', function () {
describe('#getPendingTxCount', function () {
it('should return the number of pending txs', function () {
txController.txStateManager._saveTxList([
- { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
- { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
+ { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
+ { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
+ { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
])
const pendingTxCount = txController.getPendingTxCount()
assert.equal(pendingTxCount, 3, 'should be 3')
@@ -79,15 +82,15 @@ describe('Transaction Controller', function () {
'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d',
}
txController.txStateManager._saveTxList([
- {id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams},
- {id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams},
- {id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams},
- {id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams},
- {id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams},
- {id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams},
- {id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams},
- {id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams},
- {id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams},
+ {id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
+ {id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
])
})
@@ -155,9 +158,19 @@ describe('Transaction Controller', function () {
})
describe('#addUnapprovedTransaction', function () {
+ const selectedAddress = '0x1678a085c290ebd122dc42cba69373b5953b831d'
+
+ let getSelectedAddress
+ beforeEach(function () {
+ getSelectedAddress = sinon.stub(txController, 'getSelectedAddress').returns(selectedAddress)
+ })
+
+ afterEach(function () {
+ getSelectedAddress.restore()
+ })
it('should add an unapproved transaction and return a valid txMeta', function (done) {
- txController.addUnapprovedTransaction({ from: '0x1678a085c290ebd122dc42cba69373b5953b831d' })
+ txController.addUnapprovedTransaction({ from: selectedAddress })
.then((txMeta) => {
assert(('id' in txMeta), 'should have a id')
assert(('time' in txMeta), 'should have a time stamp')
@@ -177,48 +190,58 @@ describe('Transaction Controller', function () {
assert(txMetaFromEmit, 'txMeta is falsey')
done()
})
- txController.addUnapprovedTransaction({ from: '0x1678a085c290ebd122dc42cba69373b5953b831d' })
+ txController.addUnapprovedTransaction({ from: selectedAddress })
.catch(done)
})
it('should fail if recipient is public', function (done) {
txController.networkStore = new ObservableStore(1)
- txController.addUnapprovedTransaction({ from: '0x1678a085c290ebd122dc42cba69373b5953b831d', to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
+ txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
.catch((err) => {
if (err.message === 'Recipient is a public account') done()
else done(err)
})
})
+ it('should fail if the from address isn\'t the selected address', function (done) {
+ txController.addUnapprovedTransaction({from: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2'})
+ .then(function () {
+ assert.fail('transaction should not have been added')
+ done()
+ })
+ .catch(function () {
+ assert.ok('pass')
+ done()
+ })
+ })
+
it('should not fail if recipient is public but not on mainnet', function (done) {
txController.once('newUnapprovedTx', (txMetaFromEmit) => {
assert(txMetaFromEmit, 'txMeta is falsey')
done()
})
- txController.addUnapprovedTransaction({ from: '0x1678a085c290ebd122dc42cba69373b5953b831d', to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
+ txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
.catch(done)
})
})
describe('#addTxGasDefaults', function () {
- it('should add the tx defaults if their are none', function (done) {
+ it('should add the tx defaults if their are none', async () => {
const txMeta = {
- 'txParams': {
- 'from': '0xc684832530fcbddae4b4230a47e991ddcec2831d',
- 'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ txParams: {
+ from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
},
+ history: [],
}
- providerResultStub.eth_gasPrice = '4a817c800'
- providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' }
- providerResultStub.eth_estimateGas = '5209'
- txController.addTxGasDefaults(txMeta)
- .then((txMetaWithDefaults) => {
- assert(txMetaWithDefaults.txParams.value, '0x0', 'should have added 0x0 as the value')
- assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price')
- assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field')
- done()
- })
- .catch(done)
+ providerResultStub.eth_gasPrice = '4a817c800'
+ providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' }
+ providerResultStub.eth_estimateGas = '5209'
+
+ const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta)
+ assert(txMetaWithDefaults.txParams.value, '0x0', 'should have added 0x0 as the value')
+ assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price')
+ assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field')
})
})
@@ -381,8 +404,9 @@ describe('Transaction Controller', function () {
})
it('should publish a tx, updates the rawTx when provided a one', async function () {
+ const rawTx = '0x477b2e6553c917af0db0388ae3da62965ff1a184558f61b749d1266b2e6d024c'
txController.txStateManager.addTx(txMeta)
- await txController.publishTransaction(txMeta.id)
+ await txController.publishTransaction(txMeta.id, rawTx)
const publishedTx = txController.txStateManager.getTx(1)
assert.equal(publishedTx.hash, hash)
assert.equal(publishedTx.status, 'submitted')
@@ -398,7 +422,7 @@ describe('Transaction Controller', function () {
data: '0x0',
}
txController.txStateManager._saveTxList([
- { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams },
+ { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
])
txController.retryTransaction(1)
.then((txMeta) => {