mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
fix warning for unit tests
This commit is contained in:
parent
390f86113a
commit
0da41263ac
@ -1,5 +1,4 @@
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const ethUtil = require('ethereumjs-util')
|
||||
const accountImporter = require('../../../app/scripts/account-import-strategies/index')
|
||||
const { assertRejects } = require('../test-utils')
|
||||
|
@ -5,9 +5,6 @@ const {
|
||||
getNetworkDisplayName,
|
||||
} = require('../../../../app/scripts/controllers/network/util')
|
||||
|
||||
const { createTestProviderTools } = require('../../../stub/provider')
|
||||
const providerResultStub = {}
|
||||
|
||||
describe('# Network Controller', function () {
|
||||
let networkController
|
||||
const noop = () => {}
|
||||
|
@ -4,9 +4,7 @@ const MockTxGen = require('../../../../lib/mock-tx-gen')
|
||||
const providerResultStub = {}
|
||||
|
||||
describe('Nonce Tracker', function () {
|
||||
let nonceTracker, provider
|
||||
let getPendingTransactions, pendingTxs
|
||||
let getConfirmedTransactions, confirmedTxs
|
||||
let nonceTracker, pendingTxs, confirmedTxs
|
||||
|
||||
describe('#getNonceLock', function () {
|
||||
|
||||
@ -182,8 +180,8 @@ describe('Nonce Tracker', function () {
|
||||
describe('When all three return different values', function () {
|
||||
beforeEach(function () {
|
||||
const txGen = new MockTxGen()
|
||||
const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 10 })
|
||||
const pendingTxs = txGen.generate({
|
||||
confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 10 })
|
||||
pendingTxs = txGen.generate({
|
||||
status: 'submitted',
|
||||
nonce: 100,
|
||||
}, { count: 1 })
|
||||
@ -202,8 +200,8 @@ describe('Nonce Tracker', function () {
|
||||
describe('Faq issue 67', function () {
|
||||
beforeEach(function () {
|
||||
const txGen = new MockTxGen()
|
||||
const confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 64 })
|
||||
const pendingTxs = txGen.generate({
|
||||
confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 64 })
|
||||
pendingTxs = txGen.generate({
|
||||
status: 'submitted',
|
||||
}, { count: 10 })
|
||||
// 0x40 is 64 in hex:
|
||||
|
@ -1,20 +1,12 @@
|
||||
const assert = require('assert')
|
||||
const ethUtil = require('ethereumjs-util')
|
||||
const EthTx = require('ethereumjs-tx')
|
||||
const ObservableStore = require('obs-store')
|
||||
const clone = require('clone')
|
||||
const { createTestProviderTools } = require('../../../../stub/provider')
|
||||
const PendingTransactionTracker = require('../../../../../app/scripts/controllers/transactions/pending-tx-tracker')
|
||||
const MockTxGen = require('../../../../lib/mock-tx-gen')
|
||||
const sinon = require('sinon')
|
||||
const noop = () => true
|
||||
const currentNetworkId = 42
|
||||
const otherNetworkId = 36
|
||||
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
||||
|
||||
|
||||
describe('PendingTransactionTracker', function () {
|
||||
let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub,
|
||||
let pendingTxTracker, txMeta, txMetaNoHash, providerResultStub,
|
||||
provider, txMeta3, txList, knownErrors
|
||||
this.timeout(10000)
|
||||
beforeEach(function () {
|
||||
@ -34,11 +26,7 @@ describe('PendingTransactionTracker', function () {
|
||||
status: 'signed',
|
||||
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
|
||||
}
|
||||
txMetaNoRawTx = {
|
||||
hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
|
||||
status: 'signed',
|
||||
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
|
||||
}
|
||||
|
||||
providerResultStub = {}
|
||||
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
|
||||
|
||||
@ -133,22 +121,20 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
describe('#queryPendingTxs', function () {
|
||||
it('should call #_checkPendingTxs if their is no oldBlock', function (done) {
|
||||
let newBlock, oldBlock
|
||||
newBlock = { number: '0x01' }
|
||||
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) {
|
||||
let newBlock, oldBlock
|
||||
oldBlock = { number: '0x01' }
|
||||
newBlock = { number: '0x03' }
|
||||
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) {
|
||||
let newBlock, oldBlock
|
||||
oldBlock = { number: '0x1' }
|
||||
newBlock = { number: '0x2' }
|
||||
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)
|
||||
@ -197,7 +183,6 @@ describe('PendingTransactionTracker', function () {
|
||||
it('should warp all txMeta\'s in #_checkPendingTx', function (done) {
|
||||
pendingTxTracker.getPendingTransactions = () => txList
|
||||
pendingTxTracker._checkPendingTx = (tx) => { tx.resolve(tx) }
|
||||
const list = txList.map
|
||||
Promise.all(txList.map((tx) => tx.processed))
|
||||
.then((txCompletedList) => done())
|
||||
.catch(done)
|
||||
@ -275,7 +260,7 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
describe('#_resubmitTx', function () {
|
||||
const mockFirstRetryBlockNumber = '0x1'
|
||||
let txMetaToTestExponentialBackoff
|
||||
let txMetaToTestExponentialBackoff, enoughBalance
|
||||
|
||||
beforeEach(() => {
|
||||
pendingTxTracker.getBalance = (address) => {
|
||||
@ -298,7 +283,7 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
|
||||
it('should publish the transaction', function (done) {
|
||||
const enoughBalance = '0x100000'
|
||||
enoughBalance = '0x100000'
|
||||
|
||||
// Stubbing out current account state:
|
||||
// Adding the fake tx:
|
||||
@ -313,7 +298,7 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
|
||||
it('should not publish the transaction if the limit of retries has been exceeded', function (done) {
|
||||
const enoughBalance = '0x100000'
|
||||
enoughBalance = '0x100000'
|
||||
const mockLatestBlockNumber = '0x5'
|
||||
|
||||
pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
|
||||
@ -327,7 +312,7 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
|
||||
it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) {
|
||||
const enoughBalance = '0x100000'
|
||||
enoughBalance = '0x100000'
|
||||
const mockLatestBlockNumber = '0x11'
|
||||
|
||||
pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
|
||||
|
@ -1,20 +1,17 @@
|
||||
const assert = require('assert')
|
||||
const ethUtil = require('ethereumjs-util')
|
||||
const EthTx = require('ethereumjs-tx')
|
||||
const EthjsQuery = require('ethjs-query')
|
||||
const ObservableStore = require('obs-store')
|
||||
const sinon = require('sinon')
|
||||
const TransactionController = require('../../../../../app/scripts/controllers/transactions')
|
||||
const TxGasUtils = require('../../../../../app/scripts/controllers/transactions/tx-gas-utils')
|
||||
const { createTestProviderTools, getTestAccounts } = require('../../../../stub/provider')
|
||||
|
||||
const noop = () => true
|
||||
const currentNetworkId = 42
|
||||
const otherNetworkId = 36
|
||||
|
||||
|
||||
describe('Transaction Controller', function () {
|
||||
let txController, provider, providerResultStub, query, fromAccount
|
||||
let txController, provider, providerResultStub, fromAccount
|
||||
|
||||
beforeEach(function () {
|
||||
providerResultStub = {
|
||||
@ -24,7 +21,6 @@ describe('Transaction Controller', function () {
|
||||
eth_getCode: '0x',
|
||||
}
|
||||
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
|
||||
query = new EthjsQuery(provider)
|
||||
fromAccount = getTestAccounts()[0]
|
||||
|
||||
txController = new TransactionController({
|
||||
|
@ -1,6 +1,5 @@
|
||||
const assert = require('assert')
|
||||
const Transaction = require('ethereumjs-tx')
|
||||
const BN = require('bn.js')
|
||||
|
||||
|
||||
const { hexToBn, bnToHex } = require('../../../../../app/scripts/lib/util')
|
||||
|
@ -1,6 +1,4 @@
|
||||
const assert = require('assert')
|
||||
const clone = require('clone')
|
||||
const ObservableStore = require('obs-store')
|
||||
const TxStateManager = require('../../../../../app/scripts/controllers/transactions/tx-state-manager')
|
||||
const txStateHistoryHelper = require('../../../../../app/scripts/controllers/transactions/lib/tx-state-history-helper')
|
||||
const noop = () => true
|
||||
@ -59,6 +57,7 @@ describe('TransactionStateManager', function () {
|
||||
const tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }
|
||||
txStateManager.addTx(tx)
|
||||
const noop = function (err, txId) {
|
||||
assert(err, null)
|
||||
assert(true, 'event listener has been triggered and noop executed')
|
||||
done()
|
||||
}
|
||||
@ -166,8 +165,6 @@ describe('TransactionStateManager', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const updatedMeta = clone(txMeta)
|
||||
|
||||
txStateManager.addTx(txMeta)
|
||||
const updatedTx = txStateManager.getTx('1')
|
||||
// verify tx was initialized correctly
|
||||
|
@ -35,8 +35,8 @@ describe('EdgeEncryptor', function () {
|
||||
.then(function (encryptedData) {
|
||||
const encryptedObject = JSON.parse(encryptedData)
|
||||
assert.ok(encryptedObject.data, 'there is no data')
|
||||
assert.ok(encryptedObject.iv && encryptedObject.iv.length != 0, 'there is no iv')
|
||||
assert.ok(encryptedObject.salt && encryptedObject.salt.length != 0, 'there is no salt')
|
||||
assert.ok(encryptedObject.iv && encryptedObject.iv.length !== 0, 'there is no iv')
|
||||
assert.ok(encryptedObject.salt && encryptedObject.salt.length !== 0, 'there is no salt')
|
||||
done()
|
||||
}).catch(function (err) {
|
||||
done(err)
|
||||
|
@ -13,6 +13,7 @@ describe('nodeify', function () {
|
||||
it('should retain original context', function (done) {
|
||||
var nodified = nodeify(obj.promiseFunc, obj)
|
||||
nodified('baz', function (err, res) {
|
||||
assert(err, null)
|
||||
assert.equal(res, 'barbaz')
|
||||
done()
|
||||
})
|
||||
|
@ -2,7 +2,6 @@ const assert = require('assert')
|
||||
const PendingBalanceCalculator = require('../../../app/scripts/lib/pending-balance-calculator')
|
||||
const MockTxGen = require('../../lib/mock-tx-gen')
|
||||
const BN = require('ethereumjs-util').BN
|
||||
const providerResultStub = {}
|
||||
|
||||
const zeroBn = new BN(0)
|
||||
const etherBn = new BN(String(1e18))
|
||||
|
@ -13,7 +13,6 @@ describe('SeedPhraseVerifier', function () {
|
||||
const hdKeyTree = 'HD Key Tree'
|
||||
|
||||
let keyringController
|
||||
let vault
|
||||
let primaryKeyring
|
||||
|
||||
beforeEach(async function () {
|
||||
@ -24,7 +23,7 @@ describe('SeedPhraseVerifier', function () {
|
||||
|
||||
assert(keyringController)
|
||||
|
||||
vault = await keyringController.createNewVaultAndKeychain(password)
|
||||
await keyringController.createNewVaultAndKeychain(password)
|
||||
primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0]
|
||||
})
|
||||
|
||||
@ -37,7 +36,7 @@ describe('SeedPhraseVerifier', function () {
|
||||
const seedWords = serialized.mnemonic
|
||||
assert.notEqual(seedWords.length, 0)
|
||||
|
||||
const result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
})
|
||||
|
||||
it('should be able to verify created account (upper case) with seed words', async function () {
|
||||
@ -51,7 +50,7 @@ describe('SeedPhraseVerifier', function () {
|
||||
const seedWords = serialized.mnemonic
|
||||
assert.notEqual(seedWords.length, 0)
|
||||
|
||||
const result = await seedPhraseVerifier.verifyAccounts(upperCaseAccounts, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(upperCaseAccounts, seedWords)
|
||||
})
|
||||
|
||||
it('should be able to verify created account (lower case) with seed words', async function () {
|
||||
@ -64,7 +63,7 @@ describe('SeedPhraseVerifier', function () {
|
||||
const seedWords = serialized.mnemonic
|
||||
assert.notEqual(seedWords.length, 0)
|
||||
|
||||
const result = await seedPhraseVerifier.verifyAccounts(lowerCaseAccounts, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(lowerCaseAccounts, seedWords)
|
||||
})
|
||||
|
||||
it('should return error with good but different seed words', async function () {
|
||||
@ -72,11 +71,11 @@ describe('SeedPhraseVerifier', function () {
|
||||
const createdAccounts = await primaryKeyring.getAccounts()
|
||||
assert.equal(createdAccounts.length, 1)
|
||||
|
||||
const serialized = await primaryKeyring.serialize()
|
||||
await primaryKeyring.serialize()
|
||||
const seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'
|
||||
|
||||
try {
|
||||
const result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
assert.fail('Should reject')
|
||||
} catch (err) {
|
||||
assert.ok(err.message.indexOf('Not identical accounts!') >= 0, 'Wrong error message')
|
||||
@ -88,11 +87,11 @@ describe('SeedPhraseVerifier', function () {
|
||||
const createdAccounts = await primaryKeyring.getAccounts()
|
||||
assert.equal(createdAccounts.length, 1)
|
||||
|
||||
const serialized = await primaryKeyring.serialize()
|
||||
await primaryKeyring.serialize()
|
||||
const seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'
|
||||
|
||||
try {
|
||||
const result = await seedPhraseVerifier.verifyAccounts(undefined, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(undefined, seedWords)
|
||||
assert.fail('Should reject')
|
||||
} catch (err) {
|
||||
assert.equal(err.message, 'No created accounts defined.')
|
||||
@ -104,11 +103,11 @@ describe('SeedPhraseVerifier', function () {
|
||||
const createdAccounts = await primaryKeyring.getAccounts()
|
||||
assert.equal(createdAccounts.length, 1)
|
||||
|
||||
const serialized = await primaryKeyring.serialize()
|
||||
await primaryKeyring.serialize()
|
||||
const seedWords = 'debris dizzy just program just float decrease vacant alarm reduce speak stadium'
|
||||
|
||||
try {
|
||||
const result = await seedPhraseVerifier.verifyAccounts([], seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts([], seedWords)
|
||||
assert.fail('Should reject')
|
||||
} catch (err) {
|
||||
assert.equal(err.message, 'No created accounts defined.')
|
||||
@ -117,8 +116,8 @@ describe('SeedPhraseVerifier', function () {
|
||||
|
||||
it('should be able to verify more than one created account with seed words', async function () {
|
||||
|
||||
const keyState = await keyringController.addNewAccount(primaryKeyring)
|
||||
const keyState2 = await keyringController.addNewAccount(primaryKeyring)
|
||||
await keyringController.addNewAccount(primaryKeyring)
|
||||
await keyringController.addNewAccount(primaryKeyring)
|
||||
|
||||
const createdAccounts = await primaryKeyring.getAccounts()
|
||||
assert.equal(createdAccounts.length, 3)
|
||||
@ -127,7 +126,7 @@ describe('SeedPhraseVerifier', function () {
|
||||
const seedWords = serialized.mnemonic
|
||||
assert.notEqual(seedWords.length, 0)
|
||||
|
||||
const result = await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
await seedPhraseVerifier.verifyAccounts(createdAccounts, seedWords)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,6 +1,5 @@
|
||||
const assert = require('assert')
|
||||
const migration23 = require('../../../app/scripts/migrations/023')
|
||||
const properTime = (new Date()).getTime()
|
||||
const storage = {
|
||||
'meta': {},
|
||||
'data': {
|
||||
|
@ -4,7 +4,6 @@ const firstTimeState = {
|
||||
meta: {},
|
||||
data: require('../../../app/scripts/first-time-state'),
|
||||
}
|
||||
const properTime = (new Date()).getTime()
|
||||
const storage = {
|
||||
'meta': {},
|
||||
'data': {
|
||||
|
@ -1,6 +1,5 @@
|
||||
const assert = require('assert')
|
||||
const migrationTemplate = require('../../../app/scripts/migrations/template')
|
||||
const properTime = (new Date()).getTime()
|
||||
const storage = {
|
||||
meta: {},
|
||||
data: {},
|
||||
|
Loading…
Reference in New Issue
Block a user